John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/244055

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.

Change-Id: Id11c23560800b66a5fccc95459abc28685a98bb9
---
M pywikibot/cosmetic_changes.py
M pywikibot/textlib.py
2 files changed, 26 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/55/244055/1

diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 169359f..7dce105 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -798,20 +798,25 @@
                       'startspace', 'gallery', 'hyperlink', 'interwiki', 
'link']
         # change <number> ccm -> <number> cm³
         text = textlib.replaceExcept(text, r'(\d)\s*&nbsp;ccm',
-                                     r'\1&nbsp;' + u'cm³', exceptions)
+                                     r'\1&nbsp;' + 'cm³', exceptions,
+                                     site=self.site)
         text = textlib.replaceExcept(text,
                                      r'(\d)\s*ccm', r'\1&nbsp;' + u'cm³',
-                                     exceptions)
+                                     exceptions,
+                                     site=self.site)
         # Solve wrong Nº sign with °C or °F
         # additional exception requested on fr-wiki for this stuff
         pattern = re.compile(u'«.*?»', re.UNICODE)
         exceptions.append(pattern)
         text = textlib.replaceExcept(text, r'(\d)\s*&nbsp;' + u'[º°]([CF])',
-                                     r'\1&nbsp;' + u'°' + r'\2', exceptions)
+                                     r'\1&nbsp;' + '°' + r'\2', exceptions,
+                                     site=self.site)
         text = textlib.replaceExcept(text, r'(\d)\s*' + u'[º°]([CF])',
-                                     r'\1&nbsp;' + u'°' + r'\2', exceptions)
+                                     r'\1&nbsp;' + '°' + r'\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):
@@ -855,12 +860,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, 'ه‌', 'ە', 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(

-- 
To view, visit https://gerrit.wikimedia.org/r/244055
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id11c23560800b66a5fccc95459abc28685a98bb9
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to