Skip to content

Commit c7ff8e1

Browse files
authored
examples: update start_local_server to python3 (#385)
Python 2 EOL'd in January 2020, and generally is vanishing from Linux distros. The code is simple enough that a 2to3 pass is sufficient to update it to a working state on modern Python. A pass through the “black” tool was also used just to maintain a standard style.
1 parent 979b46f commit c7ff8e1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

examples/start_local_server.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

3-
import BaseHTTPServer, SimpleHTTPServer, os
3+
import http.server
4+
import os
45

56
# We need to host from the root because we are going to be requesting files inside of dist
6-
os.chdir('../')
7-
port=8081
8-
print "Running on port %d" % port
7+
os.chdir("../")
8+
port = 8081
9+
print("Running on port %d" % port)
910

10-
SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map['.wasm'] = 'application/wasm'
11+
http.server.SimpleHTTPRequestHandler.extensions_map[".wasm"] = "application/wasm"
1112

12-
httpd = BaseHTTPServer.HTTPServer(('localhost', port), SimpleHTTPServer.SimpleHTTPRequestHandler)
13+
httpd = http.server.HTTPServer(
14+
("localhost", port), http.server.SimpleHTTPRequestHandler
15+
)
1316

14-
print "Mapping \".wasm\" to \"%s\"" % SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map['.wasm']
17+
print(
18+
'Mapping ".wasm" to "%s"'
19+
% http.server.SimpleHTTPRequestHandler.extensions_map[".wasm"]
20+
)
1521
httpd.serve_forever()

0 commit comments

Comments
 (0)