From 4e1580f988ce24ee71151ace3ccbb137a97a5dd6 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Sat, 5 Jun 2004 12:55:33 +0000 Subject: [PATCH] [Bug #841757] Patch from /F to allow Unicode strings as struct keys (Also a 2.2 bugfix candidate.) --- Lib/test/test_xmlrpc.py | 2 ++ Lib/xmlrpclib.py | 9 ++++++--- Misc/NEWS | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index f1d69c95f94c..1f533d206d7d 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -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): diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py index 20d6e714c440..5f3f5e48fa38 100644 --- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -686,12 +686,15 @@ class Marshaller: self.memo[i] = None dump = self.__dump write("\n") - for k in value.keys(): + for k, v in value.items(): write("\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("%s\n" % escape(k)) - dump(value[k], write) + dump(v, write) write("\n") write("\n") del self.memo[i] diff --git a/Misc/NEWS b/Misc/NEWS index ddb2389df91a..4a91a6645a75 100644 --- 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)? =================================== -- 2.47.3