[Lxml-checkins] r33829 - in lxml/trunk/src/lxml: . tests

scoder at codespeak.net scoder at codespeak.net
Sat Oct 28 11:05:28 CEST 2006


Author: scoder
Date: Sat Oct 28 11:05:20 2006
New Revision: 33829

Modified:
   lxml/trunk/src/lxml/parser.pxi
   lxml/trunk/src/lxml/tests/test_io.py
   lxml/trunk/src/lxml/xmlparser.pxd
Log:
always call xmlClearParserCtxt() after parsing (if libxml2 allows it ...), should fix Windows file closing bug

Modified: lxml/trunk/src/lxml/parser.pxi
==============================================================================
--- lxml/trunk/src/lxml/parser.pxi	(original)
+++ lxml/trunk/src/lxml/parser.pxi	Sat Oct 28 11:05:20 2006
@@ -388,6 +388,13 @@
         if self._parser_ctxt is not NULL:
             xmlparser.xmlFreeParserCtxt(self._parser_ctxt)
 
+    def _cleanup(self):
+        cdef xmlParserCtxt* pctxt
+        pctxt = self._parser_ctxt
+        if pctxt is not NULL:
+            if pctxt.spaceTab is not NULL: # work around bug in libxml2
+                xmlparser.xmlClearParserCtxt(pctxt)
+
     property error_log:
         def __get__(self):
             return self._error_log.copy()
@@ -461,6 +468,7 @@
             recover = self._parse_options & xmlparser.XML_PARSE_RECOVER
             return _handleParseResult(pctxt, result, None, recover)
         finally:
+            self._cleanup()
             self._context.clear()
             self._error_log.disconnect()
             self._unlockParser()
@@ -493,6 +501,7 @@
             recover = self._parse_options & xmlparser.XML_PARSE_RECOVER
             return _handleParseResult(pctxt, result, None, recover)
         finally:
+            self._cleanup()
             self._context.clear()
             self._error_log.disconnect()
             self._unlockParser()
@@ -521,6 +530,7 @@
             recover = self._parse_options & xmlparser.XML_PARSE_RECOVER
             return _handleParseResult(pctxt, result, c_filename, recover)
         finally:
+            self._cleanup()
             self._context.clear()
             self._error_log.disconnect()
             self._unlockParser()
@@ -545,6 +555,7 @@
             recover = self._parse_options & xmlparser.XML_PARSE_RECOVER
             return _handleParseResult(pctxt, result, filename, recover)
         finally:
+            self._cleanup()
             self._context.clear()
             self._error_log.disconnect()
             self._unlockParser()

Modified: lxml/trunk/src/lxml/tests/test_io.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_io.py	(original)
+++ lxml/trunk/src/lxml/tests/test_io.py	Sat Oct 28 11:05:20 2006
@@ -62,10 +62,7 @@
             self.assertEqual(self.etree.tostring(root), self.root_str)
         finally:
             os.close(handle)
-            try:
-                os.remove(filename)
-            except WindowsError:
-                pass # it's windows that's broken, not us
+            os.remove(filename)
 
     def test_class_parse_filename_remove_previous(self):
         handle, filename = tempfile.mkstemp(suffix=".xml")
@@ -86,10 +83,7 @@
             # XXX how to check?
         finally:
             os.close(handle)
-            try:
-                os.remove(filename)
-            except WindowsError:
-                pass # it's windows that's broken, not us
+            os.remove(filename)
         
     def test_class_parse_fileobject(self):
         # (c)ElementTree class ElementTree has a 'parse' method that returns

Modified: lxml/trunk/src/lxml/xmlparser.pxd
==============================================================================
--- lxml/trunk/src/lxml/xmlparser.pxd	(original)
+++ lxml/trunk/src/lxml/xmlparser.pxd	Sat Oct 28 11:05:20 2006
@@ -55,6 +55,7 @@
         xmlError lastError
         xmlNode* node
         xmlSAXHandler* sax
+        int* spaceTab
         
     ctypedef enum xmlParserOption:
         XML_PARSE_RECOVER = 1 # recover on errors
@@ -84,6 +85,8 @@
                                              int enc)
     cdef int xmlCtxtUseOptions(xmlParserCtxt* ctxt, int options)
     cdef void xmlFreeParserCtxt(xmlParserCtxt* ctxt)
+    cdef void xmlCtxtReset(xmlParserCtxt* ctxt)
+    cdef void xmlClearParserCtxt(xmlParserCtxt* ctxt)
     cdef int xmlParseChunk(xmlParserCtxt* ctxt,
                            char* chunk, int size, int terminate)
     cdef xmlDoc* xmlCtxtReadDoc(xmlParserCtxt* ctxt,


More information about the lxml-checkins mailing list