diff options
Diffstat (limited to 'lib-python/2.7/xml/sax/expatreader.py')
-rw-r--r-- | lib-python/2.7/xml/sax/expatreader.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib-python/2.7/xml/sax/expatreader.py b/lib-python/2.7/xml/sax/expatreader.py index 9de3e72307..21c9db91e9 100644 --- a/lib-python/2.7/xml/sax/expatreader.py +++ b/lib-python/2.7/xml/sax/expatreader.py @@ -43,6 +43,9 @@ else: _mkproxy = weakref.proxy del weakref, _weakref +class _ClosedParser: + pass + # --- ExpatLocator class ExpatLocator(xmlreader.Locator): @@ -214,14 +217,24 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): self._err_handler.fatalError(exc) def close(self): - if self._entity_stack: + if (self._entity_stack or self._parser is None or + isinstance(self._parser, _ClosedParser)): # If we are completing an external entity, do nothing here return - self.feed("", isFinal = 1) - self._cont_handler.endDocument() - self._parsing = 0 - # break cycle created by expat handlers pointing to our methods - self._parser = None + try: + self.feed("", isFinal = 1) + self._cont_handler.endDocument() + self._parsing = 0 + # break cycle created by expat handlers pointing to our methods + self._parser = None + finally: + self._parsing = 0 + if self._parser is not None: + # Keep ErrorColumnNumber and ErrorLineNumber after closing. + parser = _ClosedParser() + parser.ErrorColumnNumber = self._parser.ErrorColumnNumber + parser.ErrorLineNumber = self._parser.ErrorLineNumber + self._parser = parser def _reset_cont_handler(self): self._parser.ProcessingInstructionHandler = \ |