jenkins-bot has submitted this change and it was merged.
Change subject: Use explicit site for cosmetic changes ......................................................................
Use explicit site for cosmetic changes
fixTypo and fixArabicLetters used textlib.replaceExcept without an explicit site while using exception 'interwiki' which requires a site. This meant textlib.replaceExcept used pywikibot.Site to implicitly create a Site object, which could be the wrong site.
Also convert a hidden u+200C character to '\u200c'.
Change-Id: Id11c23560800b66a5fccc95459abc28685a98bb9 --- M pywikibot/cosmetic_changes.py M pywikibot/textlib.py 2 files changed, 18 insertions(+), 10 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index ef8bfc3..485769d 100755 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -799,7 +799,8 @@ text = textlib.replaceExcept(text, r'(\d)\s*(?: )?[º°]([CF])', r'\1 °\2', exceptions, site=self.site) text = textlib.replaceExcept(text, u'º([CF])', u'°' + r'\1', - exceptions) + exceptions, + site=self.site) return text
def fixArabicLetters(self, text): @@ -843,12 +844,17 @@ text = textlib.replaceExcept(text, u',', u'،', exceptions) if self.site.code == 'ckb': text = textlib.replaceExcept(text, - u'\u0647([.\u060c_<\]\s])', - u'\u06d5\1', exceptions) - text = textlib.replaceExcept(text, u'ه', u'ە', exceptions) - text = textlib.replaceExcept(text, u'ه', u'ھ', exceptions) - text = textlib.replaceExcept(text, u'ك', u'ک', exceptions) - text = textlib.replaceExcept(text, u'[ىي]', u'ی', exceptions) + '\u0647([.\u060c_<\]\s])', + '\u06d5\1', exceptions, + site=self.site) + text = textlib.replaceExcept(text, 'ه\u200c', 'ە', exceptions, + site=self.site) + text = textlib.replaceExcept(text, 'ه', 'ھ', exceptions, + site=self.site) + text = textlib.replaceExcept(text, 'ك', 'ک', exceptions, + site=self.site) + text = textlib.replaceExcept(text, '[ىي]', 'ی', exceptions, + site=self.site)
return text
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index d80ca1a..54d20eb 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -187,9 +187,6 @@
def _get_regexes(keys, site): """Fetch compiled regexes.""" - if site is None: - site = pywikibot.Site() - if not _regex_cache: _create_default_regexes()
@@ -203,6 +200,11 @@ # which may not yet have a site specific re compiled. if exc in _regex_cache: if type(_regex_cache[exc]) is tuple: + if not site: + issue_deprecation_warning( + 'site=None', 'a valid site', 3) + site = pywikibot.Site() + if (exc, site) not in _regex_cache: re_text, re_var = _regex_cache[exc] _regex_cache[(exc, site)] = re.compile(