XML-RPC Question
Brian Quinlan
brian at sweetapp.com
Thu Mar 14 15:07:26 EST 2002
Jesper Olsen wrote:
> Setting up a server goes something like this:
>
> from SimpleXMLRPCServer import *
>
> class MyClass:
> def helloWorld(self):
> return "Hello World!"
>
> def echo(self, text):
> return text
>
> myob=MyClass()
>
> server=SimpleXMLRPCServer(("",50000))
> server.register_function(myob.helloWorld)
> server.serve_forever()
While that usage is correct, it is a bit odd. There are two other ways
that my might express this:
# No need for a class
def helloWorld(self):
return "Hello World!"
server.register_function(helloWorld)
# Exports all of the methods in the class
class MyClass:
def helloWorld(self):
return "Hello World!"
def echo(self, text):
return text
server.register_instance(MyClass())
Of course I didn't test the above in any way :-)
> Is there something wrong here, or does SimpleXMLRPCServer, not support
> the listMethods() call?
I'm in the process of reorganizing it a bit, but here is a
SimpleXMLRPCServer implementation that does what you want:
http://www.sweetapp.com/xmlrpc/
# Example
server = SimpleXMLRPCServer(("",50000))
# Or use the following construction if you want the server to also
# serve HTML documentation on that port (cool, eh?)
server = SimpleXMLRPCServer(("localhost", 8000),
SimpleXMLRPCAndDocsRequestHandler)
# Make system.listMethods and system.methodHelp work
server.register_introspection_functions()
# Make system.multicall work
server.register_multicall_functions()
# Install your own methods/instance here...
server.serve_forever()
This, or something like this, should make it into Python 2.3.
Cheers,
Brian
More information about the Python-list
mailing list