[Python-Dev] Re: [Patches] Patch for xmlrpc encoding

M.-A. Lemburg mal@lemburg.com
Mon, 09 Dec 2002 11:15:38 +0100


Ragnar Kj=F8rstad wrote:
> Hi
>=20
> 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.
>=20
>=20
> 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 t=
o
> latin_1 because the xmlrpc-client (php) doesn't work with that.
 >
> The attached patch changes xmlrpclib to convert strings to unicode usin=
g
> 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 believe this is overkill. If you need this behaviour, subclass
the Marshaller in xmlrpclib and add your feature to that subclass.
Then replace the Marshaller class in xmlrpclib with your subclass.

Aside: xmlrpclib should support subclassing the Marshaller and
Unmarshaller more transparently. Currently, the two are hard-coded
into the rest of xmlrpclib without the possibility to provide your
own subclasses without tweaking xmlrpclib from the outside.

> 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.
>=20
> 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.

Please post patches using the SourceForge patch manager.

--=20
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/