2018-01-08 20:38:03 -05:00
|
|
|
#!/usr/bin/env python
|
2019-05-31 21:08:52 -04:00
|
|
|
"""A version of Python's SimpleHTTPServer that flushes its output."""
|
2018-01-08 20:38:03 -05:00
|
|
|
import sys
|
2019-12-09 15:50:20 -05:00
|
|
|
|
2019-05-31 21:08:52 -04:00
|
|
|
try:
|
|
|
|
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
|
|
|
except ImportError:
|
|
|
|
|
from BaseHTTPServer import HTTPServer
|
|
|
|
|
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
2018-01-08 20:38:03 -05:00
|
|
|
|
|
|
|
|
def serve_forever(port=0):
|
|
|
|
|
"""Spins up an HTTP server on all interfaces and the given port.
|
|
|
|
|
|
|
|
|
|
A message is printed to stdout specifying the address and port being used
|
|
|
|
|
by the server.
|
|
|
|
|
|
|
|
|
|
:param int port: port number to use.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
server = HTTPServer(('', port), SimpleHTTPRequestHandler)
|
2018-03-14 12:37:29 -04:00
|
|
|
print('Serving HTTP on {0} port {1} ...'.format(*server.server_address))
|
2018-01-08 20:38:03 -05:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
server.serve_forever()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
kwargs = {}
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
kwargs['port'] = int(sys.argv[1])
|
|
|
|
|
serve_forever(**kwargs)
|