[issue14852] json and ElementTree parsers misbehave on streams containing more than a single object

Frederick Ross report at bugs.python.org
Fri May 18 19:29:22 CEST 2012


New submission from Frederick Ross <madhadron at gmail.com>:

When parsing something like '<a>x</a><a>y</a>' with xml.etree.ElementTree, or '{}{}' with json, these parser throw exceptions instead of reading a single element of the kind they understand off the stream (or throwing an exception if there is no element they understand) and leaving the stream in a sane state.

So I should be able to write

import xml.etree.ElementTree as et
import StringIO
s = StringIO.StringIO("<a>x</a><a>y</a>")
elem1 = et.parse(s)
elem2 = et.parse(s)

and have elem1 correspond to "<a>x</a>" and elem2 correspond to "<a>y</a>".

At the very least, if the parsers refuse to parse partial streams, they should at least not destroy the streams.

----------
components: Library (Lib)
messages: 161068
nosy: Frederick.Ross
priority: normal
severity: normal
status: open
title: json and ElementTree parsers misbehave on streams containing more than a single object
versions: Python 2.6, Python 2.7

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


More information about the Python-bugs-list mailing list