Using Python xmlrpclib to build XMLRPC clients for a server with variable RPC names
JPC
jpc at parallelthoughts.org
Sun Oct 9 14:35:36 EDT 2011
That was the information I was missing many thanks.
For the reference sake, a look through the source code indicates this
solution; prior to your message I just didn't understand it that well.
--
/jpc
On Sun, 2011-10-09 at 11:00 -0700, Chris Rebert wrote:
> On Sun, Oct 9, 2011 at 6:30 AM, John P. Crackett
> <jpc at parallelthoughts.org> wrote:
> > 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.
> <snip>
> > 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.
>
> Try using getattr():
> getattr(api, "foo-bar").callOne()
>
> For reference, getattr() satisfies the following identity:
> x.y === getattr(x, "y")
> except that getattr() does not itself enforce/require that its second
> argument be a valid Python identifier.
>
> Cheers,
> Chris
> --
> http://rebertia.com
More information about the Python-list
mailing list