You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> from StringIO import StringIO
>>> source = StringIO('<body xmlns="http://éffbot.org/ns">text</body>')
>>> import xml.etree.ElementTree asET
>>> events = ("start-ns",)
>>> context =ET.iterparse(source, events)
>>> for action, elem in context:
... print action, elem
...
start-ns ('', u'http://\xe9ffbot.org/ns')
>>> source.seek(0)
>>> import xml.etree.cElementTree as cET
>>> context = cET.iterparse(source, events)
>>> for action, elem in context:
... print action, elem
...
start-ns ('', 'http://\xc3\xa9ffbot.org/ns')
I'm not sure which is more correct here, but unsing different encodings
in the result is somewhat unexpected.
nlopes commented on Jun 20, 2009
nlopesmannequin
Mannequin
More actions
This is a pretty dumb patch, but it does it's job.
Basically it decodes the utf-8 encoded prefix and uri. Then, encodes it
into Latin1. Probably there are better ways of doing this and those
ideas are welcome. Patch attached.
effbot commented on Jun 21, 2009
effbotmannequin
Mannequin
More actions
Converting from UTF-8 to Unicode is the right thing to do, but
converting back to Latin-1 is not correct -- note that ET returns a
Unicode string, not an 8-bit string. There's a "makestring" helper that
does the right thing in the library; just changing:
should work (even if you should probably do that in two steps, and look
for errors from makestring before proceeding).
nlopes commented on Jun 21, 2009
nlopesmannequin
Mannequin
More actions
You're right about the conversion to Latin1.
I actually played a bit with makestring before going in another
direction (although not very good) because makestring alone wasn't
giving what is intended.
I'll try to check tomorrow a good approach for this (already had that in
mind).
effbot commented on Jun 21, 2009
effbotmannequin
Mannequin
More actions
It should definitely give what's intended (either a Unicode string, or, if
the content is plain ASCII, an 8-bit string). What did you get instead?
nlopes commented on Jun 21, 2009
nlopesmannequin
Mannequin
More actions
I got pure gibberish output, but I know why. It was a compilation gone
wrong.
To get the output as ElementTree, I think instead of
Activity
NeilMuller commentedon Jun 11, 2009
Consider:
I'm not sure which is more correct here, but unsing different encodings
in the result is somewhat unexpected.
nlopes commentedon Jun 20, 2009
This is a pretty dumb patch, but it does it's job.
Basically it decodes the utf-8 encoded prefix and uri. Then, encodes it
into Latin1. Probably there are better ways of doing this and those
ideas are welcome. Patch attached.
effbot commentedon Jun 21, 2009
Converting from UTF-8 to Unicode is the right thing to do, but
converting back to Latin-1 is not correct -- note that ET returns a
Unicode string, not an 8-bit string. There's a "makestring" helper that
does the right thing in the library; just changing:
to
should work (even if you should probably do that in two steps, and look
for errors from makestring before proceeding).
nlopes commentedon Jun 21, 2009
You're right about the conversion to Latin1.
I actually played a bit with makestring before going in another
direction (although not very good) because makestring alone wasn't
giving what is intended.
I'll try to check tomorrow a good approach for this (already had that in
mind).
effbot commentedon Jun 21, 2009
It should definitely give what's intended (either a Unicode string, or, if
the content is plain ASCII, an 8-bit string). What did you get instead?
nlopes commentedon Jun 21, 2009
I got pure gibberish output, but I know why. It was a compilation gone
wrong.
To get the output as ElementTree, I think instead of
it should be
Else it will not be the expected result.
Or am I overseeing something?
nlopes commentedon Jun 21, 2009
Don't mind what I just said. I overlooked the N. I couldn't figure out
what was going wrong with your solution.
That works. Mine is a ... aham.
:)
florentx commentedon Feb 16, 2010
Merged with the upstream patch proposed on bpo-6472 (with test case).
florentx commentedon Mar 11, 2010
Fixed with bpo-6472.