diff options
author | Serge Guelton <sguelton@quarkslab.com> | 2019-01-03 14:26:56 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@quarkslab.com> | 2019-01-03 14:26:56 +0000 |
commit | f886c03e47092d1fad1998df0ddfcffa9e8c3d48 (patch) | |
tree | 98f9c815fbac0aea0362bfd246e40b8a54796871 /clang/tools/scan-view/share/ScanView.py | |
parent | d23e9bc5af0220c049d841acf219e2158f7004b8 (diff) | |
download | bcm5719-llvm-f886c03e47092d1fad1998df0ddfcffa9e8c3d48.tar.gz bcm5719-llvm-f886c03e47092d1fad1998df0ddfcffa9e8c3d48.zip |
Portable Python script across Python version
StringIO is obsoleted in Python3, replaced by io.BytesIO or io.StringIO depending on the use.
Differential Revision: https://reviews.llvm.org/D55196
llvm-svn: 350318
Diffstat (limited to 'clang/tools/scan-view/share/ScanView.py')
-rw-r--r-- | clang/tools/scan-view/share/ScanView.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/tools/scan-view/share/ScanView.py b/clang/tools/scan-view/share/ScanView.py index da30f361874..c40366b2e84 100644 --- a/clang/tools/scan-view/share/ScanView.py +++ b/clang/tools/scan-view/share/ScanView.py @@ -13,7 +13,12 @@ except ImportError: from urllib.parse import urlparse, unquote import posixpath -import StringIO + +if sys.version_info.major >= 3: + from io import StringIO, BytesIO +else: + from io import BytesIO, BytesIO as StringIO + import re import shutil import threading @@ -117,7 +122,7 @@ class ReporterThread(threading.Thread): except Reporter.ReportFailure as e: self.status = e.value except Exception as e: - s = StringIO.StringIO() + s = StringIO() import traceback print('<b>Unhandled Exception</b><br><pre>', file=s) traceback.print_exc(file=s) @@ -275,7 +280,7 @@ class ScanViewRequestHandler(SimpleHTTPRequestHandler): def handle_exception(self, exc): import traceback - s = StringIO.StringIO() + s = StringIO() print("INTERNAL ERROR\n", file=s) traceback.print_exc(file=s) f = self.send_string(s.getvalue(), 'text/plain') @@ -739,15 +744,16 @@ File Bug</h3> return f def send_string(self, s, ctype='text/html', headers=True, mtime=None): + encoded_s = s.encode() if headers: self.send_response(200) self.send_header("Content-type", ctype) - self.send_header("Content-Length", str(len(s))) + self.send_header("Content-Length", str(len(encoded_s))) if mtime is None: mtime = self.dynamic_mtime self.send_header("Last-Modified", self.date_time_string(mtime)) self.end_headers() - return StringIO.StringIO(s) + return BytesIO(encoded_s) def send_patched_file(self, path, ctype): # Allow a very limited set of variables. This is pretty gross. |