Keyword args to SimpleXMLRPCServer
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Dec 17 22:38:07 EST 2007
En Mon, 17 Dec 2007 21:13:32 -0300, Sean DiZazzo <half.italian at gmail.com>
escribió:
> Why is the following not working? Is there any way to get keyword
> arguments working with exposed XMLRPC functions?
>
> ~~~~~~~~~~~~~~~~ server.py
> import SocketServer
> from SimpleXMLRPCServer import
> SimpleXMLRPCServer,SimpleXMLRPCRequestHandler
>
> # Threaded mix-in
> class
> AsyncXMLRPCServer(SocketServer.ThreadingMixIn,SimpleXMLRPCServer):
> pass
>
> class XMLFunctions(object):
> def returnArgs(*args, **kwargs):
> return kwargs.items()
You forget the self argument. But this is not the problem. XMLRPC does not
allow passing parameters by name, only positional parameters. See
http://www.xmlrpc.com/spec:
"If the procedure call has parameters, the <methodCall> must contain a
<params> sub-item. The <params> sub-item can contain any number of
<param>s, each of which has a <value>. "
Parameters have no <name>, just a <value>, so you can only use positional
parameters. But you can simulate keyword arguments by collecting them in a
dictionary and passing that dictionary as an argument instead.
(server side)
def returnArgs(self, x, y, other={}):
return x, y, other
(client side)
print server.returnArgs("xvalue", "yvalue", dict(foo=123, bar=234,
baz=345))
--
Gabriel Genellina
More information about the Python-list
mailing list