summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpclib.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-07-30 03:50:35 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-07-30 03:50:35 (GMT)
commit2dbde5ea444de788721e9195d644da38061204c3 (patch)
treedc903321b3b190353a3a037607dc754bc15a1dc9 /Lib/xmlrpclib.py
parent96d7e8369c9ac4e18be002fb4af1400b4a0ca9dd (diff)
downloadcpython-2dbde5ea444de788721e9195d644da38061204c3.zip
cpython-2dbde5ea444de788721e9195d644da38061204c3.tar.gz
cpython-2dbde5ea444de788721e9195d644da38061204c3.tar.bz2
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.
Diffstat (limited to 'Lib/xmlrpclib.py')
-rw-r--r--Lib/xmlrpclib.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index 2b3f1db..83b3a04 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("<value><base64>\n")
- base64.encode(io.StringIO(self.data), out)
+ encoded = base64.encodestring(self.data)
+ out.write(encoded.decode('ascii'))
+ out.write('\n')
out.write("</base64></value>\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("<value><string>")
write(escape(value))
write("</string></value>\n")
@@ -644,9 +645,7 @@ class Marshaller:
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
- if isinstance(k, basestring):
- k = k.encode(self.encoding)
- else:
+ if not isinstance(k, basestring):
raise TypeError, "dictionary key must be string"
write("<name>%s</name>\n" % escape(k))
dump(v, write)