Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f24e7e6c
Commit
f24e7e6c
authored
Nov 01, 2011
by
Florent Xicluna
Browse files
Options
Browse Files
Download
Plain Diff
Merge 3.2: issue #2892
parents
f588dd60
91d5193b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
30 deletions
+49
-30
Lib/test/test_xml_etree.py
Lib/test/test_xml_etree.py
+1
-0
Lib/xml/etree/ElementTree.py
Lib/xml/etree/ElementTree.py
+23
-15
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_elementtree.c
Modules/_elementtree.c
+23
-15
No files found.
Lib/test/test_xml_etree.py
View file @
f24e7e6c
...
...
@@ -754,6 +754,7 @@ def iterparse():
... print(action, elem.tag)
... except ET.ParseError as v:
... print(v)
end document
junk after document element: line 1, column 12
"""
...
...
Lib/xml/etree/ElementTree.py
View file @
f24e7e6c
...
...
@@ -1250,6 +1250,7 @@ class _IterParseIterator:
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
...
...
@@ -1291,24 +1292,31 @@ class _IterParseIterator:
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
...
...
Misc/NEWS
View file @
f24e7e6c
...
...
@@ -350,6 +350,8 @@ Core and Builtins
Library
-------
-
Issue
#
2892
:
preserve
iterparse
events
in
case
of
SyntaxError
.
-
Issue
#
13287
:
urllib
.
request
and
urllib
.
error
now
contains
a
__all__
and
exposes
only
relevant
Classes
,
Functions
.
Patch
by
Florent
Xicluna
.
...
...
Modules/_elementtree.c
View file @
f24e7e6c
...
...
@@ -3016,6 +3016,7 @@ PyInit__elementtree(void)
" self._file = file
\n
"
" self._events = []
\n
"
" self._index = 0
\n
"
" self._error = None
\n
"
" self.root = self._root = None
\n
"
" b = cElementTree.TreeBuilder()
\n
"
" self._parser = cElementTree.XMLParser(b)
\n
"
...
...
@@ -3024,24 +3025,31 @@ PyInit__elementtree(void)
" while 1:
\n
"
" try:
\n
"
" item = self._events[self._index]
\n
"
" self._index += 1
\n
"
" return item
\n
"
" except IndexError:
\n
"
" if self._parser is None:
\n
"
" self.root = self._root
\n
"
" if self._close_file:
\n
"
" self._file.close()
\n
"
" raise StopIteration
\n
"
" # load event buffer
\n
"
" del self._events[:]
\n
"
" self._index = 0
\n
"
" data = self._file.read(16384)
\n
"
" if data:
\n
"
" pass
\n
"
" if self._error:
\n
"
" e = self._error
\n
"
" self._error = None
\n
"
" raise e
\n
"
" if self._parser is None:
\n
"
" self.root = self._root
\n
"
" if self._close_file:
\n
"
" self._file.close()
\n
"
" raise StopIteration
\n
"
" # load event buffer
\n
"
" del self._events[:]
\n
"
" self._index = 0
\n
"
" data = self._file.read(16384)
\n
"
" if data:
\n
"
" try:
\n
"
" self._parser.feed(data)
\n
"
" else:
\n
"
" self._root = self._parser.close()
\n
"
" self._parser = None
\n
"
" except SyntaxError as exc:
\n
"
" self._error = exc
\n
"
" else:
\n
"
" self._
index = self._index + 1
\n
"
"
return item
\n
"
" self._
root = self._parser.close()
\n
"
"
self._parser = None
\n
"
" def __iter__(self):
\n
"
" return self
\n
"
"cElementTree.iterparse = iterparse
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment