jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/462404 )

Change subject: [cleanup] cleanup scripts/replace.py
......................................................................

[cleanup] cleanup scripts/replace.py

- remove preleading "u" from strings
- use single quotes for string literals and double quotes
  **only** if they consist of single quotes within them
- use str.format(...) instead of modulo for type specifier
  arguments
- use "+" to concatenate strings in some cases

Change-Id: I23723262299d44ca02f12f10e393f19a40bd9d2c
---
M scripts/replace.py
1 file changed, 53 insertions(+), 51 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/replace.py b/scripts/replace.py
index f36d6d2..dd6924d 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -430,9 +430,9 @@
         self.skipping = bool(xmlStart)

         self.excsInside = []
-        if "inside-tags" in self.exceptions:
+        if 'inside-tags' in self.exceptions:
             self.excsInside += self.exceptions['inside-tags']
-        if "inside" in self.exceptions:
+        if 'inside' in self.exceptions:
             self.excsInside += self.exceptions['inside']
         from pywikibot import xmlreader
         if site:
@@ -468,8 +468,8 @@
             try:
                 if not self.skipping:
                     pywikibot.output(
-                        u'To resume, use "-xmlstart:%s" on the command line.'
-                        % entry.title)
+                        'To resume, use "-xmlstart:{0}" on the command line.'
+                        .format(entry.title))
             except NameError:
                 pass

@@ -479,11 +479,11 @@

         @rtype: bool
         """
-        if "title" in self.exceptions:
+        if 'title' in self.exceptions:
             for exc in self.exceptions['title']:
                 if exc.search(title):
                     return True
-        if "require-title" in self.exceptions:
+        if 'require-title' in self.exceptions:
             for req in self.exceptions['require-title']:
                 if not req.search(title):  # if not all requirements are met:
                     return True
@@ -496,7 +496,7 @@

         @rtype: bool
         """
-        if "text-contains" in self.exceptions:
+        if 'text-contains' in self.exceptions:
             for exc in self.exceptions['text-contains']:
                 if exc.search(text):
                     return True
