summaryrefslogtreecommitdiffstats
path: root/Lib/xml/sax
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-06 06:35:52 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-06 06:35:52 (GMT)
commit3234abb9a057beb88faeef96745f8c78772a88c2 (patch)
treeb99bfe2e2d46c21a628dcd1a94cb370973878c33 /Lib/xml/sax
parent69af58013106a6e70b758bf4ee48b85a30d40d0c (diff)
downloadcpython-3234abb9a057beb88faeef96745f8c78772a88c2.zip
cpython-3234abb9a057beb88faeef96745f8c78772a88c2.tar.gz
cpython-3234abb9a057beb88faeef96745f8c78772a88c2.tar.bz2
Issue #24125: Saved error's line and column numbers when an error is occured
during closing expatreader. Fixed a regression introduced in issue #23865.
Diffstat (limited to 'Lib/xml/sax')
-rw-r--r--Lib/xml/sax/expatreader.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
index cd243e6..21c9db9 100644
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -43,6 +43,9 @@ else:
_mkproxy = weakref.proxy
del weakref, _weakref
+class _ClosedParser:
+ pass
+
# --- ExpatLocator
class ExpatLocator(xmlreader.Locator):
@@ -214,16 +217,24 @@ class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
self._err_handler.fatalError(exc)
def close(self):
- if self._entity_stack or self._parser is None:
+ 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
try:
self.feed("", isFinal = 1)
self._cont_handler.endDocument()
- finally:
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 = \