This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gyorkop
Recipients gyorkop
Date 2010-10-11.16:16:38
SpamBayes Score 0.009826829
Marked as misclassified No
Message-id <1286813801.19.0.762560466895.issue10066@psf.upfronthosting.co.za>
In-reply-to
Content
If I add a string to the response, which contains non-printable characters, the output will not be parsed by the most of the XML parsers (I tried with XML-RPC for PHP).

Here is my quick and dirty fix:

--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -165,9 +165,18 @@ def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
     return data
 
 def escape(s, replace=string.replace):
-    s = replace(s, "&", "&amp;")
-    s = replace(s, "<", "&lt;")
-    return replace(s, ">", "&gt;",)
+    res = ''
+    for char in s:
+        char_code = ord(char)
+        if (char_code < 32 and char_code not in (9, 10, 13)) or char_code > 126:
+            res += '\\x%02x' % ord(char)
+        else:
+            res += char
+
+    res = replace(res, "&", "&amp;")
+    res = replace(res, "<", "&lt;")
+    res = replace(res, ">", "&gt;")
+    return res
 
 if unicode:
     def _stringify(string):
History
Date User Action Args
2010-10-11 16:16:41gyorkopsetrecipients: + gyorkop
2010-10-11 16:16:41gyorkopsetmessageid: <1286813801.19.0.762560466895.issue10066@psf.upfronthosting.co.za>
2010-10-11 16:16:39gyorkoplinkissue10066 messages
2010-10-11 16:16:38gyorkopcreate