summaryrefslogtreecommitdiffstats
path: root/Lib/xml/sax/expatreader.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-06 06:36:06 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-06 06:36:06 (GMT)
commitab914780ba6165620e3db81d11cb631de58b655a (patch)
treee914f6cde1837f1f5586f82af566f944191d7539 /Lib/xml/sax/expatreader.py
parente8042e5e98a8a368f7d067683269c7cd0f663dfd (diff)
downloadcpython-ab914780ba6165620e3db81d11cb631de58b655a.zip
cpython-ab914780ba6165620e3db81d11cb631de58b655a.tar.gz
cpython-ab914780ba6165620e3db81d11cb631de58b655a.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/expatreader.py')
-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 29d75ab..3b63737 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):
@@ -211,16 +214,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
bs = self._source.getByteStream()
if bs is not None:
bs.close()