You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2019/06/24 17:24:49 UTC
[mynewt-site] branch master updated: Update serve.py script for
Python3 compat
This is an automated email from the ASF dual-hosted git repository.
utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-site.git
The following commit(s) were added to refs/heads/master by this push:
new 0765d0d Update serve.py script for Python3 compat
0765d0d is described below
commit 0765d0df24d64db8acdf862d4e5121a24f6e50e9
Author: Fabio Utzig <ut...@apache.org>
AuthorDate: Fri Jun 14 15:32:15 2019 -0300
Update serve.py script for Python3 compat
---
serve.py | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/serve.py b/serve.py
index 9853ed5..dc9da02 100755
--- a/serve.py
+++ b/serve.py
@@ -2,8 +2,14 @@
import os
import sys
-import SimpleHTTPServer
-import SocketServer
+
+is_python3 = sys.version_info[0] >= 3
+
+if is_python3:
+ from http.server import HTTPServer, SimpleHTTPRequestHandler
+else:
+ import SimpleHTTPServer
+ import SocketServer
os.chdir('site')
@@ -12,8 +18,13 @@ if sys.argv[1:]:
else:
port = 8000
-handler = SimpleHTTPServer.SimpleHTTPRequestHandler
-httpd = SocketServer.TCPServer(('127.0.0.1', port), handler)
+server_address = ('', 8000)
+print("serving at port {}".format(port))
+
+if is_python3:
+ httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
+else:
+ handler = SimpleHTTPServer.SimpleHTTPRequestHandler
+ httpd = SocketServer.TCPServer(('127.0.0.1', port), handler)
-print "serving at port", port
httpd.serve_forever()