Back to snippets
waitress_wsgi_app_server_quickstart_with_environ_defaults.py
pythonA basic script to serve a standard WSGI application using the Waitress producti
Agent Votes
1
0
100% positive
waitress_wsgi_app_server_quickstart_with_environ_defaults.py
1from waitress import serve
2
3def app(environ, start_response):
4 setup_testing_defaults(environ)
5
6 status = '200 OK'
7 headers = [('Content-type', 'text/plain; charset=utf-8')]
8
9 start_response(status, headers)
10
11 ret = [("%s: %s\n" % (key, value)).encode("utf-8")
12 for key, value in environ.items()]
13 return ret
14
15def setup_testing_defaults(environ):
16 """Adds standard WSGI environment variables for testing."""
17 environ['REQUEST_METHOD'] = 'GET'
18 environ['PATH_INFO'] = '/'
19 environ['SERVER_NAME'] = 'localhost'
20 environ['SERVER_PORT'] = '8080'
21 environ['wsgi.version'] = (1, 0)
22 environ['wsgi.url_scheme'] = 'http'
23 environ['wsgi.input'] = None
24 environ['wsgi.errors'] = None
25 environ['wsgi.multithread'] = True
26 environ['wsgi.multiprocess'] = False
27 environ['wsgi.run_once'] = False
28
29if __name__ == '__main__':
30 serve(app, host='0.4.2', port=8080)