py3: encode str to bytes
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 12 Oct 2018 18:20:17 +0200
changeset 40202 56ea22fa55f0
parent 40201 7df42042636d
child 40203 f80f7a67e176
py3: encode str to bytes These fields are str on Python 2 and 3. This module doesn't import any Mercurial modules. So I just did the str -> bytes inline. Differential Revision: https://phab.mercurial-scm.org/D5010
mercurial/lsprof.py
--- a/mercurial/lsprof.py	Fri Oct 12 19:00:24 2018 +0200
+++ b/mercurial/lsprof.py	Fri Oct 12 18:20:17 2018 +0200
@@ -91,6 +91,8 @@
 
 def label(code):
     if isinstance(code, str):
+        if sys.version_info.major >= 3:
+            code = code.encode('latin-1')
         return code
     try:
         mname = _fn2mod[code.co_filename]
@@ -104,10 +106,14 @@
                 mname = _fn2mod[code.co_filename] = k
                 break
         else:
-            mname = _fn2mod[code.co_filename] = '<%s>' % code.co_filename
+            mname = _fn2mod[code.co_filename] = r'<%s>' % code.co_filename
+
+    res = r'%s:%d(%s)' % (mname, code.co_firstlineno, code.co_name)
 
-    return '%s:%d(%s)' % (mname, code.co_firstlineno, code.co_name)
+    if sys.version_info.major >= 3:
+        res = res.encode('latin-1')
 
+    return res
 
 if __name__ == '__main__':
     import os