jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330579?usp=email )
Change subject: tools: Use isdisjoint for invisible character check
......................................................................
tools: Use isdisjoint for invisible character check
Delegate the overlap check to frozenset.isdisjoint instead of iterating
through a Python generator.
Change-Id: I4822f5f9684e7f184f712c728458166c0a0bbbbe
---
M pywikibot/tools/chars.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/chars.py b/pywikibot/tools/chars.py
index 9ed74f1..c49d8a4 100644
--- a/pywikibot/tools/chars.py
+++ b/pywikibot/tools/chars.py
@@ -24,7 +24,7 @@
def contains_invisible(text):
"""Return True if the text contain any of the invisible characters."""
- return any(char in _invisible_chars for char in text)
+ return not _invisible_chars.isdisjoint(text)
def replace_invisible(text):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330579?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4822f5f9684e7f184f712c728458166c0a0bbbbe
Gerrit-Change-Number: 1330579
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <mahveotm(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1332488?usp=email )
Change subject: tests: Fix non-chunked filekey continuation
......................................................................
tests: Fix non-chunked filekey continuation
Accept known duplicate and history warnings which can accumulate for the
persistent upload fixture while still requiring the core warnings.
Resume the captured stash with its file key and offset so the test exercises
continuation instead of starting a separate upload.
Bug: T367314
Change-Id: If59d96a6c6b1f3ccb1e1b5e1f6c4ded089ffc62f
---
M tests/upload_tests.py
1 file changed, 22 insertions(+), 11 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/tests/upload_tests.py b/tests/upload_tests.py
index 87e66ad..76e0553 100755
--- a/tests/upload_tests.py
+++ b/tests/upload_tests.py
@@ -300,20 +300,24 @@
def _init_upload(self, chunk_size) -> None:
"""Do an initial upload causing an abort because of warnings."""
+ required_warns = {'exists'} if chunk_size else {'duplicate', 'exists'}
+ # The persistent test file may have further duplicate/history warnings.
+ allowed_warns = required_warns | {
+ 'duplicate-archive', 'duplicateversions', 'nochange'}
+
def warn_callback(warnings) -> None:
"""A simple callback not automatically finishing the upload."""
- self.assertCountEqual([w.code for w in warnings], expected_warns)
- # by now we know there are only two but just make sure
- self.assertLength(warnings, expected_warns)
- self.assertIn(len(expected_warns), [1, 2])
- if len(expected_warns) == 2:
- self.assertEqual(warnings[0].file_key, warnings[1].file_key)
- self.assertEqual(warnings[0].offset, warnings[1].offset)
+ self.assertTrue(warnings)
+ warning_codes = {warning.code for warning in warnings}
+ self.assertLessEqual(required_warns, warning_codes)
+ self.assertLessEqual(warning_codes, allowed_warns)
+ self.assertTrue(all(warning.file_key == warnings[0].file_key
+ for warning in warnings))
+ self.assertTrue(all(warning.offset == warnings[0].offset
+ for warning in warnings))
self._file_key = warnings[0].file_key
self._offset = warnings[0].offset
- expected_warns = ['exists'] if chunk_size else ['duplicate', 'exists']
-
# First upload the warning with warnings enabled
page = pywikibot.FilePage(self.site, 'MP_sounds-pwb.png')
self.assertNotHasAttr(self, '_file_key')
@@ -348,14 +352,21 @@
def _test_continue_filekey(self, chunk_size) -> None:
"""Test uploading a chunk first and finish in a separate upload."""
self._init_upload(chunk_size)
- self._finish_upload(chunk_size, self.sounds_png)
+ page = pywikibot.FilePage(self.site, 'MP_sounds-pwb.png')
+ uploader = Uploader(
+ self.site, page, source_filename=self.sounds_png,
+ comment='pywikibot test', text=page.text,
+ chunk_size=chunk_size,
+ ignore_warnings=True, report_success=False)
+ self.assertTrue(uploader._upload(
+ ignore_warnings=True, report_success=False,
+ file_key=self._file_key, offset=self._offset))
# Check if it's still cached
with self.assertAPIError('siiinvalidsessiondata') as cm:
self.site.stash_info(self._file_key)
self.assertStartsWith(cm.exception.info, 'File not found')
- @unittest.expectedFailure # T367314
def test_continue_filekey_once(self) -> None:
"""Test continuing to upload a file without using chunked mode."""
self._test_continue_filekey(0)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1332488?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If59d96a6c6b1f3ccb1e1b5e1f6c4ded089ffc62f
Gerrit-Change-Number: 1332488
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <mahveotm(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330568?usp=email )
Change subject: http: Simplify user-agent username quoting
......................................................................
http: Simplify user-agent username quoting
Use str.isascii() instead of exception-based ASCII detection.
Pass Unicode strings directly to urllib.parse.quote.
Change-Id: I75542833faec51724fd06413e70c640d6bf12fcb
---
M pywikibot/comms/http.py
1 file changed, 7 insertions(+), 13 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 8eecccd..a410d7a 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -205,8 +205,7 @@
To achieve that, this function:
- replaces spaces (' ') with '_'
- - encodes the username as 'utf-8' and if the username is not ASCII
- - URL encodes the username if it is not ASCII, or contains '%'
+ - URL encodes the username if it is not ASCII or contains '%'
.. version-changed:: 11.0
If *username* is not given, get it from environment variables
@@ -219,17 +218,12 @@
return ''
username = username.replace(' ', '_') # Avoid spaces or %20.
- try:
- username.encode('ascii') # just test, but not actually use it
- except UnicodeEncodeError:
- username = quote(username.encode('utf-8'))
- else:
- # % is legal in the default $wgLegalTitleChars
- # This is so that ops know the real pywikibot will not
- # allow a useragent in the username to allow through a hand-coded
- # percent-encoded value.
- if '%' in username:
- username = quote(username)
+ # % is legal in the default $wgLegalTitleChars
+ # This is so that ops know the real pywikibot will not
+ # allow a useragent in the username to allow through a hand-coded
+ # percent-encoded value.
+ if '%' in username or not username.isascii():
+ username = quote(username)
return username
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330568?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I75542833faec51724fd06413e70c640d6bf12fcb
Gerrit-Change-Number: 1330568
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <mahveotm(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330566?usp=email )
Change subject: pagegenerators: Use removesuffix for schema names
......................................................................
pagegenerators: Use removesuffix for schema names
Normalize Superset schema names with str.removesuffix instead of
invoking the regular expression engine for each value.
Change-Id: Idd30da797ba3d136e9b35c65744e1d2936ab3dc0
---
M pywikibot/pagegenerators/_generators.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/pagegenerators/_generators.py b/pywikibot/pagegenerators/_generators.py
index 5eb3f45..3ae65d8 100644
--- a/pywikibot/pagegenerators/_generators.py
+++ b/pywikibot/pagegenerators/_generators.py
@@ -1148,14 +1148,14 @@
if not schema_name:
raise TypeError('Schema name or site must be provided.')
- wikidb = re.sub('_p$', '', schema_name)
+ wikidb = schema_name.removesuffix('_p')
site = pywikibot.site.APISite.fromDBName(wikidb)
for row in rows:
# If page_wikidb column in SQL result then use it to retrieve site
if 'page_wikidb' in row:
# remove "_p" suffix
- wikidb = re.sub('_p$', '', row['page_wikidb'])
+ wikidb = row['page_wikidb'].removesuffix('_p')
# Caching sites
if wikidb not in sites:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1330566?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idd30da797ba3d136e9b35c65744e1d2936ab3dc0
Gerrit-Change-Number: 1330566
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <mahveotm(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot