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

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

Issue 26404: socketserver context manager
Left Patch Set: Created 3 years, 12 months ago
Right Patch Set: Created 3 years, 11 months 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 """HTTP server classes. 1 """HTTP server classes.
2 2
3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see 3 Note: BaseHTTPRequestHandler doesn't implement any HTTP request; see
4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST, 4 SimpleHTTPRequestHandler for simple implementations of GET, HEAD and POST,
5 and CGIHTTPRequestHandler for CGI scripts. 5 and CGIHTTPRequestHandler for CGI scripts.
6 6
7 It does, however, optionally implement HTTP/1.1 persistent connections, 7 It does, however, optionally implement HTTP/1.1 persistent connections,
8 as of version 0.3. 8 as of version 0.3.
9 9
10 Notes on CGIHTTPRequestHandler 10 Notes on CGIHTTPRequestHandler
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 ServerClass=HTTPServer, protocol="HTTP/1.0", port=8000, bind=""): 1168 ServerClass=HTTPServer, protocol="HTTP/1.0", port=8000, bind=""):
1169 """Test the HTTP request handler class. 1169 """Test the HTTP request handler class.
1170 1170
1171 This runs an HTTP server on port 8000 (or the port argument). 1171 This runs an HTTP server on port 8000 (or the port argument).
1172 1172
1173 """ 1173 """
1174 server_address = (bind, port) 1174 server_address = (bind, port)
1175 1175
1176 HandlerClass.protocol_version = protocol 1176 HandlerClass.protocol_version = protocol
1177 with ServerClass(server_address, HandlerClass) as httpd: 1177 with ServerClass(server_address, HandlerClass) as httpd:
1178
Martin Panter 2016/02/24 02:55:12 Also I think this blank line could be dropped
palaviv 2016/02/24 10:05:34 Done.
1179 sa = httpd.socket.getsockname() 1178 sa = httpd.socket.getsockname()
1180 print("Serving HTTP on", sa[0], "port", sa[1], "...") 1179 print("Serving HTTP on", sa[0], "port", sa[1], "...")
1181 try: 1180 try:
1182 httpd.serve_forever() 1181 httpd.serve_forever()
1183 except KeyboardInterrupt: 1182 except KeyboardInterrupt:
1184 print("\nKeyboard interrupt received, exiting.") 1183 print("\nKeyboard interrupt received, exiting.")
1185 sys.exit(0) 1184 sys.exit(0)
1186 1185
1187 if __name__ == '__main__': 1186 if __name__ == '__main__':
1188 parser = argparse.ArgumentParser() 1187 parser = argparse.ArgumentParser()
1189 parser.add_argument('--cgi', action='store_true', 1188 parser.add_argument('--cgi', action='store_true',
1190 help='Run as CGI Server') 1189 help='Run as CGI Server')
1191 parser.add_argument('--bind', '-b', default='', metavar='ADDRESS', 1190 parser.add_argument('--bind', '-b', default='', metavar='ADDRESS',
1192 help='Specify alternate bind address ' 1191 help='Specify alternate bind address '
1193 '[default: all interfaces]') 1192 '[default: all interfaces]')
1194 parser.add_argument('port', action='store', 1193 parser.add_argument('port', action='store',
1195 default=8000, type=int, 1194 default=8000, type=int,
1196 nargs='?', 1195 nargs='?',
1197 help='Specify alternate port [default: 8000]') 1196 help='Specify alternate port [default: 8000]')
1198 args = parser.parse_args() 1197 args = parser.parse_args()
1199 if args.cgi: 1198 if args.cgi:
1200 handler_class = CGIHTTPRequestHandler 1199 handler_class = CGIHTTPRequestHandler
1201 else: 1200 else:
1202 handler_class = SimpleHTTPRequestHandler 1201 handler_class = SimpleHTTPRequestHandler
1203 test(HandlerClass=handler_class, port=args.port, bind=args.bind) 1202 test(HandlerClass=handler_class, port=args.port, bind=args.bind)
LEFTRIGHT

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