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

Delta Between Two Patch Sets: Lib/wsgiref/simple_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
LEFTRIGHT
(no file at all)
1 """BaseHTTPServer that implements the Python WSGI protocol (PEP 3333) 1 """BaseHTTPServer that implements the Python WSGI protocol (PEP 3333)
2 2
3 This is both an example of how WSGI can be implemented, and a basis for running 3 This is both an example of how WSGI can be implemented, and a basis for running
4 simple web applications on a local machine, such as might be done when testing 4 simple web applications on a local machine, such as might be done when testing
5 or debugging an application. It has not been reviewed for security issues, 5 or debugging an application. It has not been reviewed for security issues,
6 however, and we strongly recommend that you use a "real" web server for 6 however, and we strongly recommend that you use a "real" web server for
7 production use. 7 production use.
8 8
9 For example usage, see the 'if __name__=="__main__"' block at the end of the 9 For example usage, see the 'if __name__=="__main__"' block at the end of the
10 module. See also the BaseHTTPServer module docs for other API information. 10 module. See also the BaseHTTPServer module docs for other API information.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 def make_server( 149 def make_server(
150 host, port, app, server_class=WSGIServer, handler_class=WSGIRequestHandler 150 host, port, app, server_class=WSGIServer, handler_class=WSGIRequestHandler
151 ): 151 ):
152 """Create a new WSGI server listening on `host` and `port` for `app`""" 152 """Create a new WSGI server listening on `host` and `port` for `app`"""
153 server = server_class((host, port), handler_class) 153 server = server_class((host, port), handler_class)
154 server.set_app(app) 154 server.set_app(app)
155 return server 155 return server
156 156
157 157
158 if __name__ == '__main__': 158 if __name__ == '__main__':
159 httpd = make_server('', 8000, demo_app) 159 with make_server('', 8000, demo_app) as httpd:
160 sa = httpd.socket.getsockname() 160 sa = httpd.socket.getsockname()
161 print("Serving HTTP on", sa[0], "port", sa[1], "...") 161 print("Serving HTTP on", sa[0], "port", sa[1], "...")
162 import webbrowser 162 import webbrowser
163 webbrowser.open('http://localhost:8000/xyz?abc') 163 webbrowser.open('http://localhost:8000/xyz?abc')
164 httpd.handle_request() # serve one request, then exit 164 httpd.handle_request() # serve one request, then exit
165 httpd.server_close()
LEFTRIGHT

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