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

SourceForge.net noreply at sourceforge.net
Thu Nov 13 17:10:46 EST 2003


Bugs item #841757, was opened at 2003-11-13 15:43
Message generated for change (Comment added) made by montanaro
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: Open
Resolution: None
Priority: 5
Submitted By: Fredrik Lundh (effbot)
>Assigned to: Skip Montanaro (montanaro)
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: Skip Montanaro (montanaro)
Date: 2003-11-13 16: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 16: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