http://www.mediawiki.org/wiki/Special:Code/pywikipedia/8984
Revision: 8984 Author: xqt Date: 2011-02-19 10:47:01 +0000 (Sat, 19 Feb 2011) Log Message: ----------- update live_version for mw 1.17. Thanks DrTrigon for the first patch.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2011-02-18 18:05:51 UTC (rev 8983) +++ trunk/pywikipedia/wikipedia.py 2011-02-19 10:47:01 UTC (rev 8984) @@ -7249,16 +7249,23 @@ """ global htmldata if not hasattr(self, "_mw_version"): + PATTERN = r"^(?:: )?([0-9]+).([0-9]+)(.*)$" versionpage = self.getUrl(self.get_address("Special:Version")) htmldata = BeautifulSoup(versionpage, convertEntities="html") - versionstring = htmldata.findAll(text="MediaWiki" - )[1].parent.nextSibling - m = re.match(r"^: ([0-9]+).([0-9]+)(.*)$", str(versionstring)) - if m: - self._mw_version = (int(m.group(1)), int(m.group(2)), - m.group(3)) + # try to find the live version + # 1st try is for mw < 1.17wmf1 + # 2nd try is for mw 1.17wmf1 + # 3rd uses family file which is not live + for versionstring in [htmldata.findAll( + text="MediaWiki")[1].parent.nextSibling, + htmldata.body.table.findAll( + 'td')[1].contents[0], + self.family.version(self.lang)]: + m = re.match(PATTERN, str(versionstring).strip()) + if m: break else: - self._mw_version = self.family.version(self.lang).split(".") + raise Error(u'Cannot find any live version!') + self._mw_version = (int(m.group(1)), int(m.group(2)), m.group(3)) return self._mw_version
def checkCharset(self, charset):
pywikipedia-svn@lists.wikimedia.org