This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xmlrpclib chokes on Unicode keys
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, effbot, skip.montanaro
Priority: normal Keywords:

Created on 2003-11-13 21:43 by effbot, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
xmlrpclib-841757.txt effbot, 2003-11-13 22:00
Messages (5)
msg18990 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2003-11-13 21:43
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
msg18991 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2003-11-13 22:00
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").
msg18992 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2003-11-13 22:10
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?
msg18993 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2003-11-13 22:29
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 ;-)
msg18994 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-05 12:56
Logged In: YES 
user_id=11375

Applied to CVS HEAD and to the 2.3 maintenance branch.  Thanks, 
Fredrik!
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39544
2003-11-13 21:43:31effbotcreate