Revision: 7134 Author: alexsh Date: 2009-08-08 12:27:09 +0000 (Sat, 08 Aug 2009)
Log Message: ----------- *Page().delete(), Site().newimages() :Add API NotImplementedError detection.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2009-08-08 04:25:51 UTC (rev 7133) +++ trunk/pywikipedia/wikipedia.py 2009-08-08 12:27:09 UTC (rev 7134) @@ -2398,6 +2398,11 @@ if answer == 'y':
token = self.site().getToken(self, sysop = True) + try: + d = self.site().api_address() + del d + except NotImplementedError: + config.use_api = False
if config.use_api and self.site().versionnumber() >= 12: params = { @@ -2413,10 +2418,11 @@ else: if datas['error']['code'] == 'missingtitle': output(u'Page %s could not be deleted - it doesn't exist' % self.aslink(forceInterwiki = True)) - return False else: output(u'Deletion of %s failed for an unknown reason. The response text is:' % self.aslink(forceInterwiki = True)) output('%s' % datas) + + return False else: host = self.site().hostname() address = self.site().delete_address(self.urlname()) @@ -5559,11 +5565,15 @@ if leuser is not None: params['leuser'] = leuser if letitle is not None: params['letitle'] = letitle while True: - data = query.GetData(params, self, encodeTitle = False) try: - imagesData = data['query']['logevents'] - except KeyError: + if self.versionnumber() >= 11: + imagesData = query.GetData(params, self, encodeTitle = False)['query']['logevents'] + else: + raise NotImplementedError("The site version is not support this action.") + except KeyError: #no 'query' or 'logevents', error occured raise ServerError("The APIs don't return the data, the site may be down") + except NotImplementedError: + raise ServerError("The site version is not support this action.")
for imageData in imagesData: try: @@ -5573,7 +5583,7 @@ pageid = imageData['pageid'] title = imageData['title'] timestamp = imageData['timestamp'] - logid = imageData['logid'] + ##logid = imageData['logid'] #no use current now user = imageData['user'] yield ImagePage(self, title), timestamp, user, comment if not repeat: @@ -5814,6 +5824,7 @@ start = page.titleWithoutNamespace() try: api_url = self.api_address() + del api_url except NotImplementedError: for page in self._allpagesOld(start, namespace, includeredirects, throttle): yield page @@ -5842,8 +5853,9 @@
if data.has_key('query-continue'): start = data['query-continue']['allpages']['apfrom'] + else: + break
- def _allpagesOld(self, start='!', namespace=0, includeredirects=True, throttle=True): """
pywikipedia-svn@lists.wikimedia.org