[XML-SIG] Problem with wddx marshaller
Giuseppe Bonelli
giuseppe.bonelli at tiscalinet.it
Tue Jun 24 15:16:46 EDT 2003
have a look to line 408 in $Python/_xmlplus/marshal/generic.py
and you'll find a nice comment (thanks to the kind developer for this !)
which says:
# might need to convert unicode string to byte string
So, the DS is actually UTF-8 and not iso-8859-1.
I would patch as follows (no test done, though):
def um_end_string(self, name):
ds = self.data_stack
# might need to convert unicode string to byte string
ds = ds.encode('iso-8859-1') # <-------------------------- patch to
convert to iso-8859-1
# Probably ds.encode(encoding) works as well, provided your
encoding
# variable is set correctly
ds[-1] = str(string.join(ds[-1], ""))
self.accumulating_chars = 0
Hope this helps,
--Giuseppe Bonelli
> -----Original Message-----
> From: xml-sig-bounces+giuseppe.bonelli=tiscali.it at python.org
> [mailto:xml-sig-bounces+giuseppe.bonelli=tiscali.it at python.org
> ]On Behalf
> Of Christian Scholz
> Sent: martedì 24 giugno 2003 13.27
> To: xml-sig at python.org
> Subject: [XML-SIG] Problem with wddx marshaller
>
>
> Hi!
>
> I am trying to read some data from a server in wddx format.
> This actually
> fails because it contains umlauts which IMHO shouldn't fail as long as
> the encoding is set right.
> I tried the same with DOM and this parser reads it without problems.
>
> Here is my failing test script:
>
> -----------------------------------------------------------
>
> from xml.marshal.wddx import loads
> from xml.dom.minidom import parseString
> from xml.dom.ext import PrettyPrint
>
> s="""<?xml version="1.0" encoding="iso-8859-1" ?>
> <wddxPacket version='1.0'>
> <header></header>
> <data>
> <struct>
> <var name='dummy'>
> <string>dummyname</string>
> </var>
> <var name='name'>
> <string>Gröhlkinder</string>
> </var>
> </struct>
> </data>
> </wddxPacket>"""
>
> print "testing dom"
> doc=parseString(s)
> PrettyPrint(doc)
>
> print "testing wddx"
> print loads(s)
>
> -----------------------------------------------------------
>
> So the first call is successful and it gets pretty printed and
> the loads() call is failing with:
>
> Traceback (most recent call last):
> File "./xmlbug.py", line 27, in ?
> print loads(s)
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/mar
> shal/wddx.py", line 272, in loads
> return WDDXUnmarshaller().loads(string)
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/mar
> shal/generic.py", line 321, in loads
> return m._load(file)
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/mar
> shal/generic.py", line 331, in _load
> p.parseFile(file)
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/sax
> /drivers/drv_pyexpat.py", line 68, in parseFile
> if self.parser.Parse(buf, 0) != 1:
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/sax
> /drivers/drv_pyexpat.py", line 49, in endElement
> self.doc_handler.endElement(name)
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/mar
> shal/generic.py", line 381, in endElement
> em(name)
> File
> "/opt/Zope/python/213/lib/python2.1/site-packages/_xmlplus/mar
> shal/generic.py", line 409, in um_end_string
> ds[-1] = str(string.join(ds[-1], ""))
> UnicodeError: ASCII encoding error: ordinal not in range(128)
>
>
> So is this a (maybe known) bug or am I doing something wrong?
> (might fix it if I'd know where to start.. might look into this..)
>
> FYI: PyXML 0.8.2 with Python 2.1.3 on linux is used.
>
> regards,
> Christian
>
> --
> COM.lounge
> http://comlounge.net/
> communication & design
> info at comlounge.net
>
> _______________________________________________
> XML-SIG maillist - XML-SIG at python.org
> http://mail.python.org/mailman/listinfo/xml-sig
>
More information about the XML-SIG
mailing list