[PATCH] D38289: [opt-viewer] Don't Decode HTML bytes for Python 2

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 12:34:28 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL315350: [opt-viewer] Don't Decode HTML bytes for Python 2 (authored by lebedevri).

Changed prior to commit:
  https://reviews.llvm.org/D38289?vs=116696&id=118453#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38289

Files:
  llvm/trunk/tools/opt-viewer/opt-viewer.py


Index: llvm/trunk/tools/opt-viewer/opt-viewer.py
===================================================================
--- llvm/trunk/tools/opt-viewer/opt-viewer.py
+++ llvm/trunk/tools/opt-viewer/opt-viewer.py
@@ -10,6 +10,7 @@
 import os.path
 import re
 import shutil
+import sys
 
 from pygments import highlight
 from pygments.lexers.c_cpp import CppLexer
@@ -62,7 +63,11 @@
         html_highlighted = highlight(
             file_text,
             self.cpp_lexer,
-            self.html_formatter).decode('utf-8')
+            self.html_formatter)
+
+        # On Python 3, pygments.highlight() returns a bytes object, not a str.
+        if sys.version_info >= (3, 0):
+          html_highlighted = html_highlighted.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: D38289.118453.patch
Type: text/x-patch
Size: 858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171010/7cdbdc86/attachment.bin>


More information about the llvm-commits mailing list