summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2014-01-13 00:06:58 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2014-01-13 00:06:58 (GMT)
commit939e2db48dc3bcb159486b599901b694d2d57f89 (patch)
treed45199046a3929f37eedc9ea370d0dd136fe0fdc /Doc
parent0abbe8c090707130fd492307b79cf5c608dedce0 (diff)
downloadcpython-939e2db48dc3bcb159486b599901b694d2d57f89.zip
cpython-939e2db48dc3bcb159486b599901b694d2d57f89.tar.gz
cpython-939e2db48dc3bcb159486b599901b694d2d57f89.tar.bz2
Issue #19082: Working xmlrpc.server and xmlrpc.client examples. Both in modules and in documentation.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/xmlrpc.server.rst64
1 files changed, 64 insertions, 0 deletions
diff --git a/Doc/library/xmlrpc.server.rst b/Doc/library/xmlrpc.server.rst
index 18fee2f..aca4f36 100644
--- a/Doc/library/xmlrpc.server.rst
+++ b/Doc/library/xmlrpc.server.rst
@@ -184,6 +184,70 @@ server::
# Print list of available methods
print(s.system.listMethods())
+The following example included in `Lib/xmlrpc/server.py` module shows a server
+allowing dotted names and registering a multicall function.
+
+.. warning::
+
+ Enabling the *allow_dotted_names* option allows intruders to access your
+ module's global variables and may allow intruders to execute arbitrary code on
+ your machine. Only use this example only within a secure, closed network.
+
+::
+
+ import datetime
+
+ class ExampleService:
+ def getData(self):
+ return '42'
+
+ class currentTime:
+ @staticmethod
+ def getCurrentTime():
+ return datetime.datetime.now()
+
+ server = SimpleXMLRPCServer(("localhost", 8000))
+ server.register_function(pow)
+ server.register_function(lambda x,y: x+y, 'add')
+ server.register_instance(ExampleService(), allow_dotted_names=True)
+ server.register_multicall_functions()
+ print('Serving XML-RPC on localhost port 8000')
+ try:
+ server.serve_forever()
+ except KeyboardInterrupt:
+ print("\nKeyboard interrupt received, exiting.")
+ server.server_close()
+ sys.exit(0)
+
+This ExampleService demo can be invoked from the command line::
+
+ python -m xmlrpc.server
+
+
+The client that interacts with the above server is included in
+`Lib/xmlrpc/client.py`::
+
+ server = ServerProxy("http://localhost:8000")
+
+ try:
+ print(server.currentTime.getCurrentTime())
+ except Error as v:
+ print("ERROR", v)
+
+ multi = MultiCall(server)
+ multi.getData()
+ multi.pow(2,9)
+ multi.add(1,2)
+ try:
+ for response in multi():
+ print(response)
+ except Error as v:
+ print("ERROR", v)
+
+This client which interacts with the demo XMLRPC server can be invoked as::
+
+ python -m xmlrpc.client
+
CGIXMLRPCRequestHandler
-----------------------