summaryrefslogtreecommitdiff
path: root/Lib/xmlrpc
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2014-01-12 16:06:58 -0800
committerSenthil Kumaran <senthil@uthcode.com>2014-01-12 16:06:58 -0800
commit939e2db48dc3bcb159486b599901b694d2d57f89 (patch)
treed45199046a3929f37eedc9ea370d0dd136fe0fdc /Lib/xmlrpc
parent0abbe8c090707130fd492307b79cf5c608dedce0 (diff)
downloadcpython-git-939e2db48dc3bcb159486b599901b694d2d57f89.tar.gz
Issue #19082: Working xmlrpc.server and xmlrpc.client examples. Both in modules and in documentation.
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r--Lib/xmlrpc/client.py10
-rw-r--r--Lib/xmlrpc/server.py14
2 files changed, 19 insertions, 5 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
index 0f9522aa3c..461c3005ff 100644
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -1460,18 +1460,18 @@ if __name__ == "__main__":
# simple test program (from the XML-RPC specification)
- # server = ServerProxy("http://localhost:8000") # local server
- server = ServerProxy("http://time.xmlrpc.com/RPC2")
+ # local server, available from Lib/xmlrpc/server.py
+ server = ServerProxy("http://localhost:8000")
try:
print(server.currentTime.getCurrentTime())
except Error as v:
print("ERROR", v)
- # The server at xmlrpc.com doesn't seem to support multicall anymore.
multi = MultiCall(server)
- multi.currentTime.getCurrentTime()
- multi.currentTime.getCurrentTime()
+ multi.getData()
+ multi.pow(2,9)
+ multi.add(1,2)
try:
for response in multi():
print(response)
diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py
index 78ca4e0a4a..d27bf5a177 100644
--- a/Lib/xmlrpc/server.py
+++ b/Lib/xmlrpc/server.py
@@ -967,10 +967,24 @@ class DocCGIXMLRPCRequestHandler( CGIXMLRPCRequestHandler,
if __name__ == '__main__':
+ 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')
+ print('It is advisable to run this example server within a secure, closed network.')
try:
server.serve_forever()
except KeyboardInterrupt: