Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Delta Between Two Patch Sets: Doc/library/xmlrpc.server.rst

Issue 26404: socketserver context manager
Left Patch Set: Created 4 years, 1 month ago
Right Patch Set: Created 4 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 :mod:`xmlrpc.server` --- Basic XML-RPC servers 1 :mod:`xmlrpc.server` --- Basic XML-RPC servers
2 ============================================== 2 ==============================================
3 3
4 .. module:: xmlrpc.server 4 .. module:: xmlrpc.server
5 :synopsis: Basic XML-RPC server implementations. 5 :synopsis: Basic XML-RPC server implementations.
6 .. moduleauthor:: Brian Quinlan <brianq@activestate.com> 6 .. moduleauthor:: Brian Quinlan <brianq@activestate.com>
7 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> 7 .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
8 8
9 **Source code:** :source:`Lib/xmlrpc/server.py` 9 **Source code:** :source:`Lib/xmlrpc/server.py`
10 10
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 from xmlrpc.server import SimpleXMLRPCServer 142 from xmlrpc.server import SimpleXMLRPCServer
143 from xmlrpc.server import SimpleXMLRPCRequestHandler 143 from xmlrpc.server import SimpleXMLRPCRequestHandler
144 144
145 # Restrict to a particular path. 145 # Restrict to a particular path.
146 class RequestHandler(SimpleXMLRPCRequestHandler): 146 class RequestHandler(SimpleXMLRPCRequestHandler):
147 rpc_paths = ('/RPC2',) 147 rpc_paths = ('/RPC2',)
148 148
149 # Create server 149 # Create server
150 with SimpleXMLRPCServer(("localhost", 8000), 150 with SimpleXMLRPCServer(("localhost", 8000),
151 requestHandler=RequestHandler) as server 151 requestHandler=RequestHandler) as server:
Martin Panter 2016/02/24 02:55:12 missing colon (... as server:)
palaviv 2016/02/24 10:05:34 Done.
152 server.register_introspection_functions() 152 server.register_introspection_functions()
153 153
154 # Register pow() function; this will use the value of 154 # Register pow() function; this will use the value of
155 # pow.__name__ as the name, which is just 'pow'. 155 # pow.__name__ as the name, which is just 'pow'.
156 server.register_function(pow) 156 server.register_function(pow)
157 157
158 # Register a function under a different name 158 # Register a function under a different name
159 def adder_function(x,y): 159 def adder_function(x,y):
160 return x + y 160 return x + y
161 server.register_function(adder_function, 'add') 161 server.register_function(adder_function, 'add')
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 @staticmethod 205 @staticmethod
206 def getCurrentTime(): 206 def getCurrentTime():
207 return datetime.datetime.now() 207 return datetime.datetime.now()
208 208
209 with SimpleXMLRPCServer(("localhost", 8000)) as server: 209 with SimpleXMLRPCServer(("localhost", 8000)) as server:
210 server.register_function(pow) 210 server.register_function(pow)
211 server.register_function(lambda x,y: x+y, 'add') 211 server.register_function(lambda x,y: x+y, 'add')
212 server.register_instance(ExampleService(), allow_dotted_names=True) 212 server.register_instance(ExampleService(), allow_dotted_names=True)
213 server.register_multicall_functions() 213 server.register_multicall_functions()
214 print('Serving XML-RPC on localhost port 8000') 214 print('Serving XML-RPC on localhost port 8000')
215 print('It is advisable to run this example server within a secure, close d network.')
Martin Panter 2016/02/24 02:55:12 I think this just dilutes the example. It is only
palaviv 2016/02/24 10:05:34 Done.
216 try: 215 try:
217 server.serve_forever() 216 server.serve_forever()
218 except KeyboardInterrupt: 217 except KeyboardInterrupt:
219 print("\nKeyboard interrupt received, exiting.") 218 print("\nKeyboard interrupt received, exiting.")
220 sys.exit(0) 219 sys.exit(0)
221 220
222 This ExampleService demo can be invoked from the command line:: 221 This ExampleService demo can be invoked from the command line::
223 222
224 python -m xmlrpc.server 223 python -m xmlrpc.server
225 224
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 .. method:: DocCGIXMLRPCRequestHandler.set_server_name(server_name) 392 .. method:: DocCGIXMLRPCRequestHandler.set_server_name(server_name)
394 393
395 Set the name used in the generated HTML documentation. This name will appear at 394 Set the name used in the generated HTML documentation. This name will appear at
396 the top of the generated documentation inside a "h1" element. 395 the top of the generated documentation inside a "h1" element.
397 396
398 397
399 .. method:: DocCGIXMLRPCRequestHandler.set_server_documentation(server_documenta tion) 398 .. method:: DocCGIXMLRPCRequestHandler.set_server_documentation(server_documenta tion)
400 399
401 Set the description used in the generated HTML documentation. This descriptio n 400 Set the description used in the generated HTML documentation. This descriptio n
402 will appear as a paragraph, below the server name, in the documentation. 401 will appear as a paragraph, below the server name, in the documentation.
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+