Index: bindings/python/tests/cindex/test_translation_unit.py =================================================================== --- bindings/python/tests/cindex/test_translation_unit.py +++ bindings/python/tests/cindex/test_translation_unit.py @@ -93,12 +93,9 @@ self.assertEqual(spellings[-1], 'y') def test_unsaved_files_2(self): - try: - from StringIO import StringIO - except: - from io import StringIO + from io import BytesIO tu = TranslationUnit.from_source('fake.c', unsaved_files = [ - ('fake.c', StringIO('int x;'))]) + ('fake.c', BytesIO('int x;'))]) spellings = [c.spelling for c in tu.cursor.get_children()] self.assertEqual(spellings[-1], 'x') Index: tools/clang-format/clang-format-diff.py =================================================================== --- tools/clang-format/clang-format-diff.py +++ tools/clang-format/clang-format-diff.py @@ -27,10 +27,8 @@ import re import subprocess import sys -try: - from StringIO import StringIO -except ImportError: - from io import StringIO + +from io import BytesIO def main(): @@ -114,7 +112,7 @@ if not args.i: with open(filename) as f: code = f.readlines() - formatted_code = StringIO(stdout).readlines() + formatted_code = BytesIO(stdout).readlines() diff = difflib.unified_diff(code, formatted_code, filename, filename, '(before formatting)', '(after formatting)') Index: tools/scan-view/share/ScanView.py =================================================================== --- tools/scan-view/share/ScanView.py +++ tools/scan-view/share/ScanView.py @@ -7,7 +7,9 @@ import sys import urllib, urlparse import posixpath -import StringIO + +from io import StringIO, BytesIO + import re import shutil import threading @@ -108,10 +110,10 @@ except Reporter.ReportFailure as e: self.status = e.value except Exception as e: - s = StringIO.StringIO() + s = StringIO() import traceback print >>s,'Unhandled Exception
'
-            traceback.print_exc(e,file=s)
+            traceback.print_exc(file=s)
             print >>s,'
' self.status = s.getvalue() @@ -266,12 +268,12 @@ def handle_exception(self, exc): import traceback - s = StringIO.StringIO() + s = StringIO() print >>s, "INTERNAL ERROR\n" - traceback.print_exc(exc, s) + traceback.print_exc(file=s) f = self.send_string(s.getvalue(), 'text/plain') if f: - self.copyfile(f, self.wfile) + self.copyfile(BytesIO(f.getvalue().encode()), self.wfile) f.close() def get_scalar_field(self, name): @@ -730,15 +732,16 @@ 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.