[Python-3000-checkins] r56626 - python/branches/py3k-struni/Lib/xmlrpclib.py
brett.cannon
python-3000-checkins at python.org
Mon Jul 30 05:50:35 CEST 2007
Author: brett.cannon
Date: Mon Jul 30 05:50:35 2007
New Revision: 56626
Modified:
python/branches/py3k-struni/Lib/xmlrpclib.py
Log:
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.
Modified: python/branches/py3k-struni/Lib/xmlrpclib.py
==============================================================================
--- python/branches/py3k-struni/Lib/xmlrpclib.py (original)
+++ python/branches/py3k-struni/Lib/xmlrpclib.py Mon Jul 30 05:50:35 2007
@@ -165,7 +165,7 @@
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 @@
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 @@
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 @@
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)
More information about the Python-3000-checkins
mailing list