[Python-Dev] xmlrpclib
Bill Bumgarner
bbum@codefab.com
Thu, 6 Mar 2003 12:10:42 -0500
On Thursday, Mar 6, 2003, at 11:50 US/Eastern, Skip Montanaro wrote:
> Bill> Is there active work on the xmlrpclib module these days? The
> Bill> HTTPTransport patch/addition should likely go out with 2.3
> as it
> Bill> adds easy authentication and proxy support to xmlrpclib.
>
> Can you provide a SF id? I can't seem to find it.
It had been closed or moved out of the SF bug queue by Fred about the
same time he left python-dev, I believe. I had sent the
HTTPTransport source to Fred, but that sounds like a dead end these
days.
Found it: 648658
> Bill> Also, the unicode support in xmlrpclib is broken in that it
> can't
> Bill> handle subclasses of <type 'unicode'>.
>
> Does it handle subclasses of str?
I haven't tested, but looking at the implementation, I don't think it
will.
In my case, I'm using xmlrpclib in the context of a Cocoa/Python based
application that frequently uses Objective-C sourced strings as a part
of the RPC request. The PyObjC bridge now bridges NSStrings as a
subclass of unicode.
Currently, the Marshaller class in xmlrpclib builds a simple dictionary
of types used to encode raw objects to XML.
class Marshaller:
...
dispatch = {}
...
def dump_string(self, value, escape=escape):
self.write("<value><string>%s</string></value>\n" %
escape(value))
dispatch[StringType] = dump_string
if unicode:
def dump_unicode(self, value, escape=escape):
value = value.encode(self.encoding)
self.write("<value><string>%s</string></value>\n" %
escape(value))
dispatch[UnicodeType] = dump_unicode
...
Where the dump method is:
def __dump(self, value):
try:
f = self.dispatch[type(value)]
except KeyError:
raise TypeError, "cannot marshal %s objects" % type(value)
else:
f(self, value)
So, no, it doesn't do subclasses properly. The workaround [for me] was
easy... and bogus:
import xmlrpclib
Marshaller.dispatch[type(NSString.stringWithString_(''))] =
Marshaller.dispatch[type(u'')]
b.bum