jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/734213 )
Change subject: [bugfix] Update update_linktrails.py ......................................................................
[bugfix] Update update_linktrails.py
- use representation string to get formatted string including quotes - unprintable characters are converted to escape sequences with repr(), therefore convert them to characters again - fix UserWarning
Change-Id: Ia3681017530e081b2b2727d14b7540b7a4a8b388 --- M scripts/maintenance/update_linktrails.py 1 file changed, 12 insertions(+), 5 deletions(-)
Approvals: Meno25: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/maintenance/update_linktrails.py b/scripts/maintenance/update_linktrails.py index f8306b2..b0ac04a 100755 --- a/scripts/maintenance/update_linktrails.py +++ b/scripts/maintenance/update_linktrails.py @@ -25,15 +25,22 @@
def format_string(code: str, pattern: str) -> str: """Format a single pattern line.""" - fmt = ' ' * 8 + "'{}': '{}'" + fmt = ' ' * 8 + "'{}': {!r}" code_len = len(code) pattern_len = len(pattern) - if pattern_len > 63 - code_len: + + if pattern_len > 64 - code_len: index = pattern_len // 2 result = fmt.format(code, pattern[:index]) + '\n' - result += ' ' * (code_len + 12) + "'{}',\n".format(pattern[index:]) + result += ' ' * (code_len + 12) + repr(pattern[index:]) else: - result = fmt.format(code, pattern) + ',\n' + result = fmt.format(code, pattern) + + result += ',\n' + # convert escape sequences of unprintable characters to unicode + result = re.sub(r'\u([a-f0-9]{4})', + lambda match: chr(int(match.group(1), 16)), result) + return result
@@ -57,7 +64,7 @@ 'Site wikipedia:[{}]+ instantiated using different code' .format(CODE_CHARACTERS), category=UserWarning, - filename=r'.+pywikibot.tools._deprecate.py'): + filename=r'.+update_linktrails.py'): site = pywikibot.Site(code, 'wikipedia')
if isinstance(site, pywikibot.site.RemovedSite):
pywikibot-commits@lists.wikimedia.org