summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2011-11-01 22:34:41 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2011-11-01 22:34:41 (GMT)
commit0965ee213e079a84686a6cfd1ada125f0ff8d575 (patch)
tree968850ba591d77304e6d136492b22d22d447a111 /Lib/xml
parent7e82b276dd5c1f786e7bd3c1554ac2017a909ab9 (diff)
downloadcpython-0965ee213e079a84686a6cfd1ada125f0ff8d575.zip
cpython-0965ee213e079a84686a6cfd1ada125f0ff8d575.tar.gz
cpython-0965ee213e079a84686a6cfd1ada125f0ff8d575.tar.bz2
Issue #2892: preserve iterparse events in case of SyntaxError
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/etree/ElementTree.py38
1 files changed, 23 insertions, 15 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 19862e2..2b0cf0c 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1210,6 +1210,7 @@ class _IterParseIterator(object):
self._close_file = close_source
self._events = []
self._index = 0
+ self._error = None
self.root = self._root = None
self._parser = parser
# wire up the parser for event reporting
@@ -1255,24 +1256,31 @@ class _IterParseIterator(object):
while 1:
try:
item = self._events[self._index]
+ self._index += 1
+ return item
except IndexError:
- if self._parser is None:
- self.root = self._root
- if self._close_file:
- self._file.close()
- raise StopIteration
- # load event buffer
- del self._events[:]
- self._index = 0
- data = self._file.read(16384)
- if data:
+ pass
+ if self._error:
+ e = self._error
+ self._error = None
+ raise e
+ if self._parser is None:
+ self.root = self._root
+ if self._close_file:
+ self._file.close()
+ raise StopIteration
+ # load event buffer
+ del self._events[:]
+ self._index = 0
+ data = self._file.read(16384)
+ if data:
+ try:
self._parser.feed(data)
- else:
- self._root = self._parser.close()
- self._parser = None
+ except SyntaxError as exc:
+ self._error = exc
else:
- self._index = self._index + 1
- return item
+ self._root = self._parser.close()
+ self._parser = None
def __iter__(self):
return self