Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dbde5e

Browse files
committed
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.
1 parent 96d7e83 commit 2dbde5e

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

Lib/xmlrpclib.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def escape(s):
165165
def _stringify(string):
166166
# convert to 7-bit ascii if possible
167167
try:
168-
return string.encode("ascii")
168+
return string.decode("ascii")
169169
except UnicodeError:
170170
return string
171171

@@ -384,11 +384,13 @@ def __ne__(self, other):
384384
return self.data != other
385385

386386
def decode(self, data):
387-
self.data = base64.decodestring(data)
387+
self.data = str8(base64.decodestring(data))
388388

389389
def encode(self, out):
390390
out.write("<value><base64>\n")
391-
base64.encode(io.StringIO(self.data), out)
391+
encoded = base64.encodestring(self.data)
392+
out.write(encoded.decode('ascii'))
393+
out.write('\n')
392394
out.write("</base64></value>\n")
393395

394396
def _binary(data):
@@ -615,7 +617,6 @@ def dump_string(self, value, write, escape=escape):
615617
dispatch[str8] = dump_string
616618

617619
def dump_unicode(self, value, write, escape=escape):
618-
value = value.encode(self.encoding)
619620
write("<value><string>")
620621
write(escape(value))
621622
write("</string></value>\n")
@@ -644,9 +645,7 @@ def dump_struct(self, value, write, escape=escape):
644645
write("<value><struct>\n")
645646
for k, v in value.items():
646647
write("<member>\n")
647-
if isinstance(k, basestring):
648-
k = k.encode(self.encoding)
649-
else:
648+
if not isinstance(k, basestring):
650649
raise TypeError, "dictionary key must be string"
651650
write("<name>%s</name>\n" % escape(k))
652651
dump(v, write)

0 commit comments

Comments
 (0)