summaryrefslogtreecommitdiffstats
path: root/Lib/xml/sax/expatreader.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/xml/sax/expatreader.py')
-rw-r--r--Lib/xml/sax/expatreader.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/xml/sax/expatreader.py b/Lib/xml/sax/expatreader.py
index 9de3e72..cd243e6 100644
--- a/Lib/xml/sax/expatreader.py
+++ b/Lib/xml/sax/expatreader.py
@@ -214,14 +214,16 @@ 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:
# 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()
+ finally:
+ self._parsing = 0
+ # break cycle created by expat handlers pointing to our methods
+ self._parser = None
def _reset_cont_handler(self):
self._parser.ProcessingInstructionHandler = \