http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10252
Revision: 10252 Author: xqt Date: 2012-05-25 16:51:15 +0000 (Fri, 25 May 2012) Log Message: ----------- namespace support for xmlreader, bug #3529618 (not tested, sorry)
Modified Paths: -------------- trunk/pywikipedia/xmlreader.py
Modified: trunk/pywikipedia/xmlreader.py =================================================================== --- trunk/pywikipedia/xmlreader.py 2012-05-24 18:56:28 UTC (rev 10251) +++ trunk/pywikipedia/xmlreader.py 2012-05-25 16:51:15 UTC (rev 10252) @@ -16,7 +16,7 @@ to the older method using regular expressions. """ # -# (C) Pywikipedia bot team, 2005-2010 +# (C) Pywikipedia bot team, 2005-2012 # # Distributed under the terms of the MIT license. # @@ -62,12 +62,13 @@ """ Represents a page. """ - def __init__(self, title, id, text, username, ipedit, timestamp, + def __init__(self, title, ns, id, text, username, ipedit, timestamp, editRestriction, moveRestriction, revisionid, comment, redirect): # TODO: there are more tags we can read. self.title = title - self.id = id + self.ns = ns + self.id =id self.text = text self.username = username.strip() self.ipedit = ipedit @@ -157,6 +158,9 @@ elif name == 'title': self.destination = 'title' self.title=u'' + elif name == 'ns': + self.destination = 'ns' + self.ns = u'' elif name == 'timestamp': self.destination = 'timestamp' self.timestamp=u'' @@ -193,7 +197,7 @@ self.timestamp[17:19]) self.title = self.title.strip() # Report back to the caller - entry = XmlEntry(self.title, self.id, + entry = XmlEntry(self.title, self.ns, self.id, text, self.username, self.ipedit, timestamp, self.editRestriction, self.moveRestriction, @@ -223,6 +227,8 @@ self.restrictions += data elif self.destination == 'title': self.title += data + elif self.destination == 'ns': + self.ns += data elif self.destination == 'username': self.username += data elif self.destination == 'timestamp': @@ -358,6 +364,7 @@ # could get comment, minor as well text = revision.findtext("{%s}text" % self.uri) return XmlEntry(title=self.title, + ns=self.ns, id=self.pageid, text=text or u'', username=username or u'', #username might be deleted @@ -382,6 +389,7 @@ Rpage = re.compile( '<page>\s*'+ '<title>(?P<title>.+?)</title>\s*'+ + '<ns>(?P<namespace>\d+?)</ns>\s*'+ '<id>(?P<pageid>\d+?)</id>\s*'+ '(<restrictions>(?P<restrictions>.+?)</restrictions>)?\s*'+ '<revision>\s*'+ @@ -430,7 +438,8 @@ else: username = m.group('ip') ipedit = True - yield XmlEntry(title = m.group('title'), + yield XmlEntry(title=m.group('title'), + ns=m.group('namespace'), id=m.group('pageid'), text=text, username=username, ipedit=ipedit, timestamp=m.group('timestamp'),
pywikipedia-svn@lists.wikimedia.org