/usr/share/doc/python-twisted-web/howto/listings/xmlrpc-customized.py is in python-twisted-web 13.2.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | from twisted.web import xmlrpc, server
class EchoHandler:
def echo(self, x):
"""
Return all passed args
"""
return x
class AddHandler:
def add(self, a, b):
"""
Return sum of arguments.
"""
return a + b
class Example(xmlrpc.XMLRPC):
"""
An example of using you own policy to fetch the handler
"""
def __init__(self):
xmlrpc.XMLRPC.__init__(self)
self._addHandler = AddHandler()
self._echoHandler = EchoHandler()
#We keep a dict of all relevant
#procedure names and callable.
self._procedureToCallable = {
'add':self._addHandler.add,
'echo':self._echoHandler.echo
}
def lookupProcedure(self, procedurePath):
try:
return self._procedureToCallable[procedurePath]
except KeyError, e:
raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
"procedure %s not found" % procedurePath)
def listProcedures(self):
"""
Since we override lookupProcedure, its suggested to override
listProcedures too.
"""
return ['add', 'echo']
if __name__ == '__main__':
from twisted.internet import reactor
r = Example()
reactor.listenTCP(7080, server.Site(r))
reactor.run()
|