[uilib] fix traceback on python3
authorJulien Cristau <julien.cristau@logilab.fr>
Mon, 12 Oct 2015 18:43:41 +0200
changeset 10784 21bb9a00adeb
parent 10783 02cc22d7d339
child 10785 e63fb79b32e0
[uilib] fix traceback on python3
uilib.py
--- a/uilib.py	Mon Oct 12 18:43:05 2015 +0200
+++ b/uilib.py	Mon Oct 12 18:43:41 2015 +0200
@@ -28,7 +28,7 @@
 import re
 from io import StringIO
 
-from six import PY3, text_type, binary_type, string_types, integer_types
+from six import PY2, PY3, text_type, binary_type, string_types, integer_types
 
 from logilab.mtconverter import xml_escape, html_unescape
 from logilab.common.date import ustrftime
@@ -467,7 +467,10 @@
     for stackentry in traceback.extract_tb(info[2]):
         res.append(u'\tFile %s, line %s, function %s' % tuple(stackentry[:3]))
         if stackentry[3]:
-            res.append(u'\t  %s' % stackentry[3].decode('utf-8', 'replace'))
+            data = xml_escape(stackentry[3])
+            if PY2:
+                data = data.decode('utf-8', 'replace')
+            res.append(u'\t  %s' % data)
     res.append(u'\n')
     try:
         res.append(u'\t Error: %s\n' % exception)
@@ -501,7 +504,9 @@
                        u'<b class="function">%s</b>:<br/>'%(
             xml_escape(stackentry[0]), stackentry[1], xml_escape(stackentry[2])))
         if stackentry[3]:
-            string = xml_escape(stackentry[3]).decode('utf-8', 'replace')
+            string = xml_escape(stackentry[3])
+            if PY2:
+                string = string.decode('utf-8', 'replace')
             strings.append(u'&#160;&#160;%s<br/>\n' % (string))
         # add locals info for each entry
         try: