From: Brett Cannon Date: Mon, 30 Jul 2007 03:50:35 +0000 (+0000) Subject: In cases where dealing with base64, do the conversion but then get the ASCII X-Git-Tag: v3.0a1~558 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2dbde5ea444de788721e9195d644da38061204c3;p=thirdparty%2FPython%2Fcpython.git In cases where dealing with base64, do the conversion but then get the ASCII string representation for use in the XML. Also strip out some unneeded encoding/decoding steps. --- diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py index 2b3f1db55756..83b3a0466678 100644 --- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -165,7 +165,7 @@ def escape(s): def _stringify(string): # convert to 7-bit ascii if possible try: - return string.encode("ascii") + return string.decode("ascii") except UnicodeError: return string @@ -384,11 +384,13 @@ class Binary: return self.data != other def decode(self, data): - self.data = base64.decodestring(data) + self.data = str8(base64.decodestring(data)) def encode(self, out): out.write("\n") - base64.encode(io.StringIO(self.data), out) + encoded = base64.encodestring(self.data) + out.write(encoded.decode('ascii')) + out.write('\n') out.write("\n") def _binary(data): @@ -615,7 +617,6 @@ class Marshaller: dispatch[str8] = dump_string def dump_unicode(self, value, write, escape=escape): - value = value.encode(self.encoding) write("") write(escape(value)) write("\n") @@ -644,9 +645,7 @@ class Marshaller: write("\n") for k, v in value.items(): write("\n") - if isinstance(k, basestring): - k = k.encode(self.encoding) - else: + if not isinstance(k, basestring): raise TypeError, "dictionary key must be string" write("%s\n" % escape(k)) dump(v, write)