summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpclib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-01-20 08:33:51 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-01-20 08:33:51 (GMT)
commit9b5177c41ae507c7e14a949c93f0d68ec54b6ecf (patch)
treeb2f06e9f1068846b732b6d33c5b6fd8c70868eca /Lib/xmlrpclib.py
parentcb868363c2437314d1e6e04179954e1ca3af250a (diff)
downloadcpython-9b5177c41ae507c7e14a949c93f0d68ec54b6ecf.zip
cpython-9b5177c41ae507c7e14a949c93f0d68ec54b6ecf.tar.gz
cpython-9b5177c41ae507c7e14a949c93f0d68ec54b6ecf.tar.bz2
Issue #26147: xmlrpclib now works with unicode not encodable with used
non-UTF-8 encoding.
Diffstat (limited to 'Lib/xmlrpclib.py')
-rw-r--r--Lib/xmlrpclib.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index a1800a1..e0e399c 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -703,9 +703,8 @@ class Marshaller:
if unicode:
def dump_unicode(self, value, write, escape=escape):
- value = value.encode(self.encoding)
write("<value><string>")
- write(escape(value))
+ write(escape(value).encode(self.encoding, 'xmlcharrefreplace'))
write("</string></value>\n")
dispatch[UnicodeType] = dump_unicode
@@ -732,12 +731,13 @@ class Marshaller:
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
- if type(k) is not StringType:
- if unicode and type(k) is UnicodeType:
- k = k.encode(self.encoding)
- else:
- raise TypeError, "dictionary key must be string"
- write("<name>%s</name>\n" % escape(k))
+ if type(k) is StringType:
+ k = escape(k)
+ elif unicode and type(k) is UnicodeType:
+ k = escape(k).encode(self.encoding, 'xmlcharrefreplace')
+ else:
+ raise TypeError, "dictionary key must be string"
+ write("<name>%s</name>\n" % k)
dump(v, write)
write("</member>\n")
write("</struct></value>\n")
@@ -1099,7 +1099,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
if methodname:
# a method call
if not isinstance(methodname, StringType):
- methodname = methodname.encode(encoding)
+ methodname = methodname.encode(encoding, 'xmlcharrefreplace')
data = (
xmlheader,
"<methodCall>\n"