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