forked from jon-jacky/PyModel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsgirunner.py
executable file
·52 lines (40 loc) · 1.29 KB
/
wsgirunner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
"""
Simple web server for WSGI applications
using only Python standard libraries
"""
import sys
from wsgiref import simple_server
from optparse import OptionParser
usage = """python wsgirunner.py [options] arg
where arg is the name of a Python module arg.py
which contains a WSGI-compliant web application.
For example:
python wsgirunner.py -p 8080 wsgidemo
If wsgirunner.py is in a directory that is on the
execution path, this can be shortened to
wsgirunner.py -p 8080 wsgidemo
"""
parser = OptionParser(usage=usage)
def parse_args():
parser.add_option('-p', '--port', type='int', default=8000,
help='Port where server listens, default 8000')
return parser.parse_args()
def print_help():
parser.print_help() # must have at least one arg, not optional
def main():
(options, args) = parse_args()
if not args:
print_help()
exit()
app_module = args[0]
app = __import__(app_module)
application = app.application
print("Running %s at http://localhost:%s/" \
% (app_module, options.port))
httpd = simple_server.WSGIServer(('', options.port),
simple_server.WSGIRequestHandler)
httpd.set_app(application)
httpd.serve_forever()
if __name__ == '__main__':
main()