forked from philippschmitt/interaktionsgestaltung.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webserver.py
38 lines (28 loc) · 831 Bytes
/
webserver.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
# http://localhost:8000/
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import os
import webbrowser
def main(*argv):
if not argv: argv = sys.argv
folder,f = os.path.split(__file__)
if not folder == '':
os.chdir(folder)
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
DefaultPort = 8000
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = DefaultPort
server_address = ('127.0.0.1', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
webbrowser.open("http://localhost:"+str(port))
httpd.serve_forever()
if __name__ == '__main__':
main()