[Patches] Patch for xmlrpc encoding

Ragnar Kjørstad python@ragnark.vestdata.no
Fri, 6 Dec 2002 02:52:20 +0100


--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by stine.vestdata.no id gB61qKN13881

Hi

The dumps-method in xmlrpclib has the following comment:
    All 8-bit strings in the data structure are assumed to use the
    packet encoding.  Unicode strings are automatically converted,
    where necessary.


This doesn't work very well. In our particular case we're using latin_1
as our default encoding, and we're using UTF-8 for the packet encoding.
We can't really change the default encoding, because the sql-modules
transfer latin_1 encoded data and we can't change the packet encoding to
latin_1 because the xmlrpc-client (php) doesn't work with that.


The attached patch changes xmlrpclib to convert strings to unicode using
the default encoding, and then convert them back to strings with the
packet encoding. If unicode is not available it falls back to the old
behaviour.

I guess for performance it could check if the defaultencoding is the
same as the packet-encoding, but my guess is that it hardly ever is, so
no reason to optimize for it.

Note; I'm not at all sure this is the best way to fix the problem. If
it's not, please feel free to ignore this patch, or even better - tell
me what the preferable fix is.


Thanks.



--=20
Ragnar Kj=F8rstad
Zet.no

--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=disclamer

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.

--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="xmlrpclib_encoding.patch"

--- xmlrpclib.py.orig	2002-12-06 02:38:25.000000000 +0100
+++ xmlrpclib.py	2002-12-06 02:51:31.000000000 +0100
@@ -485,6 +485,9 @@
     dispatch[FloatType] = dump_double
 
     def dump_string(self, value, escape=escape):
+        if unicode:
+            value = value.decode()
+            value = value.encode(self.encoding)
         self.write("<value><string>%s</string></value>\n" % escape(value))
     dispatch[StringType] = dump_string
 

--tThc/1wpZn/ma/RB--