@@ -609,7 +609,7 @@

         @rtype: bool
         """
-        if "text-contains" in self.exceptions:
+        if 'text-contains' in self.exceptions:
             for exc in self.exceptions['text-contains']:
                 if exc.search(original_text):
                     return True
@@ -710,11 +710,11 @@
             else:
                 comma = self.site.mediawiki_message('comma-separator')
                 default_summary = comma.join(
-                    u'-{0} +{1}'.format(*default_summary)
+                    '-{0} +{1}'.format(*default_summary)
                     for default_summary in default_summaries)
                 summary_messages.insert(0, i18n.twtranslate(
                     self.site, 'replace-replacing',
-                    {'description': u' ({0})'.format(default_summary)}
+                    {'description': ' ({0})'.format(default_summary)}
                 ))
         semicolon = self.site.mediawiki_message('semicolon-separator')
         return semicolon.join(summary_messages)
@@ -726,19 +726,19 @@
         for page in self.generator:
             if self.isTitleExcepted(page.title()):
                 pywikibot.output(
-                    u'Skipping %s because the title is on the exceptions list.'
-                    % page.title(as_link=True))
+                    'Skipping {0} because the title is on the exceptions list.'
+                    .format(page.title(as_link=True)))
                 continue
             try:
                 # Load the page's text from the wiki
                 original_text = page.get(get_redirect=True)
                 if not page.canBeEdited():
-                    pywikibot.output(u"You can't edit page %s"
-                                     % page.title(as_link=True))
+                    pywikibot.output("You can't edit page "
+                                     + page.title(as_link=True))
                     continue
             except pywikibot.NoPage:
-                pywikibot.output('Page %s not found' % page.title(
-                    as_link=True))
+                pywikibot.output('Page {0} not found'
+                                 .format(page.title(as_link=True)))
                 continue
             applied = set()
             new_text = original_text
@@ -746,9 +746,9 @@
             context = 0
             while True:
                 if self.isTextExcepted(new_text):
-                    pywikibot.output(u'Skipping %s because it contains text '
-                                     u'that is on the exceptions list.'
-                                     % page.title(as_link=True))
+                    pywikibot.output('Skipping {0} because it contains text '
+                                     'that is on the exceptions list.'
+                                     .format(page.title(as_link=True)))
                     break
                 while new_text != last_text:
                     last_text = new_text
@@ -757,8 +757,8 @@
                     if not self.recursive:
                         break
                 if new_text == original_text:
-                    pywikibot.output(u'No changes were necessary in %s'
-                                     % page.title(as_link=True))
+                    pywikibot.output('No changes were necessary in '
+                                     + page.title(as_link=True))
                     break
                 if hasattr(self, 'addedCat'):
                     # Fetch only categories in wikitext, otherwise the others
@@ -777,7 +777,7 @@
                 if self.getOption('always'):
                     break
                 choice = pywikibot.input_choice(
-                    u'Do you want to accept these changes?',
+                    'Do you want to accept these changes?',
                     [('Yes', 'y'), ('No', 'n'), ('Edit original', 'e'),
                      ('edit Latest', 'l'), ('open in Browser', 'b'),
                      ('More context', 'm'), ('All', 'a')],
@@ -806,8 +806,8 @@
                     try:
                         original_text = page.get(get_redirect=True, force=True)
                     except pywikibot.NoPage:
-                        pywikibot.output(u'Page %s has been deleted.'
-                                         % page.title())
+                        pywikibot.output('Page {0} has been deleted.'
+                                         .format(page.title()))
                         break
                     new_text = original_text
                     last_text = None
@@ -822,8 +822,9 @@
                               quiet=True)
                 while not self._pending_processed_titles.empty():
                     proc_title, res = self._pending_processed_titles.get()
-                    pywikibot.output('Page %s%s saved'
-                                     % (proc_title, '' if res else ' not'))
+                    pywikibot.output('Page {0}{1} saved'
+                                     .format(proc_title,
+                                             '' if res else ' not'))
                 # choice must be 'N'
                 break
             if self.getOption('always') and new_text != original_text:
@@ -832,23 +833,24 @@
                     page.save(summary=self.generate_summary(applied),
                               callback=self._replace_sync_callback, quiet=True)
                 except pywikibot.EditConflict:
-                    pywikibot.output(u'Skipping %s because of edit conflict'
-                                     % (page.title(),))
+                    pywikibot.output('Skipping {0} because of edit conflict'
+                                     .format(page.title(),))
                 except pywikibot.SpamfilterError as e:
                     pywikibot.output(
-                        u'Cannot change %s because of blacklist entry %s'
-                        % (page.title(), e.url))
+                        'Cannot change {0} because of blacklist entry {1}'
+                        .format(page.title(), e.url))
                 except pywikibot.LockedPage:
-                    pywikibot.output(u'Skipping %s (locked page)'
-                                     % (page.title(),))
+                    pywikibot.output('Skipping {0} (locked page)'
+                                     .format(page.title(),))
                 except pywikibot.PageNotSaved as error:
-                    pywikibot.output(u'Error putting page: %s'
-                                     % (error.args,))
+                    pywikibot.output('Error putting page: {0}'
+                                     .format(error.args,))
                 if self._pending_processed_titles.qsize() > 50:
                     while not self._pending_processed_titles.empty():
                         proc_title, res = self._pending_processed_titles.get()
-                        pywikibot.output('Page %s%s saved'
-                                         % (proc_title, '' if res else ' not'))
+                        pywikibot.output('Page {0}{1} saved'
+                                         .format(proc_title,
+                                                 '' if res else ' not'))


 def prepareRegexForMySQL(pattern):
@@ -876,7 +878,7 @@
     add_cat = None
     gen = None
     # summary message
-    edit_summary = u""
+    edit_summary = ''
     # Array which will collect commandline parameters.
     # First element is original text, second element is replacement text.
     commandline_replacements = []
@@ -936,7 +938,7 @@
         elif arg.startswith('-xmlstart'):
             if len(arg) == 9:
                 xmlStart = pywikibot.input(
-                    u'Please enter the dumped article to start with:')
+                    'Please enter the dumped article to start with:')
             else:
                 xmlStart = arg[10:]
         elif arg.startswith('-xml'):
@@ -996,7 +998,7 @@

             if arg == '-pairsfile':
                 replacement_file = pywikibot.input(
-                    u'Please enter the filename to read replacements from:')
+                    'Please enter the filename to read replacements from:')
             else:
                 replacement_file = arg[len('-pairsfile:'):]
         else:
@@ -1019,7 +1021,7 @@
                 # strip newlines, but not other characters
                 file_replacements = f.read().splitlines()
         except (IOError, OSError) as e:
-            pywikibot.error(u'Error loading {0}: {1}'.format(
+            pywikibot.error('Error loading {0}: {1}'.format(
                 replacement_file, e))
             return False

@@ -1030,13 +1032,13 @@
             return False

         # Strip BOM from first line
-        file_replacements[0].lstrip(u'\uFEFF')
+        file_replacements[0].lstrip('\uFEFF')
         commandline_replacements.extend(file_replacements)

     if not(commandline_replacements or fixes_set) or manual_input:
         old = pywikibot.input('Please enter the text that should be replaced:')
         while old:
-            new = pywikibot.input(u'Please enter the new text:')
+            new = pywikibot.input('Please enter the new text:')
             commandline_replacements += [old, new]
             old = pywikibot.input(
                 'Please enter another text that should be replaced,'
@@ -1051,7 +1053,7 @@
             single_summary = i18n.twtranslate(
                 site, 'replace-replacing',
                 {'description':
-                 ' (-%s +%s)' % (replacement.old, replacement.new)}
+                 ' (-{0} +{1})'.format(replacement.old, replacement.new)}
             )
         replacements.append(replacement)

@@ -1062,8 +1064,8 @@
         try:
             fix = fixes.fixes[fix_name]
         except KeyError:
-            pywikibot.output(u'Available predefined fixes are: %s'
-                             % ', '.join(fixes.fixes.keys()))
+            pywikibot.output('Available predefined fixes are: {0}'
+                             .format(', '.join(fixes.fixes.keys())))
             if not fixes.user_fixes_loaded:
                 pywikibot.output('The user fixes file could not be found: '
                                  '{0}'.format(fixes.filename))
@@ -1072,7 +1074,7 @@
             pywikibot.warning('No replacements defined for fix '
                               '"{0}"'.format(fix_name))
             continue
-        if "msg" in fix:
+        if 'msg' in fix:
             if isinstance(fix['msg'], basestring):
                 set_summary = i18n.twtranslate(site, str(fix['msg']))
             else:
@@ -1133,9 +1135,9 @@
     if ((not edit_summary or edit_summary is True) and
             (missing_fixes_summaries or single_summary)):
         if single_summary:
-            pywikibot.output(u'The summary message for the command line '
-                             'replacements will be something like: %s'
-                             % single_summary)
+            pywikibot.output('The summary message for the command line '
+                             'replacements will be something like: '
+                             + single_summary)
         if missing_fixes_summaries:
             pywikibot.output('The summary will not be used when the fix has '
                              'one defined but the following fix(es) do(es) '
@@ -1206,8 +1208,8 @@
     # Explicitly call pywikibot.stopme(). It will make sure the callback is
     # triggered before replace.py is unloaded.
     pywikibot.stopme()
-    pywikibot.output(u'\n%s pages changed.' % bot.changed_pages)
+    pywikibot.output('\n{0} pages changed.'.format(bot.changed_pages))


-if __name__ == "__main__":
+if __name__ == '__main__':
     main()

--
To view, visit https://gerrit.wikimedia.org/r/462404
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I23723262299d44ca02f12f10e393f19a40bd9d2c
Gerrit-Change-Number: 462404
Gerrit-PatchSet: 2
Gerrit-Owner: D3r1ck01 <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to