jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/647272 )
Change subject: [doc] Update ROADMAP.rst
......................................................................
[doc] Update ROADMAP.rst
Change-Id: I3cee21537547a0d132dfe8c865b077b497775ec3
---
M ROADMAP.rst
1 file changed, 26 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index 8bee61b..f11b7d9 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,6 +1,32 @@
Current release changes
~~~~~~~~~~~~~~~~~~~~~~~
+* Remove deprecated args for Page.protect() (T227610)
+* Move BaseSite its own site/_basesite.py file
+* Improve toJSON() methods in page.__init__.py
+* _is_wikibase_error_retryable rewritten (T48535, 268645)
+* Replace FrozenDict with frozenmap
+* WikiStats table may be sorted by any key
+* Retrieve month names from mediawiki_messages when required
+* Move Namespace and NamespacesDict to site/_namespace.py file
+* Fix TypeError in api.LoginManager (T268445)
+* Add repr() method to BaseDataDict and ClaimCollection
+* Define availableOptions as deprecated property
+* Do not strip all whitespaces from Link.title (T197642)
+* Introduce a common BaseDataDict as parent for LanguageDict and AliasesDict
+* Replaced PageNotSaved by PageSaveRelatedError (T267821)
+* Add -site option as -family -lang shortcut
+* Enable APISite.exturlusage() with default parameters (T266989)
+* Update tools._unidata._category_cf from Unicode version 13.0.0
+* Move TokenWallet to site/_tokenwallet.py file
+* Fix import of httplib after release of requests 2.25 (T267762)
+* user keyword parameter can be passed to Site.rollbackpage() (T106646)
+* Check for {{bots}}/{{nobots}} templates in Page.text setter (T262136, T267770)
+* Remove deprecated UserBlocked exception and Page.contributingUsers()
+* Add support for some 'wbset' actions in DataSite
+* Fix UploadRobot site attribute (T267573)
+* Ignore UnicodeDecodeError on input (T258143)
+* Replace 'source' exception regex with 'syntaxhighlight' (T257899)
* Fix get_known_families() for wikipedia_family (T267196)
* Move _InterwikiMap class to site/_interwikimap.py
* instantiate a CosmeticChangesToolkit by passing a page
@@ -19,7 +45,6 @@
* 5.0.0: wikistats methods fetch, raw_cached, csv, xml will be removed
* 5.0.0: PageRelatedError.getPage() will be removes in favour of PageRelatedError.page
* 5.0.0: HttpRequest result of http.fetch() will be replaced by requests.Response (T265206)
-* 5.0.0: edit, move, create, upload, unprotect and prompt parameters of Page.protect() will be removed (T227610)
* 5.0.0: OptionHandler.options dict will be removed in favour of OptionHandler.opt
* 5.0.0: version.getfileversion() is desupported and will be removed
* 5.0.0: Methods deprecated for 5 years or longer will be removed
@@ -30,5 +55,3 @@
* 5.0.0: DataSite.get_item() method will be removed
* 5.0.0: date.MakeParameter() function will be removed
* 5.0.0: pagegenerators.ReferringPageGenerator is desupported and will be removed
-* 4.3.0: Unused UserBlocked exception will be removed
-* 4.3.0: Deprecated Page.contributingUsers() will be removed
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/647272
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3cee21537547a0d132dfe8c865b077b497775ec3
Gerrit-Change-Number: 647272
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645925 )
Change subject: [bugfix] Check for {{bots}}/{{nobots}} in Page.text setter
......................................................................
[bugfix] Check for {{bots}}/{{nobots}} in Page.text setter
This reverts fdfae7bb446a6 and moves early check into BasePage.text setter
- revert fdfae7bb446a6 change for BasePage
- check for botMayEdit in text setter first
but ignore DryRequest rejecting Exception
- update old tests with those steps:
- call text deleter to remove "_raw_extracted_templates" cache
- add template to "_text" attribute directly to bypass the botMayEdit check
- make the test
- clear the botMayEdit cache
Bug: T267770
Change-Id: I03f23af85371d4246f41db70c7148a27d9b34c35
---
M pywikibot/page/__init__.py
M tests/page_tests.py
2 files changed, 100 insertions(+), 134 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 96cee52..8e6fe80 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -620,26 +620,26 @@
if getattr(self, '_text', None) is not None:
return self._text
- if hasattr(self, '_revid'):
- return self.latest_revision.text
-
try:
- self.get(get_redirect=True)
+ return self.get(get_redirect=True)
except pywikibot.NoPage:
# TODO: what other exceptions might be returned?
return ''
- # check botMayEdit on a very early state (T262136)
- self.botMayEdit()
- return self.latest_revision.text
-
@text.setter
- def text(self, value: str):
- """
- Update the current (edited) wikitext.
+ def text(self, value: Optional[str]):
+ """Update the current (edited) wikitext.
@param value: New value or None
"""
+ try:
+ self.botMayEdit() # T262136, T267770
+ except Exception as e:
+ # dry tests aren't able to make an API call but are
+ # but are rejected by an Exception; ignore it then.
+ if not str(e).startswith('DryRequest rejecting request:'):
+ raise
+
del self.text
self._text = None if value is None else str(value)
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 9fd5f06..1bc7743 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -739,133 +739,108 @@
'Page {} exists! Change page name in tests/page_tests.py'
.format(self.page.title()))
+ def tearDown(self):
+ """Cleanup cache."""
+ self.page.botMayEdit.cache_clear()
+ super().tearDown()
+
+ def _run_test(self, template, user, expected_result):
+ """Run a single template test."""
+ del self.page.text
+ self.page._text = template % {'user': user}
+ with self.subTest(template=template, user=user):
+ self.assertEqual(self.page.botMayEdit(), expected_result)
+ self.page.botMayEdit.cache_clear()
+
@mock.patch.object(config, 'ignore_bot_templates', False)
- def test_bot_may_edit_nobots(self):
+ def test_bot_may_edit_nobots_ok(self):
"""Test with {{nobots}} that bot is allowed to edit."""
+ templates = (
+ # Ban all compliant bots not in the list, syntax for de wp.
+ '{{nobots|HagermanBot,Werdnabot}}',
+ # Ignore second parameter
+ '{{nobots|MyBot|%(user)s}}',
+ )
+
self.page._templates = [pywikibot.Page(self.site, 'Template:Nobots')]
user = self.site.user()
-
- # Ban all compliant bots (shortcut).
- self.page.text = '{{nobots}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Ban all compliant bots not in the list, syntax for de wp.
- self.page.text = '{{nobots|HagermanBot,Werdnabot}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ban all compliant bots not in the list, syntax for de wp.
- self.page.text = '{{nobots|%s, HagermanBot,Werdnabot}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Ban all bots, syntax for de wp.
- self.page.text = '{{nobots|all}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Decline wrong nobots parameter
- self.page.text = '{{nobots|allow=%s}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Decline wrong nobots parameter
- self.page.text = '{{nobots|deny=%s}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Decline wrong nobots parameter
- self.page.text = '{{nobots|decline=%s}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Decline empty keyword parameter with nobots
- self.page.text = '{{nobots|with_empty_parameter=}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Ignore second parameter
- self.page.text = '{{nobots|%s|MyBot}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Ignore second parameter
- self.page.text = '{{nobots|MyBot|%s}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
+ for template in templates:
+ self._run_test(template, user, True)
@mock.patch.object(config, 'ignore_bot_templates', False)
- def test_bot_may_edit_bots(self):
+ def test_bot_may_edit_nobots_nok(self):
+ """Test with {{nobots}} that bot is not allowed to edit."""
+ templates = (
+ # Ban all compliant bots (shortcut)
+ '{{nobots}}',
+ # Ban all compliant bots not in the list, syntax for de wp
+ '{{nobots|%(user)s, HagermanBot,Werdnabot}}',
+ # Ban all bots, syntax for de wp
+ '{{nobots|all}}',
+ # Decline wrong nobots parameter
+ '{{nobots|allow=%(user)s}}',
+ '{{nobots|deny=%(user)s}}',
+ '{{nobots|decline=%(user)s}}',
+ # Decline empty keyword parameter with nobots
+ '{{nobots|with_empty_parameter=}}',
+ # Ignore second parameter
+ '{{nobots|%(user)s|MyBot}}',
+ )
+
+ self.page._templates = [pywikibot.Page(self.site, 'Template:Nobots')]
+ user = self.site.user()
+ for template in templates:
+ self._run_test(template, user, False)
+
+ @mock.patch.object(config, 'ignore_bot_templates', False)
+ def test_bot_may_edit_bots_ok(self):
"""Test with {{bots}} that bot is allowed to edit."""
+ templates = (
+ '{{bots}}', # Allow all bots (shortcut)
+ # Ban all compliant bots in the list
+ '{{bots|deny=HagermanBot,Werdnabot}}',
+ # Ban all compliant bots not in the list
+ '{{bots|allow=%(user)s, HagermanBot}}',
+ # Allow all bots
+ '{{bots|allow=all}}',
+ '{{bots|deny=none}}',
+ # Ignore missing named parameter
+ '{{bots|%(user)s}}', # Ignore missing named parameter
+ # Ignore unknown keyword parameter with bots
+ '{{bots|with=unknown_parameter}}',
+ # Ignore unknown empty parameter keyword with bots
+ '{{bots|with_empty_parameter=}}',
+ )
+
self.page._templates = [pywikibot.Page(self.site, 'Template:Bots')]
user = self.site.user()
-
- # Allow all bots (shortcut).
- self.page.text = '{{bots}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ban all compliant bots not in the list.
- self.page.text = '{{bots|allow=HagermanBot,Werdnabot}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Ban all compliant bots in the list.
- self.page.text = '{{bots|deny=HagermanBot,Werdnabot}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ban all compliant bots not in the list.
- self.page.text = '{{bots|allow=%s, HagermanBot}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ban all compliant bots in the list.
- self.page.text = '{{bots|deny=%s, HagermanBot}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Allow all bots.
- self.page.text = '{{bots|allow=all}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ban all compliant bots.
- self.page.text = '{{bots|allow=none}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Ban all compliant bots.
- self.page.text = '{{bots|deny=all}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertFalse(self.page.botMayEdit())
-
- # Allow all bots.
- self.page.text = '{{bots|deny=none}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ignore missing named parameter.
- self.page.text = '{{bots|%s}}' % user
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
+ for template in templates:
+ self._run_test(template, user, True)
# Ignore empty keyword parameter with bots
for param in ('allow', 'deny', 'empty_parameter'):
- self.page.text = '{{bots|%s=}}' % param
+ del self.page.text
+ self.page._text = '{{bots|%s=}}' % param
with self.subTest(template=self.page.text, user=user, param=param):
self.assertTrue(self.page.botMayEdit())
+ self.page.botMayEdit.cache_clear()
- # Ignore unknown keyword parameter with bots
- self.page.text = '{{bots|with=unknown_parameter}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
-
- # Ignore unknown empty parameter keyword with bots
- self.page.text = '{{bots|with_empty_parameter=}}'
- with self.subTest(template=self.page.text, user=user):
- self.assertTrue(self.page.botMayEdit())
+ @mock.patch.object(config, 'ignore_bot_templates', False)
+ def test_bot_may_edit_bots_nok(self):
+ """Test with {{bots}} that bot is not allowed to edit."""
+ templates = (
+ # Ban all compliant bots not in the list
+ '{{bots|allow=HagermanBot,Werdnabot}}',
+ # Ban all compliant bots in the list
+ '{{bots|deny=%(user)s, HagermanBot}}',
+ # Ban all compliant bots
+ '{{bots|allow=none}}',
+ '{{bots|deny=all}}',
+ )
+ self.page._templates = [pywikibot.Page(self.site, 'Template:Bots')]
+ user = self.site.user()
+ for template in templates:
+ self._run_test(template, user, False)
@mock.patch.object(config, 'ignore_bot_templates', False)
def test_bot_may_edit_inuse(self):
@@ -873,7 +848,7 @@
self.page._templates = [pywikibot.Page(self.site, 'Template:In use')]
# Ban all users including bots.
- self.page.text = '{{in use}}'
+ self.page._text = '{{in use}}'
self.assertFalse(self.page.botMayEdit())
def test_bot_may_edit_missing_page(self):
@@ -891,19 +866,10 @@
def test_bot_may_edit_page_set_text(self):
"""Test botMayEdit for existing page when assigning text first."""
- content = 'Does page may be changed if {{nobots}} template is found?'
- # test the page with assigning text first
- with self.subTest(content=content):
- page = pywikibot.Page(self.site, 'Pywikibot nobots test')
- page.text = content
- self.assertFalse(page.botMayEdit())
-
- @unittest.expectedFailure
- def test_bot_may_edit_page_set_text_failing(self):
- """Test botMayEdit for existing page when assigning text first."""
contents = (
'Does page may be changed if content is not read first?',
'Does page may be changed if {{bots}} template is found?',
+ 'Does page may be changed if {{nobots}} template is found?'
)
# test the page with assigning text first
for content in contents:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645925
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I03f23af85371d4246f41db70c7148a27d9b34c35
Gerrit-Change-Number: 645925
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645931 )
Change subject: [bugfix] cache botMayEdit result
......................................................................
[bugfix] cache botMayEdit result
Patch detached from bcc30f5
Bug: T267770
Change-Id: I34d258ea7018044c0fda067b0e5794a0f5ec449d
---
M pywikibot/page/__init__.py
1 file changed, 5 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 94e9c55..308dfe1 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -62,10 +62,13 @@
from pywikibot.tools import is_IP
if PYTHON_VERSION >= (3, 9):
+ from functools import cache
Dict = dict
List = list
else:
+ from functools import lru_cache
from typing import Dict, List
+ cache = lru_cache(None)
PROTOCOL_REGEX = r'\Ahttps?://'
@@ -627,7 +630,7 @@
return ''
# check botMayEdit on a very early state (T262136)
- self._bot_may_edit = self.botMayEdit()
+ self.botMayEdit()
return self.latest_revision.text
@text.setter
@@ -1093,6 +1096,7 @@
"""DEPRECATED. Determine whether the page may be edited."""
return self.has_permission()
+ @cache
def botMayEdit(self) -> bool:
"""
Determine whether the active bot is allowed to edit the page.
@@ -1108,9 +1112,6 @@
to override this by setting ignore_bot_templates=True in
user-config.py, or using page.put(force=True).
"""
- if hasattr(self, '_bot_may_edit'):
- return self._bot_may_edit
-
if not hasattr(self, 'templatesWithParams'):
return True
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645931
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I34d258ea7018044c0fda067b0e5794a0f5ec449d
Gerrit-Change-Number: 645931
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645949 )
Change subject: [bugfix] Additional test which assigns a text first without reading from api
......................................................................
[bugfix] Additional test which assigns a text first without reading from api
Two of the additional tests are expected to fail unless a solution is
found for 645925
Patch detached from bcc30f5
Bug: T267770
Change-Id: I9511e49692cfbaeed45c1041bdfe8f32a46550ef
---
M tests/page_tests.py
1 file changed, 29 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/page_tests.py b/tests/page_tests.py
index e4ef897..f7fe278 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -876,16 +876,43 @@
self.page.text = '{{in use}}'
self.assertFalse(self.page.botMayEdit())
- def test_bot_may_edit_page(self):
- """Test botMayEdit when changing content."""
+ def test_bot_may_edit_missing_page(self):
+ """Test botMayEdit for not existent page."""
self.assertTrue(self.page.botMayEdit())
self.page.text = '{{nobots}}'
self.assertTrue(self.page.botMayEdit())
+
+ def test_bot_may_edit_page_nobots(self):
+ """Test botMayEdit for existing page with nobots template."""
page = pywikibot.Page(self.site, 'Pywikibot nobots test')
self.assertFalse(page.botMayEdit())
page.text = ''
self.assertFalse(page.botMayEdit())
+ def test_bot_may_edit_page_set_text(self):
+ """Test botMayEdit for existing page when assigning text first."""
+ content = 'Does page may be changed if {{nobots}} template is found?'
+ # test the page with assigning text first
+ with self.subTest(content=content):
+ page = pywikibot.Page(self.site, 'Pywikibot nobots test')
+ page.text = content
+ self.assertFalse(page.botMayEdit())
+
+ @unittest.expectedFailure
+ def test_bot_may_edit_page_set_text_failing(self):
+ """Test botMayEdit for existing page when assigning text first."""
+ contents = (
+ 'Does page may be changed if content is not read first?',
+ 'Does page may be changed if {{bots}} template is found?',
+ )
+ # test the page with assigning text first
+ for content in contents:
+ with self.subTest(content=content):
+ page = pywikibot.Page(self.site, 'Pywikibot nobots test')
+ page.text = content
+ self.assertFalse(page.botMayEdit())
+ del page
+
class TestPageHistory(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645949
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9511e49692cfbaeed45c1041bdfe8f32a46550ef
Gerrit-Change-Number: 645949
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634078 )
Change subject: [IMPR] remove deprecated args for Page.protect()
......................................................................
[IMPR] remove deprecated args for Page.protect()
Remove deprecated args for Page.protect():
- edit, move, create, upload, unprotect and prompt
- improve docstring
Bug: T227610
Change-Id: I2c6e30a3828cee523843be69df621ba6f4db8d60
---
M pywikibot/page/__init__.py
M tests/page_tests.py
2 files changed, 33 insertions(+), 72 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 55c9a23..d5b63e0 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1974,89 +1974,36 @@
self.site.undelete_page(self, reason, undelete_revs)
def protect(self,
- edit: bool = False,
- move: bool = False,
- create=None, upload=None,
- unprotect: bool = False,
reason: Optional[str] = None,
- prompt: Optional[bool] = None,
protections: Optional[dict] = None,
**kwargs):
"""
Protect or unprotect a wiki page. Requires administrator status.
Valid protection levels are '' (equivalent to 'none'),
- 'autoconfirmed', and 'sysop'. If None is given, however,
- that protection will be skipped.
+ 'autoconfirmed', 'sysop' and 'all'. 'all' means 'everyone is allowed',
+ i.e. that protection type will be unprotected.
+
+ In order to unprotect a type of permission, the protection level shall
+ be either set to 'all' or '' or skipped in the protections dictionary.
+
+ Expiry of protections can be set via kwargs, see Site.protect() for
+ details. By default there is no expiry for the protection types.
@param protections: A dict mapping type of protection to protection
- level of that type.
- @param reason: Reason for the action
- @param prompt: Whether to ask user for confirmation (deprecated).
- Defaults to protections is None
+ level of that type. Allowed protection types for a page can be
+ retrieved by Page.self.applicable_protections()
+ Defaults to protections is None, which means unprotect all
+ protection types.
+ Example: {'move': 'sysop', 'edit': 'autoconfirmed'}
+
+ @param reason: Reason for the action, default is None and will set an
+ empty string.
"""
- def process_deprecated_arg(value, arg_name):
- # if protections was set and value is None, don't interpret that
- # argument. But otherwise warn that the parameter was set
- # (even implicit)
- if called_using_deprecated_arg:
- if value is False: # explicit test for False (don't use not)
- value = 'sysop'
- if value == 'none': # 'none' doesn't seem do be accepted
- value = ''
- if value is not None: # empty string is allowed
- protections[arg_name] = value
- issue_deprecation_warning(
- '"{}" argument of protect()'.format(arg_name),
- '"protections" dict',
- warning_class=FutureWarning,
- since='20140815')
+ protections = protections or {} # protections is converted to {}
+ reason = reason or '' # None is converted to ''
- else:
- if value:
- warn('"protections" argument of protect() replaces "{0}";'
- ' cannot use both.'.format(arg_name),
- RuntimeWarning)
-
- # buffer that, because it might get changed
- called_using_deprecated_arg = protections is None
- if called_using_deprecated_arg:
- protections = {}
- process_deprecated_arg(edit, 'edit')
- process_deprecated_arg(move, 'move')
- process_deprecated_arg(create, 'create')
- process_deprecated_arg(upload, 'upload')
-
- if reason is None:
- pywikibot.output('Preparing to protection change of %s.'
- % (self.title(as_link=True)))
- reason = pywikibot.input('Please enter a reason for the action:')
- if unprotect:
- issue_deprecation_warning(
- '"unprotect" argument of protect()',
- warning_class=FutureWarning,
- since='20140815')
- protections = {p_type: ''
- for p_type in self.applicable_protections()}
- answer = 'y'
- if called_using_deprecated_arg and prompt is None:
- prompt = True
- if prompt:
- issue_deprecation_warning(
- '"prompt" argument of protect()',
- warning_class=FutureWarning,
- since='20140815')
- if prompt and not hasattr(self.site, '_noProtectPrompt'):
- answer = pywikibot.input_choice(
- 'Do you want to change the protection level of %s?'
- % self.title(as_link=True, force_interwiki=True),
- [('Yes', 'y'), ('No', 'n'), ('All', 'a')],
- 'n', automatic_quit=False)
- if answer == 'a':
- answer = 'y'
- self.site._noProtectPrompt = True
- if answer == 'y':
- self.site.protect(self, protections, reason, **kwargs)
+ self.site.protect(self, protections, reason, **kwargs)
@deprecated_args(
comment='summary', oldCat='old_cat', newCat='new_cat',
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 7df0893..bb8781e 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1106,6 +1106,20 @@
reason='Pywikibot unit test')
self.assertEqual(p1.protection(), {})
+ def test_protect_with_empty_parameters(self):
+ """Test Page.protect."""
+ site = self.get_site()
+ p1 = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest')
+
+ p1.protect(protections={'edit': 'sysop', 'move': 'autoconfirmed'},
+ reason='Pywikibot unit test')
+ self.assertEqual(p1.protection(),
+ {'edit': ('sysop', 'infinity'),
+ 'move': ('autoconfirmed', 'infinity')})
+
+ p1.protect(reason='Pywikibot unit test')
+ self.assertEqual(p1.protection(), {})
+
def test_protect_alt(self):
"""Test of Page.protect that works around T78522."""
site = self.get_site()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634078
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2c6e30a3828cee523843be69df621ba6f4db8d60
Gerrit-Change-Number: 634078
Gerrit-PatchSet: 2
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged