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

Delta Between Two Patch Sets: Lib/xmlrpc/server.py

Issue 26404: socketserver context manager
Left Patch Set: Created 4 years ago
Right Patch Set: Created 4 years 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:
Right: Side by side diff | Download
« Doc/whatsnew/3.6.rst ('K') | « Lib/wsgiref/simple_server.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 r"""XML-RPC Servers. 1 r"""XML-RPC Servers.
2 2
3 This module can be used to create simple XML-RPC servers 3 This module can be used to create simple XML-RPC servers
4 by creating a server and either installing functions, a 4 by creating a server and either installing functions, a
5 class instance, or by extending the SimpleXMLRPCServer 5 class instance, or by extending the SimpleXMLRPCServer
6 class. 6 class.
7 7
8 It can also be used to handle XML-RPC requests in a CGI 8 It can also be used to handle XML-RPC requests in a CGI
9 environment using CGIXMLRPCRequestHandler. 9 environment using CGIXMLRPCRequestHandler.
10 10
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 964
965 class ExampleService: 965 class ExampleService:
966 def getData(self): 966 def getData(self):
967 return '42' 967 return '42'
968 968
969 class currentTime: 969 class currentTime:
970 @staticmethod 970 @staticmethod
971 def getCurrentTime(): 971 def getCurrentTime():
972 return datetime.datetime.now() 972 return datetime.datetime.now()
973 973
974 server = SimpleXMLRPCServer(("localhost", 8000)) 974 with SimpleXMLRPCServer(("localhost", 8000)) as server:
975 server.register_function(pow) 975 server.register_function(pow)
976 server.register_function(lambda x,y: x+y, 'add') 976 server.register_function(lambda x,y: x+y, 'add')
977 server.register_instance(ExampleService(), allow_dotted_names=True) 977 server.register_instance(ExampleService(), allow_dotted_names=True)
978 server.register_multicall_functions() 978 server.register_multicall_functions()
979 print('Serving XML-RPC on localhost port 8000') 979 print('Serving XML-RPC on localhost port 8000')
980 print('It is advisable to run this example server within a secure, closed ne twork.') 980 print('It is advisable to run this example server within a secure, close d network.')
981 try: 981 try:
982 server.serve_forever() 982 server.serve_forever()
983 except KeyboardInterrupt: 983 except KeyboardInterrupt:
984 print("\nKeyboard interrupt received, exiting.") 984 print("\nKeyboard interrupt received, exiting.")
985 server.server_close() 985 sys.exit(0)
986 sys.exit(0)
LEFTRIGHT

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