[PATCH] D36624: [opt-viewer] Decode HTML bytes for Python 3

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 10:42:13 PDT 2017

modocache created this revision.

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`.



Index: tools/opt-viewer/opt-viewer.py
--- tools/opt-viewer/opt-viewer.py
+++ tools/opt-viewer/opt-viewer.py
@@ -59,7 +59,10 @@
     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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36624.110768.patch
Type: text/x-patch
Size: 637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170811/dc304497/attachment.bin>

More information about the llvm-commits mailing list