Revision: 7063 Author: alexsh Date: 2009-07-14 17:48:56 +0000 (Tue, 14 Jul 2009)
Log Message: ----------- *Change site._getBlock from XML to JSON *Change site.allpages from XML to JSON, no need BeautifulSoup.( tested in checkimages.py )
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2009-07-14 16:59:57 UTC (rev 7062) +++ trunk/pywikipedia/wikipedia.py 2009-07-14 17:48:56 UTC (rev 7063) @@ -4497,9 +4497,13 @@ def _getBlock(self, sysop = False): """Get user block data from the API.""" try: - text = self.getUrl(u'%saction=query&meta=userinfo&uiprop=blockinfo' - % self.api_address(), sysop=sysop) - return 'blockedby=' in text + params = { + 'action': 'query', + 'meta': 'userinfo', + 'uiprop': 'blockinfo', + } + data = query.GetData(params, self, useAPI = True)['query']['userinfo'] + return data.has_key('blockby') except NotImplementedError: return False
@@ -5605,34 +5609,30 @@ yield page return
- api_url_basename = "%saction=query&format=xml&list=allpages" \ - "&aplimit=%i&apnamespace=%i" % \ - (self.api_address(), config.special_page_limit, - namespace) + params = { + 'action' : 'query', + 'list' : 'allpages', + 'aplimit' : config.special_page_limit, + 'apnamespace': namespace, + }
if not includeredirects: - api_url_basename += '&apfilterredir=nonredirects' + params['apfilterredir'] = 'nonredirects' elif includeredirects == 'only': - api_url_basename += '&apfilterredir=redirects' + params['apfilterredir'] = 'redirects'
while True: - api_url = '%s&apfrom=%s' % (api_url_basename, - urllib.quote(start.encode(self.encoding()))) - + params['apfrom'] = urllib.quote(start.encode(self.encoding())) if throttle: get_throttle() - text = self.getUrl(api_url) - - soup = BeautifulSoup(text, - convertEntities=BeautifulSoup.HTML_ENTITIES) - - for p in soup.api.query.allpages: + data = query.GetData(params, useAPI = True) + + for p in data['query']['allpages']: yield Page(self, p['title']) + + if data.has_key('query-continue'): + start = data['query-continue']['allpages']['apfrom']
- if soup.api.find('query-continue') is None: - # Last page reached. - break - start = soup.api.find('query-continue').allpages['apfrom']
def _allpagesOld(self, start='!', namespace=0, includeredirects=True, throttle=True):
pywikipedia-svn@lists.wikimedia.org