jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/689079 )
Change subject: [bugfix] Enable get_userpage() with TestCase
......................................................................
[bugfix] Enable get_userpage() with TestCase
TestCase has mixins which provides several methods.
To enable get_userpage() the RequireLoginMixin must
be activated which can be done with login = True
Bug: T282570
Change-Id: Idb762c93ebcf1b20d39f292eaecaac00919538e8
---
M tests/thanks_tests.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
Happy5214: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/thanks_tests.py b/tests/thanks_tests.py
index fd385db..dda33b7 100644
--- a/tests/thanks_tests.py
+++ b/tests/thanks_tests.py
@@ -21,6 +21,7 @@
family = 'wikipedia'
code = 'test'
+ login = True
write = True
def test_thank_revision(self):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/689079
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: Idb762c93ebcf1b20d39f292eaecaac00919538e8
Gerrit-Change-Number: 689079
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Darthbhyrava <hbhyrava(a)gmail.com>
Gerrit-Reviewer: Happy5214 <happy5214(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/+/689013 )
Change subject: [doc] bot owner can specify their own session object
......................................................................
[doc] bot owner can specify their own session object
- Add documentation how to use their own session object with Pywikibot.
- Make http.flush() public that it can be used from external
(on their own risk)
Bug: T185561
Change-Id: I229a1c5e2262546221e54aed68942c7f23be07cc
---
M pywikibot/comms/http.py
1 file changed, 14 insertions(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 3a6c2f3..e072b24 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -9,6 +9,17 @@
- Translate site objects with query strings into URLs
- URL-encoding all data
- Basic HTTP error handling
+
+This module creates and uses its own C{requests.Session} object.
+The session is closed if the module terminates.
+If required you can use your own Session object passing it to the
+C{http.session} variable::
+
+ from pywikibot.comms import http
+ session = requests.Session()
+ http.session = session
+
+L{flush()} can be called to close the session object.
"""
#
# (C) Pywikibot team, 2007-2021
@@ -72,7 +83,8 @@
# Prepare flush on quit
-def _flush():
+def flush():
+ """Close the session object. This is called when the module terminates."""
log('Closing network session.')
session.close()
@@ -82,7 +94,7 @@
log('Network session closed.')
-atexit.register(_flush)
+atexit.register(flush)
USER_AGENT_PRODUCTS = {
'python': 'Python/' + '.'.join(str(i) for i in sys.version_info),
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/689013
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: I229a1c5e2262546221e54aed68942c7f23be07cc
Gerrit-Change-Number: 689013
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/689025 )
Change subject: [tests] add test.wikidata.org and beta.wikidata.org to test_codes
......................................................................
[tests] add test.wikidata.org and beta.wikidata.org to test_codes
test_codes can be used with write tests, see SiteWriteMixin.
Change-Id: I3e2fee329e11e42361b7ac70d4eb9107d5f072c1
---
M pywikibot/families/wikidata_family.py
1 file changed, 3 insertions(+), 0 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/families/wikidata_family.py b/pywikibot/families/wikidata_family.py
index c296b45..06e1391 100644
--- a/pywikibot/families/wikidata_family.py
+++ b/pywikibot/families/wikidata_family.py
@@ -20,6 +20,9 @@
'beta': 'wikidata.beta.wmflabs.org',
}
+ # Sites we want to edit but not count as real languages
+ test_codes = ['test', 'beta']
+
interwiki_forward = 'wikipedia'
category_redirect_templates = {
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/689025
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: I3e2fee329e11e42361b7ac70d4eb9107d5f072c1
Gerrit-Change-Number: 689025
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(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/+/689073 )
Change subject: [bugfix] use a set to get different sites inside Family.from_url
......................................................................
[bugfix] use a set to get different sites inside Family.from_url
Family.from_url looks at codes, test_codes and closed_wikis for
valid sites. Like in wikidata test_codes may have some entries
which are in Family.langs.keys() already. Use a set for
matched_sites to ignore duplicated entries.
Bug: T282560
Change-Id: Ibeaa958f97163e06983eef66b5507f2582859ca5
---
M pywikibot/family.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index ec3a41e..d41ef5c 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -861,7 +861,7 @@
else:
return None
- matched_sites = []
+ matched_sites = set()
for code in chain(self.codes,
getattr(self, 'test_codes', ()),
getattr(self, 'closed_wikis', ()),
@@ -874,11 +874,11 @@
for iw_url in site._interwiki_urls():
if path.startswith(iw_url):
- matched_sites += [site]
+ matched_sites.add(site)
break
if len(matched_sites) == 1:
- return matched_sites[0].code
+ return matched_sites.pop().code
if not matched_sites:
return None
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/689073
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: Ibeaa958f97163e06983eef66b5507f2582859ca5
Gerrit-Change-Number: 689073
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/688629 )
Change subject: Update many-values comparison with "in"
......................................................................
Update many-values comparison with "in"
Rather than checking if a variable is equal to many values by comparing its equality to these
values, it is faster, less verbose, and more readable to check if this variable is in a tuple
containing the many values.
Bug: T282450
Change-Id: I83eb74b1be7f6e0eeb278ddf3a1596892ebd7e96
---
M pywikibot/comms/http.py
M pywikibot/page/__init__.py
M pywikibot/plural.py
M pywikibot/userinterfaces/win32_unicode.py
M scripts/category_redirect.py
M scripts/commonscat.py
M scripts/protect.py
7 files changed, 10 insertions(+), 10 deletions(-)
Approvals:
JJMC89: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 8a7383a..3a6c2f3 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -98,7 +98,7 @@
def get_value(self, key, args, kwargs):
"""Get field as usual except for version and revision."""
# This is the Pywikibot version; also map it to {revision} at present.
- if key == 'version' or key == 'revision':
+ if key in ('version', 'revision'):
return pywikibot.version.getversiondict()['rev']
return super().get_value(key, args, kwargs)
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 40f7112..ecd5672 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -310,8 +310,8 @@
or (allow_interwiki
and (self.site.family.name != target_family
or self.site.code != target_code)):
- if self.site.family.name != target_family \
- and self.site.family.name != self.site.code:
+ if self.site.family.name not in (
+ target_family, self.site.code):
title = '{site.family.name}:{site.code}:{title}'.format(
site=self.site, title=title)
else:
diff --git a/pywikibot/plural.py b/pywikibot/plural.py
index 6cef87a..fc786f0 100644
--- a/pywikibot/plural.py
+++ b/pywikibot/plural.py
@@ -27,7 +27,7 @@
'cy': {'nplurals': 4, 'plural': lambda n:
0 if (n == 1) else
1 if (n == 2) else
- 2 if (n != 8 and n != 11) else
+ 2 if n not in (8, 11) else
3},
'ga': {'nplurals': 5, 'plural': lambda n:
0 if (n == 1) else
@@ -36,8 +36,8 @@
3 if (n < 11) else
4},
'gd': {'nplurals': 4, 'plural': lambda n:
- 0 if (n == 1 or n == 11) else
- 1 if (n == 2 or n == 12) else
+ 0 if n in (1, 11) else
+ 1 if n in (2, 12) else
2 if (2 < n < 20) else
3},
'is': {'nplurals': 2, 'plural': lambda n: (n % 10 != 1 or n % 100 == 11)},
diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py
index 7962408..f9702613 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -130,7 +130,7 @@
retval = WriteConsoleW(self._hConsole, text,
min(remaining, 10000),
byref(n), None)
- if retval == 0 or n.value == 0:
+ if 0 in (retval, n.value):
msg = 'WriteConsoleW returned {!r}, n.value = {!r}' \
.format(retval, n.value)
raise IOError(msg)
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 69f1bc0..4945493 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -402,7 +402,7 @@
continue
if dest.isCategoryRedirect():
double = dest.getCategoryRedirectTarget()
- if double == dest or double == cat:
+ if double in (dest, cat):
message = i18n.twtranslate(
self.site, 'category_redirect-log-loop',
{'oldcat': dest.title(as_link=True, textlink=True)})
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 32ddc64..2a88542 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -334,7 +334,7 @@
newtemplate='', newcat='', linktitle='',
description=NotImplemented):
"""Change the current commonscat template and target."""
- if oldcat == '3=S' or linktitle == '3=S':
+ if '3=S' in (oldcat, linktitle):
return # TODO: handle additional param on de-wiki
if not linktitle and (page.title().lower() in oldcat.lower()
diff --git a/scripts/protect.py b/scripts/protect.py
index b2a4b18..ce3eff7 100755
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -228,7 +228,7 @@
level = check_protection_level(p_type, level, protection_levels,
default_level)
# '' is equivalent to 'all'
- if level == 'none' or level == '':
+ if level in ('none', ''):
level = 'all'
combined_protections[p_type] = level
if not options.get('summary'):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/688629
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: I83eb74b1be7f6e0eeb278ddf3a1596892ebd7e96
Gerrit-Change-Number: 688629
Gerrit-PatchSet: 3
Gerrit-Owner: Chris Maynor <cmchrismaynor(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/688417 )
Change subject: [C0201] iterating dictionary without keys() method
......................................................................
[C0201] iterating dictionary without keys() method
Change-Id: I5c59c6fa2a9825a4970630065bac03e603cebac4
---
M pywikibot/site/_datasite.py
M scripts/template.py
M tests/diff_tests.py
3 files changed, 4 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index 5d97952..01b5a35 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -53,7 +53,7 @@
def _cache_entity_namespaces(self):
"""Find namespaces for each known wikibase entity type."""
self._entity_namespaces = {}
- for entity_type in self._type_to_class.keys():
+ for entity_type in self._type_to_class:
for namespace in self.namespaces.values():
if not hasattr(namespace, 'defaultcontentmodel'):
continue
diff --git a/scripts/template.py b/scripts/template.py
index 0c5122d..f87d82b 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -280,7 +280,7 @@
return
old_templates = []
- for template_name in templates.keys():
+ for template_name in templates:
old_template = pywikibot.Page(site, template_name, ns=10)
old_templates.append(old_template)
diff --git a/tests/diff_tests.py b/tests/diff_tests.py
index 950dfa3..1808947 100644
--- a/tests/diff_tests.py
+++ b/tests/diff_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
"""Test diff module."""
#
-# (C) Pywikibot team, 2016-2020
+# (C) Pywikibot team, 2016-2021
#
# Distributed under the terms of the MIT license.
from contextlib import suppress
@@ -176,7 +176,7 @@
"""Test PatchManager."""
for case in self.cases:
p = PatchManager(case[0], case[1])
- for key in case[2].keys(): # for each hunk
+ for key in case[2]: # for each hunk
with self.subTest(case=case[0].strip(), key=key):
self.assertEqual(p.hunks[key].diff_plain_text,
case[2][key])
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/688417
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: I5c59c6fa2a9825a4970630065bac03e603cebac4
Gerrit-Change-Number: 688417
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged