changeset 40202:56ea22fa55f0

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
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 12 Oct 2018 18:20:17 +0200
parents 7df42042636d
children f80f7a67e176
files mercurial/lsprof.py
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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