]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Bug #841757] Patch from /F to allow Unicode strings as struct keys
authorAndrew M. Kuchling <amk@amk.ca>
Sat, 5 Jun 2004 12:55:33 +0000 (12:55 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Sat, 5 Jun 2004 12:55:33 +0000 (12:55 +0000)
(Also a 2.2 bugfix candidate.)

Lib/test/test_xmlrpc.py
Lib/xmlrpclib.py
Misc/NEWS

index f1d69c95f94cb838864beadf8b2a0720952520ed..1f533d206d7da2490af71b74d308df0cc0411598 100644 (file)
@@ -10,6 +10,8 @@ alist = [{'astring': 'foo@bar.baz.spam',
           'anotherlist': ['.zyx.41'],
           'abase64': xmlrpclib.Binary("my dog has fleas"),
           'boolean': xmlrpclib.False,
+          'unicode': u'\u4000\u6000\u8000',
+          u'ukey\u4000': 'regular value',
           }]
 
 class XMLRPCTestCase(unittest.TestCase):
index 20d6e714c440c88d0ad2f6d97305741bf175040a..5f3f5e48fa38c63174e42ec52e5890c973a97fd9 100644 (file)
@@ -686,12 +686,15 @@ class Marshaller:
         self.memo[i] = None
         dump = self.__dump
         write("<value><struct>\n")
-        for k in value.keys():
+        for k, v in value.items():
             write("<member>\n")
             if type(k) is not StringType:
-                raise TypeError, "dictionary key must be string"
+                if unicode and type(k) is UnicodeType:
+                    k = k.encode(self.encoding)
+                else:
+                    raise TypeError, "dictionary key must be string"
             write("<name>%s</name>\n" % escape(k))
-            dump(value[k], write)
+            dump(v, write)
             write("</member>\n")
         write("</struct></value>\n")
         del self.memo[i]
index ddb2389df91ab5810d641423b34cae49b2abe062..4a91a6645a75a38198be28513d3671959916ad24 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@ Extension modules
 
 - Patch #954115: Properly handle UNC roots in nt.stat.
 
+- Bug #841757: xmlrpclib failed on structs with Unicode keys.
+
+
 What's New in Python 2.3.4 (final)?
 ===================================