jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606968 )
Change subject: [bugfix] escape delete char 127 in UnicodeToAsciiHtml function
......................................................................
[bugfix] escape delete char 127 in UnicodeToAsciiHtml function
Delete char 127 should be escaped to  because it is not a
visible character but an ascii command character
Change-Id: I65ea32bb5cf77aee331a6c0bfe966feb98c16b5e
---
M pywikibot/page/__init__.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index acf6a99..422fc83 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -6864,7 +6864,7 @@
html = []
for c in s:
cord = ord(c)
- if 31 < cord < 128:
+ if 31 < cord < 127:
html.append(c)
else:
html.append('&#%d;' % cord)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606968
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: I65ea32bb5cf77aee331a6c0bfe966feb98c16b5e
Gerrit-Change-Number: 606968
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606942 )
Change subject: [cleanup] deprecate Page.isEmpty without 'instead' parameter
......................................................................
[cleanup] deprecate Page.isEmpty without 'instead' parameter
Page.isEmpty is already deprecated for 5 years.
But it is senseless to refer to a script function as an alternative.
Bug: T112340
Change-Id: If87937fa7d63f3073820889e3334b64baca6fbdb
---
M pywikibot/page/__init__.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Dvorapa: Looks good to me, but someone else must approve
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index acf6a99..64a2253 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -893,7 +893,7 @@
return Category(Link(self._catredirect, self.site))
raise pywikibot.IsNotRedirectPage(self)
- @deprecated('interwiki.page_empty_check(page)', since='20151207')
+ @deprecated(since='20151207')
def isEmpty(self):
"""
Return True if the page text has less than 4 characters.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606942
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: If87937fa7d63f3073820889e3334b64baca6fbdb
Gerrit-Change-Number: 606942
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/608038 )
Change subject: [doc] Update ROADMAP.rst
......................................................................
[doc] Update ROADMAP.rst
Change-Id: I1fbceaaf14b5e7b1aee38a1650992475b544be3f
---
M ROADMAP.rst
1 file changed, 4 insertions(+), 1 deletion(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/ROADMAP.rst b/ROADMAP.rst
index f6a6e38..8b316bd 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -3,6 +3,8 @@
**Note: This is the last release supporting Python 2 and Python 3.4**
+* Page.botMayEdit() method was improved (T253709)
+* PageNotFound, SpamfilterError, UserActionRefuse exceptions were removed (T253681)
* tools.ip submodule has been removed (T243171)
* Wait in BaseBot.exit() until asynchronous saving pages are completed
* Solve IndexError when showing an empty diff with a non-zero context (T252724)
@@ -15,9 +17,10 @@
Future releases
~~~~~~~~~~~~~~~
+* (current) Unsupported debug parameter of UploadRobot will be removed
+* (current) Unported compat decode parameter of Page.title() will be removed
* (current) tools.count, tools.Counter, tools.OrderedDict and ContextManagerWrapper will be removed
* (current) getFilesFromAnHash and getImagesFromAnHash Site methods will be removed
-* 3.0.20200508: PageNotFound, SpamfilterError and UserActionRefuse exceptions will be removed (T253681)
* 3.0.20200508: Page.getVersionHistory and Page.fullVersionHistory() methods will be removed (T136513, T151110)
* 3.0.20200405: Site and Page methods deprecated for 10 years or longer will be removed
* 3.0.20200326: Functions dealing with stars list will be removed
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/608038
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: I1fbceaaf14b5e7b1aee38a1650992475b544be3f
Gerrit-Change-Number: 608038
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: DannyS712 <DannyS712.enwiki(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/608046 )
Change subject: [doc] use version from pywikibot/__init__
......................................................................
[doc] use version from pywikibot/__init__
- Use pywikibot.__version__ for writelogheader in bot.py
- Use pywikibot.__version__ for default_edit_summary in config2.py
- Change doc in i18n.py and CONTENT.rst
detached from I7ffe9096fece8c
Bug: T197936
Change-Id: I652ac978134f7ae7105a131464c3398ae8614f88
---
M CONTENT.rst
M pywikibot/bot.py
M pywikibot/config2.py
M pywikibot/i18n.py
4 files changed, 8 insertions(+), 6 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CONTENT.rst b/CONTENT.rst
index 89771af..a5aa3bb 100644
--- a/CONTENT.rst
+++ b/CONTENT.rst
@@ -27,7 +27,7 @@
| README.rst | Short info string used by Pywikibot Nightlies |
+---------------------------+------------------------------------------------------+
| README-conversion.txt | Guide to converting bot scripts from version 1 |
- | | of the Pywikibot framework to version 3 |
+ | | of the Pywikibot framework to current version |
+---------------------------+------------------------------------------------------+
| requirements.txt | General PIP requirements file |
+---------------------------+------------------------------------------------------+
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index c111c31..9588c26 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -374,7 +374,8 @@
if not http or not hasattr(http, 'threads') or not len(http.threads):
return
- log('=== Pywikibot framework v3.0 -- Logging header ===')
+ log('=== Pywikibot framework v{} -- Logging header ==='
+ .format(pywikibot.__version__))
# script call
log('COMMAND: {0}'.format(sys.argv))
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index e57eb83..01dee15 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -55,6 +55,7 @@
from requests import __version__ as requests_version
+from pywikibot import __version__ as pwb_version
from pywikibot.logging import error, output, warning
from pywikibot.tools import PY2, issue_deprecation_warning
@@ -237,7 +238,7 @@
# edit summary to use if not supplied by bot script
# WARNING: this should NEVER be used in practice, ALWAYS supply a more
# relevant summary for bot edits
-default_edit_summary = 'Pywikibot 3.0-dev'
+default_edit_summary = 'Pywikibot ' + pwb_version
# What permissions to use to set private files to it
# such as password file.
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 73fb7f0..99f5d40 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -6,10 +6,10 @@
and for TranslateWiki-based translations.
By default messages are assumed to reside in a package called
-'scripts.i18n'. In pywikibot 3.0, that package is not packaged
-with pywikibot, and pywikibot 3.0 does not have a hard dependency
+'scripts.i18n'. In pywikibot 3+, that package is not packaged
+with pywikibot, and pywikibot 3+ does not have a hard dependency
on any i18n messages. However, there are three user input questions
-in pagegenerators which will use i18 messages if they can be loaded.
+in pagegenerators which will use i18n messages if they can be loaded.
The default message location may be changed by calling
L{set_message_package} with a package name. The package must contain
--
To view, visit https://gerrit.wikimedia.org/r/608046
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I652ac978134f7ae7105a131464c3398ae8614f88
Gerrit-Change-Number: 608046
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Isaacandy <isaac(a)iznd.xyz>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/599271 )
Change subject: [IMPR] Rewrite Page.botMayEdit method
......................................................................
[IMPR] Rewrite Page.botMayEdit method
- introduce two new family methods get_edit_restricted_templates and
get_archived_page_templates which return edit_restricted_templates
and archived_page_templates for a given site.code. Return an empty
tuple if no key is found. These methods are available as Site
method too.
- use the new methods by botMayEdit
- never return True inside the botMayEdit loop because other
restricting templates may follow and the result should not be
depend to the order; continue looping instead and enable multiple
bots/nobots templates to be used
- show a warning if bots/nobots template has more than 1 parameter
- show an error message if nobots has a named parameter and decline
edit then
- show a warning if bots has no named parameter or empty parameter
values and continue looping
- use subTest for tests and simplify them
- split tests in 3 parts to avoid missing/wrong self.page._templates
assignment
Bug: T253709
Change-Id: I035ed06fe400e59b2239f73d3c1780ec3647212f
---
M pywikibot/family.py
M pywikibot/page/__init__.py
M tests/page_tests.py
3 files changed, 196 insertions(+), 99 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 9fca4b7..c1a4f9b 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1108,6 +1108,14 @@
"""DEPRECATED: Build list of category redirect templates."""
self._get_cr_templates(code, fallback)
+ def get_edit_restricted_templates(self, code):
+ """Return tuple of edit restricted templates."""
+ return self.edit_restricted_templates.get(code, ())
+
+ def get_archived_page_templates(self, code):
+ """Return tuple of archived page templates."""
+ return self.archived_page_templates.get(code, ())
+
def disambig(self, code, fallback='_default'):
"""Return list of disambiguation templates."""
if code in self.disambiguationTemplates:
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9d46cc3..77dacef 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1180,14 +1180,12 @@
@rtype: bool
"""
- # TODO: move this to Site object?
-
- # FIXME: templatesWithParams is defined in Page only.
if not hasattr(self, 'templatesWithParams'):
return True
if config.ignore_bot_templates: # Check the "master ignore switch"
return True
+
username = self.site.user()
try:
templates = self.templatesWithParams()
@@ -1197,48 +1195,85 @@
return True
# go through all templates and look for any restriction
- # multiple bots/nobots templates are allowed
- restrictions = self.site.family.edit_restricted_templates.get(
- self.site.code)
+ restrictions = set(self.site.get_edit_restricted_templates())
+
# also add archive templates for non-archive bots
if pywikibot.calledModuleName() != 'archivebot':
- archived = self.site.family.archived_page_templates.get(
- self.site.code)
- if restrictions and archived:
- restrictions += archived
- elif archived:
- restrictions = archived
+ restrictions.update(self.site.get_archived_page_templates())
+ # multiple bots/nobots templates are allowed
for template, params in templates:
title = template.title(with_ns=False)
- if restrictions:
- if title in restrictions:
- return False
+
+ if title in restrictions:
+ return False
+
+ if title not in ('Bots', 'Nobots'):
+ continue
+
+ try:
+ key, sep, value = params[0].partition('=')
+ except IndexError:
+ key, sep, value = '', '', ''
+ names = set()
+ else:
+ if not sep:
+ key, value = value, key
+ key = key.strip()
+ names = {name.strip() for name in value.split(',')}
+
+ if len(params) > 1:
+ pywikibot.warning(
+ '{{%s|%s}} has more than 1 parameter; taking the first.'
+ % (title.lower(), '|'.join(params)))
+
if title == 'Nobots':
if not params:
return False
- else:
- bots = [bot.strip() for bot in params[0].split(',')]
- if 'all' in bots or pywikibot.calledModuleName() in bots \
- or username in bots:
- return False
- elif title == 'Bots':
- if not params:
- return True
- else:
- (ttype, bots) = [part.strip() for part
- in params[0].split('=', 1)]
- bots = [bot.strip() for bot in bots.split(',')]
- if ttype == 'allow':
- return 'all' in bots or username in bots
- if ttype == 'deny':
- return not ('all' in bots or username in bots)
- if ttype == 'allowscript':
- return ('all' in bots
- or pywikibot.calledModuleName() in bots)
- if ttype == 'denyscript':
- return not ('all' in bots
- or pywikibot.calledModuleName() in bots)
+
+ if key:
+ pywikibot.error(
+ '%s parameter for {{nobots}} is not allowed. '
+ 'Edit declined' % key)
+ return False
+
+ if 'all' in names \
+ or pywikibot.calledModuleName() in names \
+ or username in names:
+ return False
+
+ if title == 'Bots':
+ if value and not key:
+ pywikibot.warning(
+ '{{bots|%s}} is not valid. Ignoring.' % value)
+ continue
+
+ if key and not value:
+ pywikibot.warning(
+ '{{bots|%s=}} is not valid. Ignoring.' % key)
+ continue
+
+ if key == 'allow' and not ('all' in names
+ or username in names):
+ return False
+
+ if key == 'deny' and ('all' in names or username in names):
+ return False
+
+ if key == 'allowscript' \
+ and not ('all' in names
+ or pywikibot.calledModuleName() in names):
+ return False
+
+ if key == 'denyscript' \
+ and ('all' in names
+ or pywikibot.calledModuleName() in names):
+ return False
+
+ if key: # ignore unrecognized keys with a warning
+ pywikibot.warning(
+ '{{bots|%s}} is not valid. Ignoring.' % params[0])
+
# no restricting template found
return True
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 90a4323..09eb93c 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -793,98 +793,152 @@
cached = True
user = True
- @mock.patch.object(config, 'ignore_bot_templates', False)
- def test_bot_may_edit_general(self):
- """Test that bot is allowed to edit."""
- site = self.get_site()
- user = site.user()
-
- page = pywikibot.Page(site, 'not_existent_page_for_pywikibot_tests')
- if page.exists():
+ def setUp(self):
+ """Setup test."""
+ super(TestPageBotMayEdit, self).setUp()
+ self.page = pywikibot.Page(self.site,
+ 'not_existent_page_for_pywikibot_tests')
+ if self.page.exists():
self.skipTest(
'Page {} exists! Change page name in tests/page_tests.py'
- .format(page.title()))
+ .format(self.page.title()))
+
+ @mock.patch.object(config, 'ignore_bot_templates', False)
+ def test_bot_may_edit_nobots(self):
+ """Test with {{nobots}} that bot is allowed to edit."""
+ self.page._templates = [pywikibot.Page(self.site, 'Template:Nobots')]
+ user = self.site.user()
# Ban all compliant bots (shortcut).
- page.text = '{{nobots}}'
- page._templates = [pywikibot.Page(site, 'Template:Nobots')]
- self.assertFalse(page.botMayEdit())
+ 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.
- page.text = '{{nobots|HagermanBot,Werdnabot}}'
- self.assertTrue(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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.
- page.text = '{{nobots|%s, HagermanBot,Werdnabot}}' % user
- self.assertFalse(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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.
- page.text = '{{nobots|all}}'
- self.assertFalse(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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())
+
+ @mock.patch.object(config, 'ignore_bot_templates', False)
+ def test_bot_may_edit_bots(self):
+ """Test with {{bots}} that bot is allowed to edit."""
+ self.page._templates = [pywikibot.Page(self.site, 'Template:Bots')]
+ user = self.site.user()
# Allow all bots (shortcut).
- page.text = '{{bots}}'
- page._templates = [pywikibot.Page(site, 'Template:Bots')]
- self.assertTrue(page.botMayEdit())
+ 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.
- page.text = '{{bots|allow=HagermanBot,Werdnabot}}'
- self.assertFalse(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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.
- page.text = '{{bots|deny=HagermanBot,Werdnabot}}'
- self.assertTrue(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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.
- page.text = '{{bots|allow=%s, HagermanBot}}' % user
- self.assertTrue(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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.
- page.text = '{{bots|deny=%s, HagermanBot}}' % user
- self.assertFalse(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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.
- page.text = '{{bots|allow=all}}'
- self.assertTrue(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ self.page.text = '{{bots|allow=all}}'
+ with self.subTest(template=self.page.text, user=user):
+ self.assertTrue(self.page.botMayEdit())
# Ban all compliant bots.
- page.text = '{{bots|allow=none}}'
- self.assertFalse(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ self.page.text = '{{bots|allow=none}}'
+ with self.subTest(template=self.page.text, user=user):
+ self.assertFalse(self.page.botMayEdit())
# Ban all compliant bots.
- page.text = '{{bots|deny=all}}'
- self.assertFalse(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ self.page.text = '{{bots|deny=all}}'
+ with self.subTest(template=self.page.text, user=user):
+ self.assertFalse(self.page.botMayEdit())
# Allow all bots.
- page.text = '{{bots|deny=none}}'
- self.assertTrue(page.botMayEdit(),
- '{}: {} but user={}'
- .format(page.text, page.botMayEdit(), user))
+ 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())
+
+ # Ignore empty keyword parameter with bots
+ for param in ('allow', 'deny', 'empty_parameter'):
+ self.page.text = '{{bots|%s=}}' % param
+ with self.subTest(template=self.page.text, user=user, param=param):
+ self.assertTrue(self.page.botMayEdit())
+
+ # 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_inuse(self):
+ """Test with {{inuse}} that bot is allowed to edit."""
+ self.page._templates = [pywikibot.Page(self.site, 'Template:In use')]
# Ban all users including bots.
- page.text = '{{in use}}'
- page._templates = [pywikibot.Page(site, 'Template:In use')]
- self.assertFalse(page.botMayEdit())
+ self.page.text = '{{in use}}'
+ self.assertFalse(self.page.botMayEdit())
class TestPageHistory(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/599271
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I035ed06fe400e59b2239f73d3c1780ec3647212f
Gerrit-Change-Number: 599271
Gerrit-PatchSet: 15
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/607865 )
Change subject: [IMPR] use 'isinstance' in favour of 'is type()'
......................................................................
[IMPR] use 'isinstance' in favour of 'is type()'
Due to PEP 8 object type comparisons should always use isinstance()
instead of comparing types directly.
https://www.python.org/dev/peps/pep-0008/#programming-recommendations
Change-Id: I3f493c18aa3ef873727f3fc7427dc2adcb8d519d
---
M pywikibot/date.py
M pywikibot/login.py
M pywikibot/textlib.py
3 files changed, 5 insertions(+), 5 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py
index c4e0030..9c97756 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -355,8 +355,6 @@
# A map of sitecode+pattern to (re matching object and corresponding decoders)
_escPtrnCache2 = {}
-_listTypes = [list, tuple]
-
def escapePattern2(pattern):
"""
@@ -464,7 +462,7 @@
params = encf(value)
- if type(params) in _listTypes:
+ if isinstance(params, (tuple, list)):
assert len(params) == len(decoders), (
'parameter count ({0}) does not match decoder count ({1})'
.format(len(params), len(decoders)))
diff --git a/pywikibot/login.py b/pywikibot/login.py
index 04b74c8..d9d5484 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -232,10 +232,12 @@
entry = eval(line)
except SyntaxError:
entry = None
- if type(entry) is not tuple:
+
+ if not isinstance(entry, tuple):
warn('Invalid tuple in line {0}'.format(line_nr),
_PasswordFileWarning)
continue
+
if not 2 <= len(entry) <= 4:
warn('The length of tuple in line {0} should be 2 to 4 ({1} '
'given)'.format(line_nr, entry), _PasswordFileWarning)
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index b4e7f36..5339249 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -316,7 +316,7 @@
# assume the string is a reference to a standard regex above,
# which may not yet have a site specific re compiled.
if exc in _regex_cache:
- if type(_regex_cache[exc]) is tuple:
+ if isinstance(_regex_cache[exc], tuple):
if not site and exc in ('interwiki', 'property', 'invoke',
'category', 'file'):
issue_deprecation_warning(
--
To view, visit https://gerrit.wikimedia.org/r/607865
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I3f493c18aa3ef873727f3fc7427dc2adcb8d519d
Gerrit-Change-Number: 607865
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Eranroz <eranroz89(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: VcamX <vcamx3(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/606656 )
Change subject: [cleanup] show a FutureWarning for deprecated debug and uploadByUrl parameters
......................................................................
[cleanup] show a FutureWarning for deprecated debug and uploadByUrl parameters
Change-Id: Ic96541f4f4165ced7904aa5e03f4d6619f396419
---
M pywikibot/specialbots/_upload.py
1 file changed, 3 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index eec04ad..93c905a 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -37,7 +37,7 @@
"""Upload bot."""
- @deprecated_args(uploadByUrl=None, urlEncoding='url_encoding',
+ @deprecated_args(uploadByUrl=True, urlEncoding='url_encoding',
useFilename='use_filename', keepFilename='keep_filename',
verifyDescription='verify_description',
ignoreWarning='ignore_warning', targetSite='target_site')
@@ -87,10 +87,6 @@
or aborts are set to True and that the description is also set. It
overwrites verify_description to False and keep_filename to True.
@type always: bool
-
- @deprecated: Using upload_image() is deprecated, use upload_file() with
- file_url param instead
-
"""
super(UploadRobot, self).__init__(**kwargs)
always = self.getOption('always')
@@ -392,12 +388,12 @@
return warn_code in self.ignore_warning
@deprecated('UploadRobot.upload_file()', since='20141211')
- @deprecated_args(debug=None)
+ @deprecated_args(debug=True)
def upload_image(self):
"""Upload image."""
return self.upload_file(self.url)
- @deprecated_args(debug=None)
+ @deprecated_args(debug=True)
def upload_file(self, file_url, _file_key=None, _offset=0):
"""
Upload the image at file_url to the target wiki.
--
To view, visit https://gerrit.wikimedia.org/r/606656
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic96541f4f4165ced7904aa5e03f4d6619f396419
Gerrit-Change-Number: 606656
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)