New submission from Eric Talevich <eric.talev...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue9257>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to