Revision: 8139 Author: xqt Date: 2010-04-29 05:53:37 +0000 (Thu, 29 Apr 2010)
Log Message: ----------- memory leak fix + small optimization by Dmitry. Thanks.
Modified Paths: -------------- trunk/pywikipedia/xmlreader.py
Modified: trunk/pywikipedia/xmlreader.py =================================================================== --- trunk/pywikipedia/xmlreader.py 2010-04-29 05:21:09 UTC (rev 8138) +++ trunk/pywikipedia/xmlreader.py 2010-04-29 05:53:37 UTC (rev 8139) @@ -62,7 +62,9 @@ """ Represents a page. """ - def __init__(self, title, id, text, username, ipedit, timestamp, editRestriction, moveRestriction, revisionid, comment, redirect): + def __init__(self, title, id, text, username, ipedit, timestamp, + editRestriction, moveRestriction, revisionid, comment, + redirect): # TODO: there are more tags we can read. self.title = title self.id = id @@ -172,7 +174,8 @@ if name == 'contributor': self.inContributorTag = False elif name == 'restrictions': - self.editRestriction, self.moveRestriction = parseRestrictions(self.restrictions) + self.editRestriction, self.moveRestriction \ + = parseRestrictions(self.restrictions) elif name == 'redirect': self.isredirect = True elif name == 'revision': @@ -318,18 +321,18 @@ """Parser that yields only the latest revision""" if event == "end" and elem.tag == "{%s}page" % self.uri: self._headers(elem) - revision = elem.find("{%s}revision" % self.uri) yield self._create_revision(revision) + elem.clear() self.root.clear()
def _parse_all(self, event, elem): """Parser that yields all revisions""" if event == "start" and elem.tag == "{%s}page" % self.uri: self._headers(elem) - if event == "end" and elem.tag == "{%s}revision" % self.uri: yield self._create_revision(elem) + elem.clear() self.root.clear()
def _headers(self, elem): @@ -337,7 +340,10 @@ self.pageid = elem.findtext("{%s}id" % self.uri) self.restrictions = elem.findtext("{%s}restrictions" % self.uri) self.isredirect = elem.findtext("{%s}redirect" % self.uri) is not None + self.editRestriction, self.moveRestriction \ + = parseRestrictions(self.restrictions)
+ def _create_revision(self, revision): """Creates a Single revision""" revisionid = revision.findtext("{%s}id" % self.uri) @@ -348,16 +354,14 @@ username = ipeditor or contributor.findtext("{%s}username" % self.uri) # could get comment, minor as well text = revision.findtext("{%s}text" % self.uri) - editRestriction, moveRestriction \ - = parseRestrictions(self.restrictions) return XmlEntry(title=self.title, id=self.pageid, text=text or u'', username=username or u'', #username might be deleted ipedit=bool(ipeditor), timestamp=timestamp, - editRestriction=editRestriction, - moveRestriction=moveRestriction, + editRestriction=self.editRestriction, + moveRestriction=self.moveRestriction, revisionid=revisionid, comment=comment, redirect=self.isredirect @@ -414,7 +418,8 @@ lines = u'' text = m.group('text') or u'' restrictions = m.group('restrictions') - editRestriction, moveRestriction = parseRestrictions(restrictions) + editRestriction, moveRestriction \ + = parseRestrictions(restrictions)
if m.group('username'): username = m.group('username')
pywikipedia-svn@lists.wikimedia.org