diff options
| author | arcadia-devtools <[email protected]> | 2022-03-18 09:10:23 +0300 |
|---|---|---|
| committer | arcadia-devtools <[email protected]> | 2022-03-18 09:10:23 +0300 |
| commit | fef2b3a8ed5955b63c71e8e541a5acf2e393925a (patch) | |
| tree | e55d2882d5c2c71561a0aa89158ec174d81f92fd /contrib/tools/python3/src/Lib/xml | |
| parent | 2acc0fc3cdc40434ea286f2fac62386e3fd9c19d (diff) | |
intermediate changes
ref:102662f6c42fba80d7bfd4a328124cbb4294be48
Diffstat (limited to 'contrib/tools/python3/src/Lib/xml')
| -rw-r--r-- | contrib/tools/python3/src/Lib/xml/etree/ElementTree.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py b/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py index fde303c875c..dae2251d859 100644 --- a/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py +++ b/contrib/tools/python3/src/Lib/xml/etree/ElementTree.py @@ -1248,8 +1248,14 @@ def iterparse(source, events=None, parser=None): # Use the internal, undocumented _parser argument for now; When the # parser argument of iterparse is removed, this can be killed. pullparser = XMLPullParser(events=events, _parser=parser) - def iterator(): + + def iterator(source): + close_source = False 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 @@ -1265,16 +1271,12 @@ def iterparse(source, events=None, parser=None): source.close() class IterParseIterator(collections.abc.Iterator): - __next__ = iterator().__next__ + __next__ = iterator(source).__next__ it = IterParseIterator() it.root = None del iterator, IterParseIterator - close_source = False - if not hasattr(source, "read"): - source = open(source, "rb") - close_source = True - + next(it) return it |
