summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libsimplexmlrpc.tex
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2004-12-01 18:34:11 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2004-12-01 18:34:11 (GMT)
commitab807e8a0d0ac6978c61a52036eb742fef3dad13 (patch)
tree6e1559469a3faa73f039a2276e651ebf9ec532e2 /Doc/lib/libsimplexmlrpc.tex
parent9cc5cb7c4b866f255c73185b2ec4648d532b9108 (diff)
downloadcpython-ab807e8a0d0ac6978c61a52036eb742fef3dad13.zip
cpython-ab807e8a0d0ac6978c61a52036eb742fef3dad13.tar.gz
cpython-ab807e8a0d0ac6978c61a52036eb742fef3dad13.tar.bz2
Make the example server code clearer; add the corresponding example client. [Bugfix candidate]
Diffstat (limited to 'Doc/lib/libsimplexmlrpc.tex')
-rw-r--r--Doc/lib/libsimplexmlrpc.tex41
1 files changed, 36 insertions, 5 deletions
diff --git a/Doc/lib/libsimplexmlrpc.tex b/Doc/lib/libsimplexmlrpc.tex
index 89db62b..0170c1a 100644
--- a/Doc/lib/libsimplexmlrpc.tex
+++ b/Doc/lib/libsimplexmlrpc.tex
@@ -88,18 +88,49 @@ simple, stand alone XML-RPC servers.
Example:
\begin{verbatim}
-class MyFuncs:
- def div(self, x, y) : return x // y
-
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+# Create server
server = SimpleXMLRPCServer(("localhost", 8000))
-server.register_function(pow)
-server.register_function(lambda x,y: x+y, 'add')
server.register_introspection_functions()
+
+# Register pow() function; this will use the value of
+# pow.__name__ as the name, which is just 'pow'.
+server.register_function(pow)
+
+# Register a function under a different name
+def adder_function(x,y):
+ return x + y
+server.register_function(adder_function, 'add')
+
+# Register an instance; all the methods of the instance are
+# published as XML-RPC methods (in this case, just 'div').
+class MyFuncs:
+ def div(self, x, y):
+ return x // y
+
server.register_instance(MyFuncs())
+
+# Run the server's main loop
server.serve_forever()
\end{verbatim}
+The following client code will call the methods made available by
+the preceding server:
+
+\begin{verbatim}
+import xmlrpclib
+
+s = xmlrpclib.Server('http://localhost:8000')
+print s.pow(2,3) # Returns 2**3 = 8
+print s.add(2,3) # Returns 5
+print s.div(5,2) # Returns 5//2 = 2
+
+# Print list of available methods
+print s.system.listMethods()
+\end{verbatim}
+
+
\subsection{CGIXMLRPCRequestHandler}
The \class{CGIXMLRPCRequestHandler} class can be used to