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

2012-05-18 Thread Frederick Ross

New submission from Frederick Ross :

When parsing something like 'xy' 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("xy")
elem1 = et.parse(s)
elem2 = et.parse(s)

and have elem1 correspond to "x" and elem2 correspond to "y".

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 
<http://bugs.python.org/issue14852>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14891] An error in bindings of closures

2012-05-23 Thread Frederick Ross

New submission from Frederick Ross :

The following code throws an UnboundLocal error:

def f(x):
def g():
x = x + "a"
return x
return g()
f("b")

--
components: None
messages: 161432
nosy: Frederick.Ross
priority: normal
severity: normal
status: open
title: An error in bindings of closures
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue14891>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14891] An error in bindings of closures

2012-05-23 Thread Frederick Ross

Frederick Ross  added the comment:

Assignment in Python creates a new binding. Whether the new binding shadows or 
replaces an old binding should be irrelevant. This behavior is inconsistent 
with that. Please fix expectations, and then Python interpreter.

--
resolution: invalid -> 
status: closed -> open

___
Python tracker 
<http://bugs.python.org/issue14891>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2012-05-25 Thread Frederick Ross

Frederick Ross  added the comment:

Antoine, It's not iterative parsing, it's a sequence of XML docs or json 
objects.

Eric, the server I'm retrieving from, for real time searches, steadily produces 
a stream of (each properly formed) XML or json documents containing new search 
results. However, at the moment I have to edit the stream on the fly to wrap an 
outer tag around it and remove any DTD in inner elements, or I can't use the 
XML parser. Such a workaround isn't possible with the json parser, since it has 
no iterative parsing mode.

--

___
Python tracker 
<http://bugs.python.org/issue14852>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2012-05-25 Thread Frederick Ross

Frederick Ross  added the comment:

In the case of files, sure, it's fine. The error gives me the offset, and I can 
go pull it out and buffer it, and it's fine. Plus XML is strict about having 
only one document per file.

For streams, none of this is applicable. I can't seek in a streaming network 
connection. If the parser leaves it in an unusable state, then I lose 
everything that may follow. It makes Python unusable in certain, not very rare, 
cases of network programming.

I'll just add that Haskell's Parsec does this right, and should be used as an 
example.

--

___
Python tracker 
<http://bugs.python.org/issue14852>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com