Doc XML RPC Server Example : XML RPC « Network « Python Tutorial






from DocXMLRPCServer import DocXMLRPCServer, DocXMLRPCRequestHandler
from SocketServer import ThreadingMixIn
import time

class Stats:
    def getstats(self):
        return self.callstats

    def getruntime(self):
        return time.time() - self.starttime

    def failure(self):
        raise RuntimeError, "This function always raises an error."

class Math(Stats):
    def __init__(self):
        self.callstats = {'pow': 0, 'hex': 0}
        self.starttime = time.time()
        
    def pow(self, x, y):
        self.callstats['pow'] += 1    
        return pow(x, y)

    def hex(self, x):
        self.callstats['hex'] += 1    
        return "%x" % x

class ThreadingServer(ThreadingMixIn, DocXMLRPCServer):
    pass

serveraddr = ('', 8765)
srvr = ThreadingServer(serveraddr, DocXMLRPCRequestHandler)
srvr.set_server_title("Example Documentation")
srvr.set_server_name("Your name")
srvr.set_server_documentation("""Welcome to""")
srvr.register_instance(Math())
srvr.register_introspection_functions()
srvr.serve_forever()








21.23.XML RPC
21.23.1.Creating an XML-RPC Server
21.23.2.Creating an XML-RPC Client
21.23.3.XML-RPC Basic Client
21.23.4.XML-RPC Introspection Client
21.23.5.Doc XML RPC Server Example
21.23.6.Simple XML RPC Server Example with functions
21.23.7.Simple XML RPC Server Basic Example
21.23.8.XML-RPC Basic Test Client
21.23.9.CGI Example