# HG changeset patch # User Matt Harbison # Date 2018-09-13 04:39:02 # Node ID a407f900939257680a59c5279e481cf92605b98d # Parent aa7e312375cf20a820f46b53f64aa6b7310333fb py3: byteify strings in pycompat These surfaced when disabling the source transformer to debug the problems in win32.py. ./contrib/byteify-strings.py found a couple false positives, so I marked them with r'' explicitly (in case I'm wrong). # skip-blame since this is just b'' and r'' prefixing diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -138,7 +138,7 @@ if ispy3: if getattr(sys, 'argv', None) is not None: sysargv = list(map(os.fsencode, sys.argv)) - bytechr = struct.Struct('>B').pack + bytechr = struct.Struct(r'>B').pack byterepr = b'%r'.__mod__ class bytestr(bytes): @@ -282,7 +282,7 @@ if ispy3: xrange = builtins.range unicode = str - def open(name, mode='r', buffering=-1, encoding=None): + def open(name, mode=b'r', buffering=-1, encoding=None): return builtins.open(name, sysstr(mode), buffering, encoding) safehasattr = _wrapattrfunc(builtins.hasattr) @@ -359,7 +359,7 @@ else: return filename else: raise TypeError( - "expect str, not %s" % type(filename).__name__) + r"expect str, not %s" % type(filename).__name__) # In Python 2, fsdecode() has a very chance to receive bytes. So it's # better not to touch Python 2 part as it's already working fine. @@ -404,11 +404,11 @@ else: rawinput = raw_input getargspec = inspect.getargspec -isjython = sysplatform.startswith('java') +isjython = sysplatform.startswith(b'java') -isdarwin = sysplatform == 'darwin' -isposix = osname == 'posix' -iswindows = osname == 'nt' +isdarwin = sysplatform == b'darwin' +isposix = osname == b'posix' +iswindows = osname == b'nt' def getoptb(args, shortlist, namelist): return _getoptbwrapper(getopt.getopt, args, shortlist, namelist)