[ python-Bugs-841757 ] xmlrpclib chokes on Unicode keys

SourceForge.net noreply at sourceforge.net
Sat Jun 5 08:56:34 EDT 2004


Bugs item #841757, was opened at 2003-11-13 16:43
Message generated for change (Comment added) made by akuchling
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=841757&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Fredrik Lundh (effbot)
>Assigned to: A.M. Kuchling (akuchling)
Summary: xmlrpclib chokes on Unicode keys

Initial Comment:
the type check in dump_struct is too strict; I suggest 
changing the loop to:

        for k, v in value.items():
            write("<member>\n")
            if type(k) is UnicodeType:
                k = k.encode(self.encoding)
            elif type(k) is not StringType:
                raise TypeError, "dictionary key must 
be string"
            write("<name>%s</name>\n" % escape(k))
            dump(v, write)
            write("</member>\n")

ths applies to all Python versions since 2.2.  
backport as necessary.

regards /F


----------------------------------------------------------------------

>Comment By: A.M. Kuchling (akuchling)
Date: 2004-06-05 08:56

Message:
Logged In: YES 
user_id=11375

Applied to CVS HEAD and to the 2.3 maintenance branch.  Thanks, 
Fredrik!

----------------------------------------------------------------------

Comment By: Fredrik Lundh (effbot)
Date: 2003-11-13 17:29

Message:
Logged In: YES 
user_id=38376

The XML-RPC specification wasn't exactly clear on this
issue, and was changed earlier this year.  See

    http://www.effbot.org/zone/xmlrpc-errata.htm
    http://www.effbot.org/zone/xmlrpc-ascii.htm

And even if the spec hadn't been changed, xmlrpclib
has always "done the right thing" with Unicode strings
in all other cases.  Trust me, I wrote the code, so I
should know ;-)

----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2003-11-13 17:10

Message:
Logged In: YES 
user_id=44345

I long ago got tired of Dave Wiener's stance on the XML-RPC 
protocol and got off any mailing lists he participated in, but I seem 
to recall that he was adamant about not allowing anything but 
ASCII characters.  Accordingly, either Unicode encodings would be 
verboten or some other transformation should be applied to them 
to make them truly ASCII (like % encoding them).  Has Dave's 
position on whether or not to accept non-ASCII on the wire 
changed?


----------------------------------------------------------------------

Comment By: Fredrik Lundh (effbot)
Date: 2003-11-13 17:00

Message:
Logged In: YES 
user_id=38376

to avoid a performance hit for existing code, the type test 
is better written as:

            if type(k) is not StringType:
                if unicode and type(k) is UnicodeType:
                    k = k.encode(self.encoding)
                else:
                    raise TypeError, "dictionary key must 
be string"

(this also works under 1.5.2)

(see attachment for a more readable "patch").


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=841757&group_id=5470



More information about the Python-bugs-list mailing list