aboutsummaryrefslogtreecommitdiff
path: root/Lib/xml/sax
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-06 09:36:06 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-06 09:36:06 +0300
commitab914780ba6165620e3db81d11cb631de58b655a (patch)
treee914f6cde1837f1f5586f82af566f944191d7539 /Lib/xml/sax
parent - Issue #24122, fix quoting for LIBPL (diff)
downloadcpython-ab914780ba6165620e3db81d11cb631de58b655a.tar.gz
cpython-ab914780ba6165620e3db81d11cb631de58b655a.tar.bz2
cpython-ab914780ba6165620e3db81d11cb631de58b655a.zip
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 29d75ab4ac4..3b63737457d 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()