Revision: 4115 Author: cosoleto Date: 2007-08-26 14:41:20 +0000 (Sun, 26 Aug 2007)
Log Message: ----------- Previous code was look better than r4112. REs fixed, now it seems work. r4112 wasn't locale independet too.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2007-08-26 14:00:43 UTC (rev 4114) +++ trunk/pywikipedia/wikipedia.py 2007-08-26 14:41:20 UTC (rev 4115) @@ -2112,20 +2112,18 @@
def getFileVersionHistory(self): result = [] - history = self.getImagePageHtml() - pat = re.compile(r'</p><table class="filehistory">((.*?\n)*?)</table>', re.M) - lineR = re.findall(pat, history)[0][0] - for match in lineR.split('\n'): - if not '(<a href=' in match: - continue - res = re.findall(r'">(\d\d:\d\d, \d\d .*? \d\d\d\d)</a></td><td><a href=".*?" (?:class="new" |)title=".*?">(.*?)</a> ' + \ - '(.*?)</td><td>(.*?)</td><td class="mw-imagepage-filesize">(.*?)</td><td>(.*?)</td></tr>', match)[0] - datetime = res[0] - username = res[1] - size = res[2] - resolution = res[3] - comment = res[4] - result.append((datetime, username, resolution, size, comment)) + history = re.search('(?s)<table class="filehistory">.+?</table>', self.getImagePageHtml()) + + if history: + lineR = re.compile('<tr><td>.*?</td><td><a href=".+?">(?P<datetime>.+?)</a></td><td><a href=".+?" title=".+?">(?P<username>.+?)</a>.*?</td><td>(?P<resolution>.+?)</td><td class=".+?">(?P<filesize>.+?)</td><td>(?P<comment>.*?)</td></tr>') + + for match in lineR.finditer(history.group()): + datetime = match.group('datetime') + username = match.group('username') + resolution = match.group('resolution') + size = match.group('filesize') + comment = match.group('comment') or '' + result.append((datetime, username, resolution, size, comment)) return result
def getFileVersionHistoryTable(self):