Right way to define methods to SimpleXMLRPCServer?

Skip Montanaro skip at pobox.com
Thu Sep 2 15:46:40 EDT 2004


I decided to use SimpleXMLRPCServer for an xml-rpc server.  As I understand
it, if I register an instance like so:

    myserver.register_instance(MyStuff())

then it will call MyStuff()._dispatch(name, *args, **kwds) to try and
execute the method.  Since _dispatch is generic, you can't really define a
more elaborate argument list.  I defined _dispatch like so:

    def _dispatch(self, name, *args, **kwds):
        print {"args": args, "kwds": kwds}
        try:
            meth = self._map[name]
        except KeyError:
            raise ValueError, "Invalid method: %s" % name
        else:
            return meth(self, *args, **kwds)

The **kwds parameter can probably be omitted since XML-RPC only supports
positional arguments.

When I call a method on the server with no args _dispatch is called, and the
server prints this:

    {'args': ((),), 'kwds': {}}

Seems to me like it has one nesting level too many in the args tuple.
Shouldn't it be ()?  Is this a bug or am I misinterpreting something?

Skip



More information about the Python-list mailing list