[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Workaround bug in xmlrpclib's string escaping. That library outputs invalid



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 395e57314710c0c8d21e3ebc695f17ef6b93709d
# Parent  13e6993a0c6536a4d51453409011a54c22fbf216
Workaround bug in xmlrpclib's string escaping.  That library outputs invalid
UTF-8 if given a string containing high-bit characters, so instead pass in
Unicode strings, for which the escaping is correct.

This fixes a bug seen when the dmesg of a machine contains high bit characters,
but I'm sure there are other ways in which it might be triggered.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 13e6993a0c65 -r 395e57314710 tools/python/xen/util/xmlrpclib2.py
--- a/tools/python/xen/util/xmlrpclib2.py       Tue Apr  4 08:53:53 2006
+++ b/tools/python/xen/util/xmlrpclib2.py       Tue Apr  4 10:08:20 2006
@@ -19,6 +19,8 @@
 """
 An enhanced XML-RPC client/server interface for Python.
 """
+
+import types
 
 from httplib import HTTPConnection, HTTP
 from xmlrpclib import Transport
@@ -77,6 +79,15 @@
             else:
                 response = self._dispatch(method, params)
 
+            # Convert strings to unicode strings so that they are escaped
+            # properly by xmlrpclib.  We use latin-1 here, but any
+            # ASCII-compatible scheme would do -- we just care about getting
+            # the bytes across the wire.
+            # Any message handler that actually cares about the charset in
+            # use should be returning Unicode strings.
+            if isinstance(response, types.StringType):
+                response = unicode(response, 'iso-8859-1')
+
             response = (response,)
             response = xmlrpclib.dumps(response,
                                        methodresponse=1,

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.