jenkins-bot merged this change.

View Change

Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[cleanup] Remove deactivated code in cosmetic_changes.py

- remove deactivated code in cosmetic_changes.py but save it in T57185
- use textlib.NON_LATIN_DIGITS for fa-digits
- use string.format() in favour of modula operator
- return text in commonsfiledesc due to PEP 8

Change-Id: I04c725b3cb93bfcba3c1576eb5775ca359c25e78
---
M pywikibot/cosmetic_changes.py
1 file changed, 8 insertions(+), 32 deletions(-)

diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 2f5666e..1baba11 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -272,8 +272,8 @@
result = method(text)
except Exception as e:
if self.ignore == CANCEL_METHOD:
- pywikibot.warning('Unable to perform "{0}" on "{1}"!'.format(
- method.__name__, self.title))
+ pywikibot.warning('Unable to perform "{}" on "{}"!'
+ .format(method.__name__, self.title))
pywikibot.exception(e)
else:
raise
@@ -945,21 +945,13 @@
'startspace',
'inputbox',
]
- # FIXME: use textlib.NON_LATIN_DIGITS
- # valid digits
- digits = {
- 'ckb': ('٠١٢٣٤٥٦٧٨٩', 'fa'),
- 'fa': ('۰۱۲۳۴۵۶۷۸۹', 'ckb'),
- }
- faChrs = 'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + digits['fa'][0]

- # For replacing old digits by new one
- new, old_key = digits[self.site.code]
- old = digits[old_key][0]
+ digits = textlib.NON_LATIN_DIGITS
+ faChrs = 'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + digits['fa']

# not to let bot edits in latin content
- exceptions.append(re.compile('[^%(fa)s] *?\"*? *?, *?[^%(fa)s]'
- % {'fa': faChrs}))
+ exceptions.append(re.compile('[^{fa}] *?"*? *?, *?[^{fa}]'
+ .format(fa=faChrs)))
text = textlib.replaceExcept(text, ',', '،', exceptions,
site=self.site)
if self.site.code == 'ckb':
@@ -978,23 +970,6 @@

return text

- # FIXME: split this function into two.
- # replace persian/arabic digits
- # deactivated due to bug T57185
- for i in range(0, 10):
- text = textlib.replaceExcept(text, old[i], new[i], exceptions)
- # do not change digits in class, style and table params
- pattern = re.compile(r'\w+=(".+?"|\d+)', re.UNICODE)
- exceptions.append(pattern)
- # do not change digits inside html-tags
- pattern = re.compile('<[/]*?[^</]+?[/]*?>', re.UNICODE)
- exceptions.append(pattern)
- exceptions.append('table') # exclude tables for now
- # replace digits
- for i in range(0, 10):
- text = textlib.replaceExcept(text, str(i), new[i], exceptions)
- return text
-
def commonsfiledesc(self, text):
"""
Clean up file descriptions on the Wikimedia Commons.
@@ -1006,7 +981,8 @@
https://commons.wikimedia.org/wiki/Commons:Tools/pywiki_file_description_cleanup
"""
if self.site.sitename != 'commons:commons' or self.namespace == 6:
- return
+ return text
+
# section headers to {{int:}} versions
exceptions = ['comment', 'includeonly', 'math', 'noinclude', 'nowiki',
'pre', 'source', 'ref', 'timeline']

To view, visit change 606988. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I04c725b3cb93bfcba3c1576eb5775ca359c25e78
Gerrit-Change-Number: 606988
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: AbdealiJK <abdealikothari@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)