Commit 0acbcb5b authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #17741: use composition, rather than inheritance, for xml.etree.iterparse's result class.

Patch by Stefan Behnel.
parent 892584e0
...@@ -1265,27 +1265,29 @@ class IncrementalParser: ...@@ -1265,27 +1265,29 @@ class IncrementalParser:
self.root = self._root self.root = self._root
class _IterParseIterator(IncrementalParser): class _IterParseIterator:
def __init__(self, source, events, parser, close_source=False): def __init__(self, source, events, parser, close_source=False):
IncrementalParser.__init__(self, events, parser) self._parser = IncrementalParser(events, parser)
self._file = source self._file = source
self._close_file = close_source self._close_file = close_source
self.root = None
def __next__(self): def __next__(self):
while 1: while 1:
for event in self.events(): for event in self._parser.events():
return event return event
if self._parser is None: if self._parser._parser is None:
self.root = self._parser.root
if self._close_file: if self._close_file:
self._file.close() self._file.close()
raise StopIteration raise StopIteration
# load event buffer # load event buffer
data = self._file.read(16384) data = self._file.read(16384)
if data: if data:
self.data_received(data) self._parser.data_received(data)
else: else:
self.eof_received() self._parser.eof_received()
def __iter__(self): def __iter__(self):
return self return self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment