@@ -88,18 +88,49 @@ \subsection{SimpleXMLRPCServer Objects \label{simple-xmlrpc-servers}}
8888Example:
8989
9090\begin {verbatim }
91- class MyFuncs:
92- def div(self, x, y) : return x // y
93-
91+ from SimpleXMLRPCServer import SimpleXMLRPCServer
9492
93+ # Create server
9594server = SimpleXMLRPCServer(("localhost", 8000))
96- server.register_function(pow)
97- server.register_function(lambda x,y: x+y, 'add')
9895server.register_introspection_functions()
96+
97+ # Register pow() function; this will use the value of
98+ # pow.__name__ as the name, which is just 'pow'.
99+ server.register_function(pow)
100+
101+ # Register a function under a different name
102+ def adder_function(x,y):
103+ return x + y
104+ server.register_function(adder_function, 'add')
105+
106+ # Register an instance; all the methods of the instance are
107+ # published as XML-RPC methods (in this case, just 'div').
108+ class MyFuncs:
109+ def div(self, x, y):
110+ return x // y
111+
99112server.register_instance(MyFuncs())
113+
114+ # Run the server's main loop
100115server.serve_forever()
101116\end {verbatim }
102117
118+ The following client code will call the methods made available by
119+ the preceding server:
120+
121+ \begin {verbatim }
122+ import xmlrpclib
123+
124+ s = xmlrpclib.Server('http://localhost:8000')
125+ print s.pow(2,3) # Returns 2**3 = 8
126+ print s.add(2,3) # Returns 5
127+ print s.div(5,2) # Returns 5//2 = 2
128+
129+ # Print list of available methods
130+ print s.system.listMethods()
131+ \end {verbatim }
132+
133+
103134\subsection {CGIXMLRPCRequestHandler }
104135
105136The \class {CGIXMLRPCRequestHandler} class can be used to
0 commit comments