changeset 39658:a407f9009392

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
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 13 Sep 2018 00:39:02 -0400
parents aa7e312375cf
children 47ac5d93d708
files mercurial/pycompat.py
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pycompat.py	Thu Aug 30 14:55:34 2018 -0700
+++ b/mercurial/pycompat.py	Thu Sep 13 00:39:02 2018 -0400
@@ -138,7 +138,7 @@
     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 @@
     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 @@
             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 @@
     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)