aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2015-06-12 15:58:29 +0200
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2015-06-12 15:58:29 +0200
commit1a4d31b48706916fe83829810ec5a0ec21c33fac (patch)
tree6c1b8ed15d7e1b77ffa3e3555d4320cdf475fe98 /lib-python/2.7/xml
parentIssue #2060: one more case (diff)
parentUpgrade 2.7 stdlib to 2.7.10 (diff)
downloadpypy-1a4d31b48706916fe83829810ec5a0ec21c33fac.tar.gz
pypy-1a4d31b48706916fe83829810ec5a0ec21c33fac.tar.bz2
pypy-1a4d31b48706916fe83829810ec5a0ec21c33fac.zip
Merge vendor/stdlib: 2.7.10
Diffstat (limited to 'lib-python/2.7/xml')
-rw-r--r--lib-python/2.7/xml/sax/expatreader.py25
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 = \