[Pywikipedia-l] SVN: [5451] trunk/pywikipedia

nicdumz at svn.wikimedia.org nicdumz at svn.wikimedia.org
Wed May 28 11:29:12 UTC 2008


Revision: 5451
Author:   nicdumz
Date:     2008-05-28 11:29:11 +0000 (Wed, 28 May 2008)

Log Message:
-----------
Cleaning the calls to wikipedia::inputChoice : 
* the function returns a single, lowercase letter
* it can have a 'default choice' parameter

Modified Paths:
--------------
    trunk/pywikipedia/add_text.py
    trunk/pywikipedia/blockpageschecker.py
    trunk/pywikipedia/capitalize_redirects.py
    trunk/pywikipedia/commons_link.py
    trunk/pywikipedia/copyright_clean.py
    trunk/pywikipedia/cosmetic_changes.py
    trunk/pywikipedia/imageharvest.py
    trunk/pywikipedia/interwiki.py
    trunk/pywikipedia/lonelypages.py
    trunk/pywikipedia/movepages.py
    trunk/pywikipedia/pageimport.py
    trunk/pywikipedia/reflinks.py
    trunk/pywikipedia/replace.py
    trunk/pywikipedia/solve_disambiguation.py
    trunk/pywikipedia/unusedfiles.py
    trunk/pywikipedia/upload.py
    trunk/pywikipedia/wikipedia.py

Modified: trunk/pywikipedia/add_text.py
===================================================================
--- trunk/pywikipedia/add_text.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/add_text.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -189,11 +189,11 @@
         if putText:
             if not always:
                 choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-            if choice.lower() in ['a', 'all']:
+            if choice == 'a':
                 always = True
-            if choice.lower() in ['n', 'no']:
+            if choice == 'n':
                 return (False, always)
-            if choice.lower() in ['y', 'yes'] or always:
+            if choice == 'y' or always:
                 try:
                     page.put(newtext, summary)
                 except wikipedia.EditConflict:

Modified: trunk/pywikipedia/blockpageschecker.py
===================================================================
--- trunk/pywikipedia/blockpageschecker.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/blockpageschecker.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -356,15 +356,12 @@
             # Ok, asking if the change has to be performed and do it if yes.
             wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
             wikipedia.showDiff(oldtext, text)
-            choice = ''
-            while 1:
-                if not always:
-                    choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-                if choice.lower() in ['a', 'all']:
+            if not always:
+                choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
+                if choice == 'a':
                     always = True
-                if choice.lower() in ['n', 'no']:
-                    break
-                if choice.lower() in ['y', 'yes'] or always:
+            if always or choice == 'y':
+                while 1:
                     try:
                         page.put(text, commentUsed, force=True)
                     except wikipedia.EditConflict:

Modified: trunk/pywikipedia/capitalize_redirects.py
===================================================================
--- trunk/pywikipedia/capitalize_redirects.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/capitalize_redirects.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -69,9 +69,9 @@
                     choice = wikipedia.inputChoice(
                             u'Do you want to create a redirect?',
                             ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-                    if choice in ['a', 'A']:
+                    if choice == 'a':
                         self.acceptall = True
-                if self.acceptall or choice in ['y', 'Y']:
+                if self.acceptall or choice == 'y':
                     try:
                         wikipedia.setAction(
                             wikipedia.translate(wikipedia.getSite(), msg)

Modified: trunk/pywikipedia/commons_link.py
===================================================================
--- trunk/pywikipedia/commons_link.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/commons_link.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -81,9 +81,9 @@
                                 wikipedia.showDiff(oldText, text)
                                 if not self.acceptall:
                                     choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-                                    if choice in ['a', 'A']:
+                                    if choice == 'a':
                                         self.acceptall = True
-                                if self.acceptall or choice in ['y', 'Y']:
+                                if self.acceptall or choice == 'y':
                                     try:
                                         msg = wikipedia.translate(wikipedia.getSite(), comment1)
                                         page.put(text, msg)
@@ -125,9 +125,9 @@
                                 wikipedia.showDiff(oldText, text)
                                 if not self.acceptall:
                                     choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-                                    if choice in ['a', 'A']:
+                                    if choice == 'a':
                                         self.acceptall = True
-                                if self.acceptall or choice in ['y', 'Y']:
+                                if self.acceptall or choice == 'y':
                                     try:
                                         msg = wikipedia.translate(wikipedia.getSite(), comment2)
                                         page.put(text, msg)

Modified: trunk/pywikipedia/copyright_clean.py
===================================================================
--- trunk/pywikipedia/copyright_clean.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/copyright_clean.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -149,7 +149,7 @@
 
         if len(sys.argv)!=1:
             choice = wikipedia.inputChoice(u'Do you want to clean the page?',  ['Yes', 'No'], ['y', 'n'], 'n')
-            if choice in ['n', 'N']:
+            if choice == 'n':
                continue
         try:
             put(page, output, add_comment)

Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/cosmetic_changes.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -364,9 +364,9 @@
             if changedText != page.get():
                 if not self.acceptall:
                     choice = wikipedia.inputChoice(u'Do you want to accept these changes?',  ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-                    if choice in ['a', 'A']:
+                    if choice == 'a':
                         self.acceptall = True
-                if self.acceptall or choice in ['y', 'Y']:
+                if self.acceptall or choice == 'y':
                     page.put(changedText)
             else:
                 wikipedia.output('No changes were necessary in %s' % page.title())

Modified: trunk/pywikipedia/imageharvest.py
===================================================================
--- trunk/pywikipedia/imageharvest.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/imageharvest.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -88,12 +88,12 @@
 
     for image in ilinks:
         answer = wikipedia.inputChoice(u'Include image %s?' % image, ['yes', 'no', 'stop'], ['y', 'N', 's'], 'N')
-        if answer in ["y","Y"]:
+        if answer == 'y':
             desc = wikipedia.input(u"Give the description of this image:")
             desc = desc + "\r\n\n\r" + basicdesc
             uploadBot = upload.UploadRobot(image, desc)
             uploadBot.run()
-        elif answer in ["s","S"]:
+        elif answer == 's':
             break
 try:
     url = u''

Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/interwiki.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -933,9 +933,7 @@
                         if acceptall: 
                             answer = 'a'
                         else: 
-                            answer = wikipedia.inputChoice(u'What should be done?', ['accept', 'reject', 'give up', 'accept all'], ['a', 'r', 'g', 'l'])
-                            if not answer:
-                                answer = 'a'
+                            answer = wikipedia.inputChoice(u'What should be done?', ['accept', 'reject', 'give up', 'accept all'], ['a', 'r', 'g', 'l'], 'a')
                         if answer == 'l': # accept all
                             acceptall = True
                             answer = 'a'

Modified: trunk/pywikipedia/lonelypages.py
===================================================================
--- trunk/pywikipedia/lonelypages.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/lonelypages.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -248,11 +248,11 @@
                 wikipedia.showDiff(oldtxt, newtxt) # Showing the changes
                 choice = 'y' # Default answer
                 if not always:
-                    choice = wikipedia.inputChoice(u'Orphan page found, shall I add the template?',  [u'Yes', u'No', u'All'], [u'y', u'n', u'a'], [u'Y', u'N', 'A'])
-                if choice.lower() in [u'a', u'all']:
+                    choice = wikipedia.inputChoice(u'Orphan page found, shall I add the template?',  ['Yes', 'No', 'All'], ['y', 'n', 'a'])
+                if choice == 'a':
                     always = True
                     choice = 'y'
-                if choice.lower() in [u'y', u'yes']:
+                if choice == 'y':
                     try:
                         page.put(newtxt, comment)
                     except wikipedia.EditConflict:

Modified: trunk/pywikipedia/movepages.py
===================================================================
--- trunk/pywikipedia/movepages.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/movepages.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -122,14 +122,14 @@
         if self.addprefix or self.appendAll or self.regexAll:
             if not self.always:
                 choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q'])
-                if choice2 in ['y', 'Yes', 'Y']:
+                if choice2 == 'y':
                     self.moveOne(page, newPageTitle)
-                elif choice2 in ['a', 'all', 'A']:
+                elif choice2 == 'a':
                     self.always = True
                     self.moveOne(page, newPageTitle)
-                elif choice2 in ['q', 'Q', 'quit']:
+                elif choice2 == 'q':
                     sys.exit()
-                elif choice2 in ['n', 'N', 'no']:
+                elif choice2 == 'n':
                     pass
                 else:
                     self.treat(page)
@@ -151,14 +151,14 @@
                     else:
                         newPageTitle = (u'%s:%s' % (namesp, newPageTitle))
                 choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q'])
-                if choice2 in ['y', 'Y', 'yes']:
+                if choice2  == 'y':
                     self.moveOne(page, newPageTitle)
-                elif choice2 in ['a', 'A', 'all']:
+                elif choice2 == 'a':
                     self.appendAll = True
                     self.moveOne(page, newPageTitle)
-                elif choice2 in ['q', 'Q', 'quit']:
+                elif choice2 == 'q':
                     sys.exit()
-                elif choice2 in ['n', 'no', 'N']:
+                elif choice2 == 'n':
                     pass
                 else:
                     self.treat(page)
@@ -176,20 +176,20 @@
                     else:
                         newPageTitle = self.regex.sub(self.replacePattern, page.title())
                 choice2 = wikipedia.inputChoice(u'Change the page title to "%s"?' % newPageTitle, ['yes', 'no', 'all', 'quit'], ['y', 'n', 'a', 'q'])
-                if choice2 in ['y', 'Y', 'yes']:
+                if choice2 == 'y':
                     self.moveOne(page, newPageTitle)
-                elif choice2 in ['a', 'A', 'all']:
+                elif choice2 == 'a':
                     self.regexAll = True
                     self.moveOne(page, newPageTitle)
-                elif choice2 in ['q', 'Q', 'quit']:
+                elif choice2 == 'q':
                     sys.exit()
-                elif choice2 in ['n', 'no', 'N']:
+                elif choice2 == 'n':
                     pass
                 else:
                     self.treat(page)
-            elif choice in ['n', 'N', 'no']:
+            elif choice == 'n':
                 pass
-            elif choice in ['q', 'Q', 'quit']:
+            elif choice == 'q':
                 sys.exit()
             else:
                 self.treat(page)

Modified: trunk/pywikipedia/pageimport.py
===================================================================
--- trunk/pywikipedia/pageimport.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/pageimport.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -65,7 +65,7 @@
         answer = 'y'
         if prompt:
             answer = wikipedia.inputChoice(u'Do you want to import %s?' % target, ['Yes', 'No'], ['y', 'N'], 'N')
-        if answer in ['y', 'Y']:
+        if answer == 'y':
             host = self.site().hostname()
             address = self.site().path() + '?title=%s&action=submit' % self.urlname()
             # You need to be a sysop for the import.

Modified: trunk/pywikipedia/reflinks.py
===================================================================
--- trunk/pywikipedia/reflinks.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/reflinks.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -233,9 +233,9 @@
                                            u'these changes?', 
                                            ['Yes', 'No', 'All'], 
                                            ['y', 'N', 'a'], 'N')
-            if choice in ['a', 'A']:
+            if choice == 'a':
                 self.acceptall = True
-            if choice in ['y', 'Y']:
+            if choice == 'y':
                 page.put_async(new)
         if self.acceptall:
             try:

Modified: trunk/pywikipedia/replace.py
===================================================================
--- trunk/pywikipedia/replace.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/replace.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -384,18 +384,18 @@
                             u'Do you want to accept these changes?',
                             ['Yes', 'No', 'Edit', 'All', "Quit"],
                             ['y', 'N', 'e', 'a', 'q'], 'N')
-                if choice in "Ee":
+                if choice == 'e':
                     editor = editarticle.TextEditor()
                     as_edited = editor.edit(new_text)
                     # if user didn't press Cancel
                     if as_edited and as_edited != new_text:
                         new_text = as_edited
                     continue
-                if choice in "Qq":
+                if choice == 'q':
                     return
-                if choice in ['a', 'A']:
+                if choice == 'a':
                     self.acceptall = True
-                if choice in ['y', 'Y']:
+                if choice == 'y':
                     page.put_async(new_text)
                 break
             if self.acceptall:

Modified: trunk/pywikipedia/solve_disambiguation.py
===================================================================
--- trunk/pywikipedia/solve_disambiguation.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/solve_disambiguation.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -578,7 +578,7 @@
             if disambPage.isRedirectPage():
                 target = self.alternatives[0]
                 choice = wikipedia.inputChoice(u'Do you want to make redirect %s point to %s?' % (refPage.title(), target), ['yes', 'no'], ['y', 'N'], 'N')
-                if choice in ['y', 'Y']:
+                if choice == 'y':
                     redir_text = '#%s [[%s]]' % (self.mysite.redirect(default=True), target)
                     try:
                         refPage.put_async(redir_text,comment=self.comment)
@@ -586,14 +586,14 @@
                         wikipedia.output(u'Page not saved: %s' % error.args)
             else:
                 choice = wikipedia.inputChoice(u'Do you want to work on pages linking to %s?' % refPage.title(), ['yes', 'no', 'change redirect'], ['y', 'N', 'c'], 'N')
-                if choice in ['y', 'Y']:
+                if choice == 'y':
                     gen = ReferringPageGeneratorWithIgnore(refPage, self.primary)
                     preloadingGen = pagegenerators.PreloadingGenerator(gen)
                     for refPage2 in preloadingGen:
                         # run until the user selected 'quit'
                         if not self.treat(refPage2, refPage):
                             break
-                elif choice in ['c', 'C']:
+                elif choice == 'c':
                     text=refPage.get(throttle=False,get_redirect=True)
                     include = "redirect"
         except wikipedia.NoPage:
@@ -936,7 +936,7 @@
                 else:
                     answer = wikipedia.inputChoice(u'Possibility %s does not actually exist. Use it anyway?'
                              % page.title(), ['yes', 'no'], ['y', 'N'], 'N')
-                    if answer in ('Y', 'y'):
+                    if answer == 'y':
                         alternatives.append(page.title())
             else:
                 alternatives.append(arg[5:])

Modified: trunk/pywikipedia/unusedfiles.py
===================================================================
--- trunk/pywikipedia/unusedfiles.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/unusedfiles.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -66,10 +66,10 @@
     if text != page.get():
         wikipedia.showDiff(page.get(),text)
         choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
-        if choice.lower() in ['a', 'all']:
+        if choice == 'a':
             always = True
             choice = 'y'
-        if choice.lower() in ['y', 'yes']:
+        if choice == 'y':
             msg = wikipedia.translate(wikipedia.getSite(), comment)
             page.put(text, msg)
 

Modified: trunk/pywikipedia/upload.py
===================================================================
--- trunk/pywikipedia/upload.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/upload.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -273,13 +273,13 @@
 
                 if self.targetSite.mediawiki_message('uploadwarning') in returned_html:
                     answer = wikipedia.inputChoice(u"You have recevied an upload warning message. Ignore?", ['Yes', 'No'], ['y', 'N'], 'N')
-                    if answer in ["y", "Y"]:
+                    if answer == "y":
                         self.ignoreWarning = 1
                         self.keepFilename = True
                         return self.upload_image(debug)
                 else:
                     answer = wikipedia.inputChoice(u'Upload of %s probably failed. Above you see the HTML page which was returned by MediaWiki. Try again?' % filename, ['Yes', 'No'], ['y', 'N'], 'N')
-                    if answer in ["y", "Y"]:
+                    if answer == "y":
                         return self.upload_image(debug)
                     else:
                         return
@@ -322,4 +322,4 @@
     try:
         main(sys.argv[1:])
     finally:
-        wikipedia.stopme()
\ No newline at end of file
+        wikipedia.stopme()

Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py	2008-05-28 10:54:30 UTC (rev 5450)
+++ trunk/pywikipedia/wikipedia.py	2008-05-28 11:29:11 UTC (rev 5451)
@@ -2147,10 +2147,10 @@
         answer = 'y'
         if prompt and not hasattr(self.site(), '_noDeletePrompt'):
             answer = inputChoice(u'Do you want to delete %s?' % self.aslink(forceInterwiki = True), ['Yes', 'No', 'All'], ['Y', 'N', 'A'], 'N')
-            if answer in ['a', 'A']:
+            if answer == 'a':
                 answer = 'y'
                 self.site()._noDeletePrompt = True
-        if answer in ['y', 'Y']:
+        if answer == 'y':
             host = self.site().hostname()
             address = self.site().delete_address(self.urlname())
 
@@ -2346,10 +2346,10 @@
                 u'Do you want to change the protection level of %s?'
                     % self.aslink(forceInterwiki = True),
                 ['Yes', 'No', 'All'], ['Y', 'N', 'A'], 'N')
-            if answer in ['a', 'A']:
+            if answer == 'a':
                 answer = 'y'
                 self.site()._noProtectPrompt = True
-        if answer in ['y', 'Y']:
+        if answer == 'y':
             host = self.site().hostname()
 
             token = self.site().getToken(self, sysop = True)





More information about the Pywikipedia-l mailing list