[Zope] Re: I'm clumsy with XML-RPC.
Kyler Laird
Kyler at Lairds.com
Fri Dec 26 23:13:52 EST 2003
O.k., I decided to attack it again this evening. It's starting to feel
good. Before I forget what I did, I want to get my notes recorded.
Maybe someone else will need to do this someday.
The first step I took was to modify HTTPRequest.py so that if the
request is just a single arg that's a dictionary, it stuffs the
name/value pairs (with types) into fslist and then parses them just as
if they'd been passed it by HTTP.
[code too ugly to post - You'd do better on your own.]
This is good. It lets me use named parameters *almost* like plain
Python.
Zope_server.test({'first': 'une', 'second': 'deux'})
I can use integers, floats, strings, lists, and dictionaries. They all
slip right into place. I liked it...but not enough.
With the server working better, I felt like seeing if I could make the
calls from the client even simpler. Here's the terribly simple kludge
I developed.
class _Method(xmlrpclib._Method):
def __call__(self, *args, **kw):
if kw:
return self.__send(self.__name, tuple(list(args)
+ [kw]))
else:
return self.__send(self.__name, args)
xmlrpclib._Method = _Method
O.k., besides screwing up a standard library, what does that do? Well,
it lets me make calls like this.
Zope_server.test(first='une', second='deux')
Ah...much better.
With that in place, I started playing. I quickly discovered that Zope
XML-RPC still doesn't handle binary data well. I ran into this about a
year ago, trying to send data to Zope. Now I just wanted to get an
image *from* Zope. The xmlrpclib call would choke on illegal characters
in the returned "<string>" element.
My solution is to modify Zope's xmlrpc.py so that setBody converts body
to a Binary object before marshalling it.
body = xmlrpclib.dumps((xmlrpclib.Binary(body),), methodresponse=1)
Now I can do real stuff.
toolbox = xmlrpclib.Server("https://aviationtoolbox.org/Members/kyler/tools/")
chunk = toolbox.chunk_create(
ul_lon=-87.0, ul_lat=40.5,
lr_lon=-86.8, lr_lat=40.4
)
chunk_file = open('/tmp/chunk.tif', 'w')
chunk_file.write(str(chunk))
chunk_file.close()
Oh, that feels good. I know this is all riding on a bunch of kludges,
but it does show that XML-RPC *can* be a slick way to work with Zope.
I'm going to play with it for awhile.
--kyler
More information about the Zope
mailing list