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

SourceForge.net noreply at sourceforge.net
Thu Nov 13 17:00:56 EST 2003


Bugs item #841757, was opened at 2003-11-13 22:43
Message generated for change (Comment added) made by effbot
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: Nobody/Anonymous (nobody)
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: Fredrik Lundh (effbot)
Date: 2003-11-13 23: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