Using Python xmlrpclib to build XMLRPC clients for a server with variable RPC names

John P. Crackett jpc at parallelthoughts.org
Sun Oct 9 09:30:42 EDT 2011


I need to write prototype XMLRPC clients using xmlrpclib for a server
that has variable RPC names and I'd like to use Python as the
prototyping tool.  I've searched but can't find any relevant advice
online.  Any pointers would be gratefully received; details follow.

The server in question constructs method names dynamically using the
names of objects created by the client.  Since the xmlrpclib ServerProxy
object uses methods mirroring the RPC names I would need to be able to
do the following:

api = xmlrpclib.ServerProxy(serverURL)

api.createObject("foo")

api.foo.callOne()

where I don't know what "foo" will actually be in advance.

As an added complication, object names need to be concatenated using "-"
as a separator to form compound RPC names.  Following on from the
example above, this could lead to:

api = xmlrpclib.ServerProxy(serverURL)

api. createObjects("foo", "far")

api.foo-bar.callOne()

Where I don't know, again, what "foo" and "bar" will actually be in
advance.  "foo-bar" is obviously not a valid Python method name and this
is preventing me from hard-coding just to get a prototype going.

Is Python + xmlrpclib usable under these circumstances?  If so, a
pointer in the right direction would be appreciated.

Apologies if there's some glaringly obvious way of doing this that I
have overlooked - I'm new to Python.  Many thanks in anticipation.

-- 
/jpc







More information about the Python-list mailing list