diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 87bfb1f..f179df9 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -22,6 +22,7 @@ else:
have_unicode = True
alist = [{'astring': 'foo@bar.baz.spam',
+ 'bstring': ''.join(map(chr,xrange(256))),
'afloat': 7283.43,
'anint': 2**20,
'ashortlong': 2L,
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index c7971cc..535652d 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -690,9 +690,14 @@ class Marshaller:
dispatch[FloatType] = dump_double
def dump_string(self, value, write, escape=escape):
- write("")
- write(escape(value))
- write("\n")
+ if all(32 <= ord(byte) <= 127 for byte in value):
+ write("")
+ write(escape(value))
+ write("\n")
+ else:
+ write("\n")
+ write(base64.b64encode(value))
+ write("\n")
dispatch[StringType] = dump_string
if unicode: