1
"""Example of an XML-RPC server in Twisted.
3
To run the server, just run this file ("python xmlrpc.py").
5
An example session (assuming the server is running)::
8
>>> s = xmlrpclib.Server('http://localhost:7080/')
15
>>> s.echo("lala", 4, 3.4)
16
['lala', 4, 3.3999999999999999]
17
>>> s.echo("lala", 4, [1, 2])
22
from twisted.web import xmlrpc
23
from twisted.internet import defer
25
# This module is standard in Python 2.2, otherwise get it from
26
# http://www.pythonware.com/products/xmlrpc/
30
class Echoer(xmlrpc.XMLRPC):
31
"""An example object to be published.
33
Has five methods accessable by XML-RPC, 'echo', 'hello', 'defer',
34
'defer_fail' and 'fail.
37
def xmlrpc_echo(self, *args):
38
"""Return all passed args."""
41
def xmlrpc_hello(self):
42
"""Return 'hello, world'."""
43
return 'hello, world!'
45
def xmlrpc_defer(self):
46
"""Show how xmlrpc methods can return Deferred."""
47
return defer.succeed("hello")
49
def xmlrpc_defer_fail(self):
50
"""Show how xmlrpc methods can return failed Deferred."""
53
def xmlrpc_fail(self):
54
"""Show how we can return a failure code."""
55
return xmlrpclib.Fault(7, "Out of cheese.")
59
from twisted.internet import reactor
60
from twisted.web import server
62
reactor.listenTCP(7080, server.Site(r))
66
if __name__ == '__main__':