[New-bugs-announce] [issue9257] cElementTree iterparse requires events as bytes; ElementTree uses strings

Eric Talevich report at bugs.python.org
Wed Jul 14 05:27:47 CEST 2010


New submission from Eric Talevich <eric.talevich at gmail.com>:

In xml.etree, ElementTree and cElementTree implement different interfaces for the iterparse function/class.

In ElementTree, the argument "events" must be a tuple of strings:

from xml.etree import ElementTree as ET
for result in ET.iterparse('example.xml', events=('start', 'end')):
    print(result)

That works, given a valid XML file 'example.xml'. If the event names are given as bytes instead of strings (b'start', b'end'), there's no crash, but no events are recognized.

In cElementTree, it's the opposite: the events argument must be a tuple of bytes:

from xml.etree import cElementTree as cET
for result in cET.iterparse('example.xml', events=(b'start', b'end')):
    print(result)

Giving a tuple of strings instead of bytes results in:

>>> for result in cET.iterparse('example.xml', events=('start', 'end')):
...     print(result)
TypeError: invalid event tuple


This makes it difficult to use ElementTree as a backup for cElementTree, or at least very awkward.

----------
components: Library (Lib)
messages: 110252
nosy: eric-talevich
priority: normal
severity: normal
status: open
title: cElementTree iterparse requires events as bytes; ElementTree uses strings
versions: Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9257>
_______________________________________


More information about the New-bugs-announce mailing list