jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Remove Category.copyTo and Category.copyAndKeep methods

Deprecated in I81000f4db448feb837a287ea6355ce48e7d1169e

Change-Id: Ic19b20435cac7e8ef68b990c7a53b64e83bca7b6
---
M HISTORY.rst
M pywikibot/page/__init__.py
M tests/category_tests.py
3 files changed, 1 insertion(+), 109 deletions(-)

diff --git a/HISTORY.rst b/HISTORY.rst
index b583603..d20bf13 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,7 @@
Current release
---------------

+* Category.copyTo and Category.copyAndKeep methods have been removed
* Use site.userinfo getter instead of site._userinfo within api (T243794)
* Fix endprefix parameter in Category.articles() (T247201)
* Fix search for changed claims when saving entity (T246359)
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index f8b4418..2f27c25 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -3148,93 +3148,6 @@
"""DEPRECATED: equivalent to list(self.categories(...))."""
return sorted(set(self.categories()))

- @deprecated(since='20200111', future_warning=True)
- def copyTo(self, cat, message):
- """
- Copy text of category page to a new page. Does not move contents.
-
- @param cat: New category title (without namespace) or Category object
- @type cat: str or pywikibot.page.Category
- @param message: message to use for category creation message
- If two %s are provided in message, will be replaced
- by (self.title, authorsList)
- @type message: str
- @return: True if copying was successful, False if target page
- already existed.
- @rtype: bool
- """
- # This seems far too specialized to be in the top-level framework
- # move to category.py? (Although it doesn't seem to be used there,
- # either)
- if not isinstance(cat, Category):
- target_cat = Category(self.site, 'Category:' + cat)
- else:
- target_cat = cat
- if target_cat.exists():
- pywikibot.warning(
- 'Target page %s already exists!' % target_cat.title())
- return False
- else:
- pywikibot.output('Moving text from %s to %s.'
- % (self.title(), target_cat.title()))
- authors = ', '.join(self.contributingUsers())
- try:
- creation_summary = message % (self.title(), authors)
- except TypeError:
- creation_summary = message
- target_cat.put(self.get(), creation_summary)
- return True
-
- @deprecated(since='20200111', future_warning=True)
- @deprecated_args(cfdTemplates='cfd_templates')
- def copyAndKeep(self, catname, cfd_templates, message):
- """
- Copy partial category page text (not contents) to a new title.
-
- Like copyTo above, except this removes a list of templates (like
- deletion templates) that appear in the old category text. It also
- removes all text between the two HTML comments BEGIN CFD TEMPLATE
- and END CFD TEMPLATE. (This is to deal with CFD templates that are
- substituted.)
-
- Returns true if copying was successful, false if target page already
- existed.
-
- @param catname: New category title (without namespace)
- @param cfd_templates: A list (or iterator) of templates to be removed
- from the page text
- @return: True if copying was successful, False if target page
- already existed.
- @rtype: bool
- """
- # I don't see why we need this as part of the framework either
- # move to scripts/category.py?
- target_cat = Category(self.site, 'Category:' + catname)
- if target_cat.exists():
- pywikibot.warning('Target page %s already exists!'
- % target_cat.title())
- return False
-
- pywikibot.output(
- 'Moving text from {} to {}.'
- .format(self.title(), target_cat.title()))
- authors = ', '.join(self.contributingUsers())
- creation_summary = message % (self.title(), authors)
- newtext = self.get()
- for regex_name in cfd_templates:
- matchcfd = re.compile(r'{{%s.*?}}' % regex_name, re.IGNORECASE)
- newtext = matchcfd.sub('', newtext)
- matchcomment = re.compile(
- r'<!--BEGIN CFD TEMPLATE-->.*?<!--END CFD TEMPLATE-->',
- re.IGNORECASE | re.MULTILINE | re.DOTALL)
- newtext = matchcomment.sub('', newtext)
- pos = 0
- while (newtext[pos:pos + 1] == '\n'):
- pos = pos + 1
- newtext = newtext[pos:]
- target_cat.put(newtext, creation_summary)
- return True
-

class User(Page):

diff --git a/tests/category_tests.py b/tests/category_tests.py
index f17cef9..25c2ee3 100644
--- a/tests/category_tests.py
+++ b/tests/category_tests.py
@@ -10,7 +10,6 @@
import pywikibot
import pywikibot.page

-from tests import patch
from tests.aspects import unittest, TestCase


@@ -170,27 +169,6 @@

dry = True

- def test_copy_to(self):
- """Test the copyTo method."""
- site = self.get_site()
- foo_cat = pywikibot.Category(site, 'Category:Foo')
- with patch.object(pywikibot.Category, 'exists', return_value=True), \
- patch.object(pywikibot, 'warning') as w:
- self.assertFalse(foo_cat.copyTo('cattitle', 'message'))
- w.assert_called_once_with(
- 'Target page Category:Cattitle already exists!')
-
- def test_copy_and_keep(self):
- """Test the copyAndKeep method."""
- site = self.get_site()
- foo_cat = pywikibot.Category(site, 'Category:Foo')
- with patch.object(pywikibot.Category, 'exists', return_value=True), \
- patch.object(pywikibot, 'warning') as w:
- self.assertFalse(
- foo_cat.copyAndKeep('cattitle', [], 'message'))
- w.assert_called_once_with(
- 'Target page Category:Cattitle already exists!')
-
def test_init_dry(self):
"""Test the category's __init__."""
site = self.get_site()

To view, visit change 577840. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic19b20435cac7e8ef68b990c7a53b64e83bca7b6
Gerrit-Change-Number: 577840
Gerrit-PatchSet: 8
Gerrit-Owner: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)