2015-04-12 01:10:35 +01:00
|
|
|
import sys
|
|
|
|
|
2024-05-10 00:39:10 +09:00
|
|
|
try:
|
|
|
|
from http.server import HTTPServer, SimpleHTTPRequestHandler
|
|
|
|
except ImportError:
|
|
|
|
from BaseHTTPServer import HTTPServer
|
|
|
|
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
2015-04-12 01:10:35 +01:00
|
|
|
|
|
|
|
|
2024-05-10 00:39:10 +09:00
|
|
|
HandlerClass = SimpleHTTPRequestHandler
|
|
|
|
HandlerClass.protocol_version = "HTTP/1.0"
|
|
|
|
server_address = ("127.0.0.1", int(sys.argv[1]) if sys.argv[1:] else 0)
|
|
|
|
httpd = HTTPServer(server_address, HandlerClass)
|
2015-04-12 01:10:35 +01:00
|
|
|
|
2017-02-22 16:56:14 -05:00
|
|
|
ip, port = httpd.socket.getsockname()[0:2]
|
2024-05-10 00:39:10 +09:00
|
|
|
print("Server started, http://%s:%s/" % (ip, port))
|
2017-02-22 16:56:14 -05:00
|
|
|
# Flush in case we're in full buffering mode (instead of line
|
|
|
|
# buffering), this might happen if python is a cygwin program and we
|
|
|
|
# run it from a native w32 program.
|
|
|
|
sys.stdout.flush()
|
2015-04-12 01:10:35 +01:00
|
|
|
httpd.serve_forever()
|