]> granicus.if.org Git - llvm/commitdiff
[opt-viewer] Decode HTML bytes for Python 3
authorBrian Gesiak <modocache@gmail.com>
Fri, 11 Aug 2017 18:05:26 +0000 (18:05 +0000)
committerBrian Gesiak <modocache@gmail.com>
Fri, 11 Aug 2017 18:05:26 +0000 (18:05 +0000)
Summary:
When using Python 3, `pygments.highlight()` returns a `bytes` object, not
a `str`, causing the call to `str.replace` on the following line to fail
with a runtime exception:
`TypeError: 'str' does not support the buffer interface`. Decode the
bytes into a string in order to fix the exception.

Test Plan:
Run `opt-viewer.py` with Python 3.4, and confirm no runtime error occurs
when calling `str.replace`.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D36624

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310741 91177308-0d34-0410-b5e6-96231b3b80d8

tools/opt-viewer/opt-viewer.py

index b5c7c09547a99bfc394582c181d5dd76180e1e5b..ceb9e22586c8ab8b4c3f35e4c4732117330e9c40 100755 (executable)
@@ -59,7 +59,10 @@ class SourceFileRenderer:
 
     def render_source_lines(self, stream, line_remarks):
         file_text = stream.read()
-        html_highlighted = highlight(file_text, self.cpp_lexer, self.html_formatter)
+        html_highlighted = highlight(
+            file_text,
+            self.cpp_lexer,
+            self.html_formatter).decode('utf-8')
 
         # Take off the header and footer, these must be
         #   reapplied line-wise, within the page structure