[Zope] xmlrpc and charsets

Gilles Lenfant gilles at pilotsystems.net
Wed Oct 15 07:09:09 EDT 2003


----- Original Message -----
From: "Toby Dickenson" <tdickenson at geminidataloggers.com>
To: "Gilles Lenfant" <gilles at pilotsystems.net>; <zope at zope.org>
Sent: Wednesday, October 15, 2003 8:52 AM
Subject: Re: [Zope] xmlrpc and charsets


> On Tuesday 14 October 2003 20:41, Gilles Lenfant wrote:
> > I'm stuck hacking the xmlrpc stuff. I can't understand the charset rules
> > with xmlrpc in the Zope implementation.
>
> The original xmlrpc spec required that all strings were ascii. very silly.
> Most xmlrpc implementations dont enforce that.... what library are you
using
> on the client?


The client is another Zope instance that uses the Zope provided
xmlrpclib.py.
I'm familiar using this one but it's the first time I sent non ascii chars
through xmlrpc.

>
> > Why doesn't it provide unicode string because, the server side is not
> > supposed to know (and has no way to know AFAIK) the charset of the
client
> > side.
>
> Are you sure it doesnt? if there is a unicode value inside the xml
<string>
> tag I am sure the Unmarshaller class will convert it into a python unicode
> object.

I'm trying to hack the stuff to have a view to the marshalled xml.
I'm just using the standard API...

server = xmlrpclib(http://some.server.net/)
x = server.doStuff(a, b, c)

I dunno how to mention the encoding to be used for strings (any of a, b, or
c) to have the stuff correctly marshaled and transmitted to the server.
Otherwise, I could "base64" those texts for the transport. and mention the
charset as a parameter.
Do u thing this may be a solution ?

>
> > Should that charset be provided explicitely in the xmlrpc request to the
> > server ?
>
> character encoding of what?

Of the client side provided texts.

>
> the xml file defines its own character encoding, but that is an irrelevant
> detail of the implementation of the xmlrpc library.
>
> or did you mean the encoding used by the client application? Assuming you
are
> using pythons xmlrpclib, you need to pass unicode object parameters into
the
> xmlrpc library and everything will 'just work'.

Ah OK, I gonna try this one...

# Client side (external method)
charset = 'iso-8859-1'
# Setting params
a = unicode(a, charset)
b = unicode(b, charset)
# Making request
server = xmlrpclib.Server("http://some.webservice.net/")
resultstring = server.doStuff(a, b).encode(charset, 'replace')

# Server side handler (TTW python script)
##parameters=a, b
charset = 'utf-8'
a = a.encode(charset, 'replace')
b = b.encode(charset, 'replace')
# Do the stuff
...
return unicode(stuff, charset)

Cheers...

--Gilles





More information about the Zope mailing list