@@ -184,6 +184,70 @@ server::
184184 # Print list of available methods
185185 print(s.system.listMethods())
186186
187+ The following example included in `Lib/xmlrpc/server.py ` module shows a server
188+ allowing dotted names and registering a multicall function.
189+
190+ .. warning ::
191+
192+ Enabling the *allow_dotted_names * option allows intruders to access your
193+ module's global variables and may allow intruders to execute arbitrary code on
194+ your machine. Only use this example only within a secure, closed network.
195+
196+ ::
197+
198+ import datetime
199+
200+ class ExampleService:
201+ def getData(self):
202+ return '42'
203+
204+ class currentTime:
205+ @staticmethod
206+ def getCurrentTime():
207+ return datetime.datetime.now()
208+
209+ server = SimpleXMLRPCServer(("localhost", 8000))
210+ server.register_function(pow)
211+ server.register_function(lambda x,y: x+y, 'add')
212+ server.register_instance(ExampleService(), allow_dotted_names=True)
213+ server.register_multicall_functions()
214+ print('Serving XML-RPC on localhost port 8000')
215+ try:
216+ server.serve_forever()
217+ except KeyboardInterrupt:
218+ print("\nKeyboard interrupt received, exiting.")
219+ server.server_close()
220+ sys.exit(0)
221+
222+ This ExampleService demo can be invoked from the command line::
223+
224+ python -m xmlrpc.server
225+
226+
227+ The client that interacts with the above server is included in
228+ `Lib/xmlrpc/client.py `::
229+
230+ server = ServerProxy("http://localhost:8000")
231+
232+ try:
233+ print(server.currentTime.getCurrentTime())
234+ except Error as v:
235+ print("ERROR", v)
236+
237+ multi = MultiCall(server)
238+ multi.getData()
239+ multi.pow(2,9)
240+ multi.add(1,2)
241+ try:
242+ for response in multi():
243+ print(response)
244+ except Error as v:
245+ print("ERROR", v)
246+
247+ This client which interacts with the demo XMLRPC server can be invoked as::
248+
249+ python -m xmlrpc.client
250+
187251
188252CGIXMLRPCRequestHandler
189253-----------------------
0 commit comments