ia64/xen-unstable

changeset 9580:395e57314710

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@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Apr 04 11:08:20 2006 +0100 (2006-04-04)
parents 13e6993a0c65
children 9ae1f9349b76 09967f2d6e3b
files tools/python/xen/util/xmlrpclib2.py
line diff
     1.1 --- a/tools/python/xen/util/xmlrpclib2.py	Tue Apr 04 09:53:53 2006 +0100
     1.2 +++ b/tools/python/xen/util/xmlrpclib2.py	Tue Apr 04 11:08:20 2006 +0100
     1.3 @@ -20,6 +20,8 @@
     1.4  An enhanced XML-RPC client/server interface for Python.
     1.5  """
     1.6  
     1.7 +import types
     1.8 +
     1.9  from httplib import HTTPConnection, HTTP
    1.10  from xmlrpclib import Transport
    1.11  from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
    1.12 @@ -77,6 +79,15 @@ class TCPXMLRPCServer(SocketServer.Threa
    1.13              else:
    1.14                  response = self._dispatch(method, params)
    1.15  
    1.16 +            # Convert strings to unicode strings so that they are escaped
    1.17 +            # properly by xmlrpclib.  We use latin-1 here, but any
    1.18 +            # ASCII-compatible scheme would do -- we just care about getting
    1.19 +            # the bytes across the wire.
    1.20 +            # Any message handler that actually cares about the charset in
    1.21 +            # use should be returning Unicode strings.
    1.22 +            if isinstance(response, types.StringType):
    1.23 +                response = unicode(response, 'iso-8859-1')
    1.24 +
    1.25              response = (response,)
    1.26              response = xmlrpclib.dumps(response,
    1.27                                         methodresponse=1,