diff options
| author | shadchin <[email protected]> | 2024-02-07 09:25:06 +0300 |
|---|---|---|
| committer | Alexander Smirnov <[email protected]> | 2024-02-09 19:18:32 +0300 |
| commit | f0785dc88eee3da0f1514f5b4cafa931571e669d (patch) | |
| tree | 44165310ad6023cd29776f9b1b4477364cd2b5bb /contrib/tools/python3/src/Lib/xml | |
| parent | 2c0985fb513cb5b352324abf223bf749c6c2bd24 (diff) | |
Update Python 3 to 3.11.8
Diffstat (limited to 'contrib/tools/python3/src/Lib/xml')
| -rw-r--r-- | contrib/tools/python3/src/Lib/xml/etree/ElementTree.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py b/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py index 1dc80351bf7..fce0c2963a2 100644 --- a/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py +++ b/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py @@ -99,6 +99,7 @@ import io import collections import collections.abc import contextlib +import weakref from . import ElementPath @@ -1238,13 +1239,14 @@ def iterparse(source, events=None, parser=None): # parser argument of iterparse is removed, this can be killed. pullparser = XMLPullParser(events=events, _parser=parser) - def iterator(source): + if not hasattr(source, "read"): + source = open(source, "rb") + close_source = True + else: close_source = False + + def iterator(source): try: - if not hasattr(source, "read"): - source = open(source, "rb") - close_source = True - yield None while True: yield from pullparser.read_events() # load event buffer @@ -1254,18 +1256,23 @@ def iterparse(source, events=None, parser=None): pullparser.feed(data) root = pullparser._close_and_return_root() yield from pullparser.read_events() - it.root = root + it = wr() + if it is not None: + it.root = root finally: if close_source: source.close() class IterParseIterator(collections.abc.Iterator): __next__ = iterator(source).__next__ + + def __del__(self): + if close_source: + source.close() + it = IterParseIterator() it.root = None - del iterator, IterParseIterator - - next(it) + wr = weakref.ref(it) return it |
