http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10485
Revision: 10485 Author: xqt Date: 2012-08-15 14:13:57 +0000 (Wed, 15 Aug 2012) Log Message: ----------- bugfix for query-continue params introduced with mw 1.20wmf8 (same as in bug #3550060)
Modified Paths: -------------- trunk/pywikipedia/apispec.py trunk/pywikipedia/botlist.py trunk/pywikipedia/casechecker.py trunk/pywikipedia/category_redirect.py trunk/pywikipedia/revertbot.py trunk/pywikipedia/userlib.py trunk/pywikipedia/watchlist.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/apispec.py =================================================================== --- trunk/pywikipedia/apispec.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/apispec.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -23,6 +23,7 @@ """ # # (C) Bináris, 2012 +# (C) Pywikipedia bot team, 2012 # # Distributed under the terms of the MIT license. # @@ -237,13 +238,7 @@ blocklist = result['query']['blocks'] #Todo: handle possible errors (they will cause KeyError at this time) while 'query-continue' in result: - try: - self.params['bkstart'] = \ - result['query-continue']['blocks']['bkstart'] - except KeyError: - print 'Error in key, has API format changed?' - print result['query-continue'] - break + self.params.update(result['query-continue']['blocks']) result = query.GetData(self.params) blocklist += result['query']['blocks'] #Finally we remove possible duplicates. This piece of code may be
Modified: trunk/pywikipedia/botlist.py =================================================================== --- trunk/pywikipedia/botlist.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/botlist.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -9,6 +9,7 @@
# (C) Daniel Herding, 2005 # (C) Dr. Trigon, 2009-2010 +# (C) Pywikipedia bot team, 2010-2012 # # DrTrigonBot: http://de.wikipedia.org/wiki/Benutzer:DrTrigonBot # @@ -81,7 +82,7 @@ botlist.extend([w['name'] for w in data['query']['allusers']])
if 'query-continue' in data: - params['aufrom'] = data['query-continue']['allusers']['aufrom'] + params.update(data['query-continue']['allusers']) else: break
Modified: trunk/pywikipedia/casechecker.py =================================================================== --- trunk/pywikipedia/casechecker.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/casechecker.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -13,18 +13,19 @@ if n==0: yield [] else: for i in xrange(len(items)): - for cc in xuniqueCombinations(items[i+1:],n-1): - yield [items[i]]+cc + for cc in xuniqueCombinations(items[i+1:], n-1): + yield [items[i]] + cc + # End of permutation code # -# (C) Pywikipedia bot team, 2006-2011 +# (C) Pywikipedia bot team, 2006-2012 # # Distributed under the terms of the MIT license. # __version__ = '$Id$'
# -# Windows Concose colors +# Windows Concole colors # This code makes this script Windows ONLY!!! # Feel free to adapt it to another platform # @@ -257,10 +258,9 @@ # Get data self.params['gapfrom'] = self.apfrom data = query.GetData(self.params, self.site) - try: - self.apfrom = data['query-continue'] \ - ['allpages']['gapfrom'] - except: + if 'query-continue' in data: + self.params.update(data['query-continue']['allpages']) + else: self.apfrom = None
# Process received data @@ -411,7 +411,7 @@
self.apfrom = u'' # Restart apfrom for other namespaces
- print "***************************** Done" + print "*" * 29, "Done"
except: if self.apfrom is not None: @@ -591,7 +591,6 @@ if not dst.exists(): # choice = pywikibot.inputChoice(u'Move %s to %s?' % (title, newTitle), ['Yes', 'No'], ['y', 'n']) return newTitle - return None
def ColorCodeWord(self, word, toScreen = False): @@ -622,10 +621,10 @@ if toScreen: SetColor(FOREGROUND_WHITE) else: return res + self.suffixClr + u"</b>"
- def MakeLink(self, title): return u"[[:%s|««« %s »»»]]" % (title, self.ColorCodeWord(title))
+ if __name__ == "__main__": try: bot = CaseChecker()
Modified: trunk/pywikipedia/category_redirect.py =================================================================== --- trunk/pywikipedia/category_redirect.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/category_redirect.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -14,7 +14,7 @@ """
# -# (C) Pywikipedia team, 2008-2011 +# (C) Pywikipedia team, 2008-2012 # __version__ = '$Id$' # @@ -262,11 +262,6 @@ assert len(result['query-continue'].keys()) == 1, \ "More than one query-continue key returned: %s" \ % result['query-continue'].keys() - query_type = result['query-continue'].keys()[0] - assert (query_type in querydata.keys() - or query_type in querydata.values()), \ - "Site returned unknown query-continue type '%s'"\ - % query_type querydata.update(result['query-continue'][query_type]) else: return
Modified: trunk/pywikipedia/revertbot.py =================================================================== --- trunk/pywikipedia/revertbot.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/revertbot.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -4,7 +4,7 @@ """ # # (C) Bryan Tong Minh, 2008 -# (C) Pywikipedia bot team, 2008-2010 +# (C) Pywikipedia bot team, 2008-2012 # # Distributed under the terms of the MIT license. # @@ -47,7 +47,7 @@ if 'error' in data: raise RuntimeError(data['error']) if 'query-continue' in data: - predata['uccontinue'] = data['query-continue']['usercontribs'] + predata.update(data['query-continue']['usercontribs']) else: never_continue = True iterator = iter(data['query']['usercontribs'])
Modified: trunk/pywikipedia/userlib.py =================================================================== --- trunk/pywikipedia/userlib.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/userlib.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -3,7 +3,7 @@ Library to work with users, their pages and talk pages. """ # -# (C) Pywikipedia bot team, 2008-2010 +# (C) Pywikipedia bot team, 2008-2012 # # Distributed under the terms of the MIT license. # @@ -13,28 +13,38 @@ import wikipedia as pywikibot import query, config
+ class AutoblockUser(pywikibot.Error): """ The class AutoblockUserError is an exception that is raised whenever an action is requested on a virtual autoblock user that's not available for him (i.e. roughly everything except unblock). """ + + class UserActionRefuse(pywikibot.Error): pass
+ class BlockError(UserActionRefuse): pass
+ class AlreadyBlocked(BlockError): pass
+ class UnblockError(UserActionRefuse): pass
+ class BlockIDError(UnblockError): pass
+ class AlreadyUnblocked(UnblockError): pass
+ class InvalidUser(pywikibot.InvalidTitle): """The mediawiki API does not allow IP lookups.""" pass
+ ip_regexp = re.compile(r'^(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}' r'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|' r'(((?=(?=(.*?(::)))\3(?!.+\4)))\4?|[\dA-F]{1,4}:)' @@ -327,7 +337,7 @@ if nbresults >= limit: break if 'query-continue' in result and nbresults < limit: - params['ucstart'] = result['query-continue']['usercontribs']['ucstart'] + params.update(result['query-continue']['usercontribs']) else: break return @@ -537,6 +547,7 @@ raise UnblockError, data return True
+ def getall(site, users, throttle=True, force=False): """Bulk-retrieve users data from site
@@ -562,6 +573,7 @@ else: _GetAllUI(site, users, throttle, force).run()
+ class _GetAllUI(object): def __init__(self, site, users, throttle, force): self.site = site @@ -621,6 +633,7 @@ users[user['name']] = user return users
+ if __name__ == '__main__': """ Simple testing code for the [[User:Example]] on the English pywikibot.
Modified: trunk/pywikipedia/watchlist.py =================================================================== --- trunk/pywikipedia/watchlist.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/watchlist.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -87,7 +87,7 @@ watchlist.extend([w['title'] for w in data['query']['watchlist']])
if 'query-continue' in data: - params['wlstart'] = data['query-continue']['watchlist']['wlstart'] + params.update(data['query-continue']['watchlist']) else: break
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2012-08-12 18:28:22 UTC (rev 10484) +++ trunk/pywikipedia/wikipedia.py 2012-08-15 14:13:57 UTC (rev 10485) @@ -1343,7 +1343,7 @@ break
if 'query-continue' in data and count < tllimit: - params["tlcontinue"] = data["query-continue"]["templates"]["tlcontinue"] + params.update(data["query-continue"]["templates"]) else: break
@@ -1684,10 +1684,10 @@
if 'query-continue' in datas: if 'backlinks' in datas['query-continue']: - params['blcontinue'] = datas['query-continue']['backlinks']['blcontinue'] + params.update(datas['query-continue']['backlinks'])
if 'embeddedin' in datas['query-continue']: - params['eicontinue'] = datas['query-continue']['embeddedin']['eicontinue'] + params.update(datas['query-continue']['embeddedin']) else: allDone = True
@@ -2632,7 +2632,7 @@
if 'query-continue' in datas: if 'categories' in datas['query-continue']: - params['clcontinue'] = datas['query-continue']['categories']['clcontinue'] + params.update(datas['query-continue']['categories']) else: allDone = True return cats @@ -2974,7 +2974,7 @@ raise BadTitle('BadTitle: %s' % self)
if 'query-continue' in result and getAll: - params['rvstartid'] = result['query-continue']['revisions']['rvstartid'] + params.update(result['query-continue']['revisions']) else: thisHistoryDone = True
@@ -3143,7 +3143,7 @@ raise BadTitle('BadTitle: %s' % self)
if 'query-continue' in result and getAll: - params['rvstartid'] = result['query-continue']['revisions']['rvstartid'] + params.update(result['query-continue']['revisions']) else: thisHistoryDone = True
@@ -4120,7 +4120,7 @@ break
if 'query-continue' in data and limit != 1: - params['iistart'] = data['query-continue']['imageinfo']['iistart'] + params.update(data['query-continue']['imageinfo']) else: break except KeyError: @@ -4284,7 +4284,7 @@ yield Page(self.site(), iu['title'], defaultNamespace=iu['ns'])
if 'query-continue' in data: - params['iucontinue'] = data['query-continue']['imageusage']['iucontinue'] + params.update(data['query-continue']['imageusage']) else: break
@@ -4345,7 +4345,7 @@ yield Page(site, gu['title'])
if 'query-continue' in data: - params['gucontinue'] = data['query-continue']['globalusage']['gucontinue'] + params.update(data['query-continue']['globalusage']) else: break
@@ -6514,7 +6514,7 @@ if nbresults >= number: break if 'query-continue' in result and nbresults < number: - params['lestart'] = result['query-continue']['logevents']['lestart'] + params.update(result['query-continue']['logevents']) elif repeat: nbresults = 0 try: @@ -7313,7 +7313,7 @@ break
if 'query-continue' in data and count < limit: - params['euoffset'] = data[u'query-continue'][u'exturlusage'][u'euoffset'] + params.update(data[u'query-continue'][u'exturlusage']) else: break else: