-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ElementTree with upstream changes #50721
Comments
I can't quite sort this out, because it's difficult to see what is I think someone should go over the page and sort this out and make it I stumbled on this trying to parses and extract individual bits of |
This isn't just a documentation issue. A function named getiterator(), iterator = element.getiterator()
next(iterator)
subelement = next(iterator) Which broke when I tried switching to ElementTree from cElementTree, Also, for findall() and friends, is there any reason why we can't stick for x in tree.findall(path):
mutate_tree(tree, x) |
There's many differences between both implementations. ~ $ ./python
Python 3.1.1+ (release31-maint:76650, Dec 3 2009, 17:14:50)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.etree import ElementTree as ET, cElementTree as cET
>>> from io import StringIO
>>> SAMPLE = '<root/>'
>>> IO_SAMPLE = StringIO(SAMPLE) With ElementTree >>> elt = ET.XML(SAMPLE)
>>> elt.getiterator()
[<Element root at 15cb920>]
>>> elt.findall('') # or '.'
[<Element root at 15cb920>]
>>> elt.findall('./')
[<Element root at 15cb920>]
>>> elt.items()
dict_items([])
>>> elt.keys()
dict_keys([])
>>> elt[:]
[]
>>> IO_SAMPLE.seek(0)
>>> next(ET.iterparse(IO_SAMPLE))
('end', <Element root at 15d60d0>)
>>> IO_SAMPLE.seek(0)
>>> list(ET.iterparse(IO_SAMPLE))
[('end', <Element root at 15583e0>)] With cElementTree >>> elt_c = cET.XML(SAMPLE)
>>> elt_c.getiterator()
<generator object getiterator at 0x15baae0>
>>> elt_c.findall('')
[]
>>> elt_c.findall('./')
[<Element 'root' at 0x15cf3a0>]
>>> elt_c.items()
[]
>>> elt_c.keys()
[]
>>> elt_c[:]
Traceback (most recent call last):
TypeError: sequence index must be integer, not 'slice'
>>> IO_SAMPLE.seek(0)
>>> next(cET.iterparse(IO_SAMPLE))
Traceback (most recent call last):
TypeError: iterparse object is not an iterator
>>> IO_SAMPLE.seek(0)
>>> list(cET.iterparse(IO_SAMPLE))
[(b'end', <Element 'root' at 0x15cf940>)] |
Proposed patch fixes most of the discrepancies between both implementations. It restores some features that were lost with Python 3:
Some tests were added to check these issues. |
I fixed it differently, using the upstream modules (Thank you Fredrik).
It works. |
The patch should have doc updates for new functionality, if any. |
I see some new features in the changelog. (patch "py3k" fixed: support assignment of arbitrary sequences) |
Patch for the documentation. (source: upstream documentation) |
Small update of the patch for 3.2: the __cmp__method is replaced with |
It would be nice to upgrade ElementTree for 2.7 and 3.2, at least. |
Patch updated, with upstream packages:
Now all tests are identical for the ElementTree part:
Waiting for some developer kind enough to review and merge in 2.7 and 3.2. |
Given the size of the patch, it's very difficult to review properly. |
Ok, will do the upload to rietveld. In addition to the straight review of the patch itself, you could:
Btw, I've backported the last tests (bpo-2746, bpo-6233) to all 4 test files (ET and cET, 2.x and 3.x). |
Here it is: |
Update the 2.x patch with the last version uploaded to rietveld (patch set 5). Improved test coverage with upstream tests and tests cases provided by Neil on issue bpo-6232. Note: the patch for 3.x is obsolete. |
Strip out the experimental C API. |
Fixed on trunk with r78838. Thank you Fredrik and Antoine for reviewing this patch. |
W00t! |
Patch to merge ElementTree 1.3 in 3.x. |
Merged in 3.x with r78942 and r78945. See bpo-8047 for a discussion about the |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: