[Python-checkins] cpython (2.7): Issue #24125: Saved error's line and column numbers when an error is occured

serhiy.storchaka python-checkins at python.org
Wed May 6 08:54:22 CEST 2015


https://hg.python.org/cpython/rev/fe340c2a220e
changeset: 95891:fe340c2a220e
branch: 2.7
parent: 95874:376c2d81d0e2
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed May 06 09:35:52 2015 +0300
summary:
 Issue #24125: Saved error's line and column numbers when an error is occured
during closing expatreader. Fixed a regression introduced in issue #23865.
files:
 Lib/test/test_sax.py | 2 ++
 Lib/xml/sax/expatreader.py | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -933,6 +933,8 @@
 parser = create_parser()
 parser.setContentHandler(ContentHandler()) # do nothing
 self.assertRaises(SAXParseException, parser.parse, StringIO("<foo>"))
+ self.assertEqual(parser.getColumnNumber(), 5)
+ self.assertEqual(parser.getLineNumber(), 1)
 
 def test_sax_parse_exception_str(self):
 # pass various values from a locator to the SAXParseException to
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -43,6 +43,9 @@
 _mkproxy = weakref.proxy
 del weakref, _weakref
 
+class _ClosedParser:
+ pass
+
 # --- ExpatLocator
 
 class ExpatLocator(xmlreader.Locator):
@@ -214,16 +217,24 @@
 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 = \
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /