diff options
author | Serge Guelton <sguelton@quarkslab.com> | 2018-12-03 20:26:51 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@quarkslab.com> | 2018-12-03 20:26:51 +0000 |
commit | 12005cd649feb066e45fb688b80e8c158a44d9bb (patch) | |
tree | 874d9ec7033f8f81fb3fc00675c95c11d513c357 /tools | |
parent | efecfbc6a83b5362737635178d5aa3d42fb279eb (diff) | |
download | clang-12005cd649feb066e45fb688b80e8c158a44d9bb.tar.gz |
Portable Python script across Python version
Workaround naming and hierarchy changes in BaseHTTPServer and SimpleHTTPServer module.
Differential Revision: https://reviews.llvm.org/D55203
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348184 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/scan-view/share/ScanView.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/tools/scan-view/share/ScanView.py b/tools/scan-view/share/ScanView.py index 95ecfe262e..b489589d00 100644 --- a/tools/scan-view/share/ScanView.py +++ b/tools/scan-view/share/ScanView.py @@ -1,5 +1,8 @@ -import BaseHTTPServer -import SimpleHTTPServer +try: + from http.server import HTTPServer, SimpleHTTPRequestHandler +except ImportError: + from BaseHTTPServer import HTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler import os import sys import urllib, urlparse @@ -112,9 +115,9 @@ class ReporterThread(threading.Thread): print >>s,'</pre>' self.status = s.getvalue() -class ScanViewServer(BaseHTTPServer.HTTPServer): +class ScanViewServer(HTTPServer): def __init__(self, address, handler, root, reporters, options): - BaseHTTPServer.HTTPServer.__init__(self, address, handler) + HTTPServer.__init__(self, address, handler) self.root = root self.reporters = reporters self.options = options @@ -170,7 +173,7 @@ class ScanViewServer(BaseHTTPServer.HTTPServer): if self.options.autoReload: import ScanView self.RequestHandlerClass = reload(ScanView).ScanViewRequestHandler - BaseHTTPServer.HTTPServer.finish_request(self, request, client_address) + HTTPServer.finish_request(self, request, client_address) def handle_error(self, request, client_address): # Ignore socket errors @@ -179,7 +182,7 @@ class ScanViewServer(BaseHTTPServer.HTTPServer): if self.options.debug > 1: print >>sys.stderr, "%s: SERVER: ignored socket error." % (sys.argv[0],) return - BaseHTTPServer.HTTPServer.handle_error(self, request, client_address) + HTTPServer.handle_error(self, request, client_address) # Borrowed from Quixote, with simplifications. def parse_query(qs, fields=None): @@ -200,19 +203,19 @@ def parse_query(qs, fields=None): item.append(value) return fields -class ScanViewRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class ScanViewRequestHandler(SimpleHTTPRequestHandler): server_version = "ScanViewServer/" + __version__ dynamic_mtime = time.time() def do_HEAD(self): try: - SimpleHTTPServer.SimpleHTTPRequestHandler.do_HEAD(self) + SimpleHTTPRequestHandler.do_HEAD(self) except Exception as e: self.handle_exception(e) def do_GET(self): try: - SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + SimpleHTTPRequestHandler.do_GET(self) except Exception as e: self.handle_exception(e) |