jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/586066 )
Change subject: [cleanup] Avoid creating objects passed to str.join
......................................................................
[cleanup] Avoid creating objects passed to str.join
A tip from https://deepsource.io/blog/8-new-python-antipatterns/
Change-Id: Ibe594bd53f93b964f8a7c9edf09558bfcd24a23c
---
M pywikibot/comms/http.py
M pywikibot/site/__init__.py
M scripts/casechecker.py
M scripts/followlive.py
M scripts/interwiki.py
M scripts/replace.py
6 files changed, 19 insertions(+), 20 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index e09f880..2051afd 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -130,7 +130,7 @@
atexit.register(_flush)
USER_AGENT_PRODUCTS = {
- 'python': 'Python/' + '.'.join([str(i) for i in sys.version_info]),
+ 'python': 'Python/' + '.'.join(str(i) for i in sys.version_info),
'http_backend': 'requests/' + requests.__version__,
'pwb': 'Pywikibot/' + __version__,
}
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index f7b8471..fc016c2 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -372,9 +372,8 @@
if key not in standard_attr]
if extra:
- kwargs = ', ' + ', '.join([key + '=' + repr(value)
- for (key, value) in
- extra])
+ kwargs = ', ' + ', '.join(
+ key + '=' + repr(value) for key, value in extra)
else:
kwargs = ''
@@ -628,8 +627,8 @@
if None in result:
raise KeyError(
'Namespace identifier(s) not recognised: %s'
- % ','.join([str(identifier) for identifier, ns in zip(
- identifiers, result) if ns is None]))
+ % ','.join(str(identifier) for identifier, ns in zip(
+ identifiers, result) if ns is None))
return result
diff --git a/scripts/casechecker.py b/scripts/casechecker.py
index c666f10..7d6273f 100755
--- a/scripts/casechecker.py
+++ b/scripts/casechecker.py
@@ -229,8 +229,8 @@
% len(self.knownWords))
if len(self.knownWords) > 0:
pywikibot.log('Whitelist: '
- + ', '.join([self.MakeLink(i, False)
- for i in self.knownWords]))
+ + ', '.join(self.MakeLink(i, False)
+ for i in self.knownWords))
else:
pywikibot.output('Whitelist is not known for language %s'
% self.site.code)
@@ -541,7 +541,7 @@
suggestions = list(mapLcl.values()) + list(mapLat.values())
if len(suggestions) > 0:
infoText += ', word suggestions: ' + ', '.join(
- [self.ColorCodeWord(t) for t in suggestions])
+ self.ColorCodeWord(t) for t in suggestions)
else:
infoText += ', no suggestions'
else:
@@ -572,7 +572,7 @@
if len(possibleAlternatives) > 0:
infoText += ', can be converted to ' + ', '.join(
- [self.MakeLink(t) for t in possibleAlternatives])
+ self.MakeLink(t) for t in possibleAlternatives)
else:
infoText += ', no suggestions'
return (infoText, possibleAlternatives)
@@ -712,7 +712,7 @@
def PutNewPage(self, pageObj, pageTxt, msg):
"""Save new page."""
title = pageObj.title(as_link=True, textlink=True)
- coloredMsg = ', '.join([self.ColorCodeWord(m) for m in msg])
+ coloredMsg = ', '.join(self.ColorCodeWord(m) for m in msg)
if pageObj.text == pageTxt:
self.WikiLog('* Error: Text replacement failed in %s (%s)'
% (self.MakeLink(title, False), coloredMsg))
diff --git a/scripts/followlive.py b/scripts/followlive.py
index eb54db9..3c1ecad 100644
--- a/scripts/followlive.py
+++ b/scripts/followlive.py
@@ -539,8 +539,8 @@
"""Setup bot before running."""
self.questionlist = {
i: t for i, t in enumerate(templates[self.site.code], start=1)}
- questions = '\n'.join(('{}) {}'.format(k, v)
- for k, v in self.questionlist.items()))
+ questions = '\n'.join('{}) {}'.format(k, v)
+ for k, v in self.questionlist.items())
self.question = questions + self.question
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index d4e5e76..8f9fd66 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1860,7 +1860,7 @@
# Allow for special case of a self-pointing interwiki link
if removing and removing != [page.site]:
self.problem('Found incorrect link to {} in {}'
- .format(', '.join([x.code for x in removing]), page),
+ .format(', '.join(x.code for x in removing), page),
createneed=False)
ask = True
if self.conf.force or self.conf.cleanup:
@@ -1944,7 +1944,7 @@
raise GiveUpOnPage('User asked us to give up')
else:
raise LinkMustBeRemoved('Found incorrect link to {} in {}'.format(
- ', '.join([x.code for x in removing]), page))
+ ', '.join(x.code for x in removing), page))
def reportBacklinks(self, new, updatedSites):
"""
diff --git a/scripts/replace.py b/scripts/replace.py
index b2343dd..3a9d5a4 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -1171,13 +1171,13 @@
elif useSql:
if not sql_query:
whereClause = 'WHERE (%s)' % ' OR '.join(
- ["old_text RLIKE '%s'" % prepareRegexForMySQL(
- old_regexp.pattern) for (old_regexp, new_text)
- in replacements])
+ "old_text RLIKE '%s'"
+ % prepareRegexForMySQL(old_regexp.pattern)
+ for (old_regexp, new_text) in replacements)
if exceptions:
exceptClause = 'AND NOT (%s)' % ' OR '.join(
- ["old_text RLIKE '%s'" % prepareRegexForMySQL(exc.pattern)
- for exc in exceptions])
+ "old_text RLIKE '%s'" % prepareRegexForMySQL(exc.pattern)
+ for exc in exceptions)
else:
exceptClause = ''
query = sql_query or """
--
To view, visit https://gerrit.wikimedia.org/r/586066
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: Ibe594bd53f93b964f8a7c9edf09558bfcd24a23c
Gerrit-Change-Number: 586066
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
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)
Gerrit-CC: Dvorapa <dvorapa(a)seznam.cz>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/586017 )
Change subject: [bugfix] insert absolute path to sys.path
......................................................................
[bugfix] insert absolute path to sys.path
insert absolute path to sys.path because sys.path[0], which is usual
the absolute path, is overridden by os.path.dirname(filename) within
run_python_file function
Bug: T249427
Change-Id: I7a16744bbc3998909ffd3b7bd633a92592259081
---
M HISTORY.rst
M pwb.py
2 files changed, 4 insertions(+), 2 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index a182023..40fa119 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -4,6 +4,7 @@
Current release
---------------
+* Fix regression of combining sys.path in pwb.py wrapper (T249427)
* pagengenerators.py no more support 'oursql' or 'MySQLdb'. It now solely
support PyMySQL https://pypi.org/project/PyMySQL/ (T243154, T89976)
* Bugfixes and improvements
diff --git a/pwb.py b/pwb.py
index 76018b3..e50d678 100755
--- a/pwb.py
+++ b/pwb.py
@@ -205,8 +205,9 @@
# or it is the absolute path for the directory of pwb.py
absolute_path = abspath(os.path.dirname(sys.argv[0]))
-if absolute_path not in sys.path[:2]:
- sys.path.insert(1, absolute_path)
+# add absolute path because sys.path[0] is overridden
+# with os.path.dirname(filename) within run_python_file
+sys.path.insert(1, absolute_path)
if not check_modules():
sys.exit()
--
To view, visit https://gerrit.wikimedia.org/r/586017
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: I7a16744bbc3998909ffd3b7bd633a92592259081
Gerrit-Change-Number: 586017
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/585881 )
Change subject: [cleanup] Desupport SkipPageError with BaseBot
......................................................................
[cleanup] Desupport SkipPageError with BaseBot
Throw a FutureWarning when SkipPageError is used for a BaseBot
that this deprecated skipping method can be removed shortly.
Change-Id: I9c43e7f16b94d7ec904484ecf8b108b735bffbba
---
M pywikibot/bot.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 74427fd..a2b65ca 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1405,6 +1405,7 @@
except SkipPageError as e:
issue_deprecation_warning('Use of SkipPageError',
'BaseBot.skip_page() method',
+ warning_class=FutureWarning,
since='20180522')
pywikibot.warning('Skipped "{0}" due to: {1}'.format(
item, e.reason))
--
To view, visit https://gerrit.wikimedia.org/r/585881
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: I9c43e7f16b94d7ec904484ecf8b108b735bffbba
Gerrit-Change-Number: 585881
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/585839 )
Change subject: [IMPR] Update Dockerfile to Python 3.5
......................................................................
[IMPR] Update Dockerfile to Python 3.5
- There were various issues with Python 3.4 and setuptools, pip
and some other PyPI packages as well. Docker is supposed to have
issueless installation and ready environment, therefore updating
to Python 3.5 (supported by Debian Stretch or newer)
Change-Id: Ife2a7e765e0efdbe73b56851992bcf04a080c7cf
---
M Dockerfile
1 file changed, 5 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Dockerfile b/Dockerfile
index 8eb855f..e4bcd00 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,9 @@
-FROM debian:jessie
+FROM debian:stretch
-MAINTAINER Pywikibot Team <pywikibot(a)lists.wikimedia.org>
+MAINTAINER Pywikibot team <pywikibot(a)lists.wikimedia.org>
RUN apt-get update
-RUN apt-get install --yes python3.4 python3-pip git libjpeg62-turbo libjpeg62-turbo-dev zlib1g zlib1g-dev locales
+RUN apt-get install --yes python3.5 python3-pip git libjpeg62-turbo libjpeg62-turbo-dev zlib1g zlib1g-dev locales
# Setup the C.UTF-8 Locale, since otherwise it defaults to an ASCII one
RUN locale-gen C.UTF-8
@@ -12,11 +12,11 @@
# TODO: Add this to the default PYTHONPATH and PATH?
ADD . /srv/pwb
-# pip version in jessie is too old :(
+# pip version in stretch is too old :(
RUN pip3 install -U pip
RUN pip3 install -r /srv/pwb/requirements.txt
RUN pip3 install -r /srv/pwb/dev-requirements.txt
RUN pip3 install /srv/pwb/
-CMD /bin/bash
+CMD /bin/bash
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/585839
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: Ife2a7e765e0efdbe73b56851992bcf04a080c7cf
Gerrit-Change-Number: 585839
Gerrit-PatchSet: 2
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
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/585333 )
Change subject: [bugfix] Clear second level domain cookies after logout
......................................................................
[bugfix] Clear second level domain cookies after logout
To solve this issue, there are two options:
Option A (this patch):
- clear second level domain cookies in the current requests session
directly after logout (this session logout) and after "badtoken"
response (parallel session logout)
Option B:
- make separate session and *.lwp file for every site
Bug: T224712
Change-Id: I0e31ecaf14650ed499c82601a2afda6e9009f2a5
---
M pywikibot/data/api.py
M pywikibot/site/__init__.py
M tests/site_tests.py
3 files changed, 48 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 499722b..9560b53 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -37,6 +37,7 @@
Server504Error, Server414Error, FatalServerError, NoUsername,
Error, TimeoutError, MaxlagTimeoutError, InvalidTitle, UnsupportedPage
)
+from pywikibot.family import SubdomainFamily
from pywikibot.tools import (
deprecated, itergroup, PY2, PYTHON_VERSION,
getargspec, UnicodeType, remove_last_args
@@ -101,6 +102,21 @@
r'Waiting for [\w.: ]+: (?P<lag>\d+(?:\.\d+)?) seconds? lagged')
+def _invalidate_superior_cookies(family):
+ """
+ Clear cookies for site's second level domain.
+
+ get_login_token() will generate new cookies needed.
+ This is a workaround for requests bug, see T224712
+ and https://github.com/psf/requests/issues/5411
+ for more details.
+ """
+ if isinstance(family, SubdomainFamily):
+ for cookie in http.cookie_jar:
+ if family.domain == cookie.domain:
+ http.cookie_jar.clear(cookie.domain, cookie.path, cookie.name)
+
+
class APIError(Error):
"""The wiki site returned an error message."""
@@ -1916,6 +1932,9 @@
'invalidated them.'
.format(self.site.user(),
'", "'.join(sorted(set(invalid_param.values())))))
+ # invalidate superior wiki cookies (T224712)
+ _invalidate_superior_cookies(self.site.family)
+ # request new token(s) instead of invalid
self.site.tokens.load_tokens(set(invalid_param.values()))
# fix parameters; lets hope that it doesn't mistake actual
# parameters as tokens
@@ -3180,6 +3199,8 @@
# force relogin and generate fresh one
pywikibot.error('Received incorrect login token. '
'Forcing re-login.')
+ # invalidate superior wiki cookies (T224712)
+ _invalidate_superior_cookies(self.site.family)
continue
elif (status == 'Throttled' or status == self.keyword('fail')
and (response['messagecode'] == 'login-throttled'
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 7729276..d99ad80 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -2135,6 +2135,9 @@
self.tokens = TokenWallet(self)
self._paraminfo = api.ParamInfo(self)
+ # Clear also cookies for site's second level domain (T224712)
+ api._invalidate_superior_cookies(self.family)
+
def getuserinfo(self, force=False):
"""Retrieve userinfo from site and store in _userinfo attribute.
diff --git a/tests/site_tests.py b/tests/site_tests.py
index e772cdc..0873eb6 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -3864,6 +3864,30 @@
self.assertIsNone(site.user())
+class TestClearCookies(TestCase):
+ """Test cookies are cleared after logout."""
+
+ user = True
+
+ family = 'wikisource'
+ code = 'zh'
+
+ def test_clear_cookies(self):
+ """Test cookies are cleared (T224712)."""
+ site = self.get_site()
+ site.login()
+ site2 = pywikibot.Site('mul', 'wikisource', user=site.username())
+ site2.login()
+ site.logout()
+
+ raised = False
+ try:
+ site.login()
+ except Exception as e:
+ raised = e
+ self.assertFalse(raised)
+
+
if __name__ == '__main__': # pragma: no cover
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/585333
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: I0e31ecaf14650ed499c82601a2afda6e9009f2a5
Gerrit-Change-Number: 585333
Gerrit-PatchSet: 16
Gerrit-Owner: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Urbanecm <martin.urbanec(a)wikimedia.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)