diff options
author | Rasmus Andersson <rasmus@figma.com> | 2019-01-28 06:19:56 +0300 |
---|---|---|
committer | Rasmus Andersson <rasmus@figma.com> | 2019-01-28 06:19:56 +0300 |
commit | b931b7c72d00677310194261db8be472218c3fca (patch) | |
tree | e17659b69a5559397f5d7b15a06aad6efb9b67f0 /docs | |
parent | 6ac28e9940b74613de5f27afb3f6473e0b8951e3 (diff) | |
download | inter-b931b7c72d00677310194261db8be472218c3fca.tar.xz |
website helper script: python 3
Diffstat (limited to 'docs')
-rwxr-xr-x | docs/lab/serve.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/docs/lab/serve.py b/docs/lab/serve.py index 9dd5378ce..d78484f36 100755 --- a/docs/lab/serve.py +++ b/docs/lab/serve.py @@ -2,28 +2,32 @@ from __future__ import print_function, absolute_import import os, sys import signal -import SimpleHTTPServer import socket -import SocketServer +import http.server def sighandler(signum, frame): sys.stdout.write('\n') sys.stdout.flush() sys.exit(1) -class TCPServer(SocketServer.TCPServer): + +class HTTPServer(http.server.HTTPServer): + def __init__(self, addr): + http.server.HTTPServer.__init__( + self, addr, http.server.SimpleHTTPRequestHandler) + def server_bind(self): self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.socket.bind(self.server_address) + http.server.HTTPServer.server_bind(self) -os.chdir(os.path.dirname(os.path.abspath(__file__))) + +addr = ("localhost", 3002) # make ^C instantly exit program signal.signal(signal.SIGINT, sighandler) -httpd = TCPServer( - ("127.0.0.1", 3002), - SimpleHTTPServer.SimpleHTTPRequestHandler) +os.chdir(os.path.dirname(os.path.abspath(__file__))) -print("serving at http://localhost:3002/") +httpd = HTTPServer(addr) +print("serving at http://%s:%d/" % addr) httpd.serve_forever() |