[Pywikipedia-l] a memory leak fix in the xmlreader (trunk)

Dmitry Chichkov dchichkov at gmail.com
Wed Apr 28 06:40:25 UTC 2010


Here is a memory leak fix + small optimization  in the xmlreader.py (trunk).

-- Cheers, Dmitry


--- pywikipedia/xmlreader.py    2010-04-27 17:04:34.376531862 -0700
+++ xmlreader.py    2010-04-27 23:17:53.956531055 -0700
@@ -321,6 +321,7 @@

             revision = elem.find("{%s}revision" % self.uri)
             yield self._create_revision(revision)
+            elem.clear()
             self.root.clear()

     def _parse_all(self, event, elem):
@@ -330,6 +331,7 @@

         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,6 +339,8 @@
         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"""
@@ -348,16 +352,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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wikimedia.org/pipermail/pywikipedia-l/attachments/20100427/dd7d13a9/attachment.htm 


More information about the Pywikipedia-l mailing list