changeset 50739:48d9af6bd043 stable

win32mbcs: unbyteify some strings for py3 support A crash was reported on the TortoiseHg bug tracker for this[1]. [1] https://foss.heptapod.net/mercurial/tortoisehg/thg/-/issues/5905
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 08 Jun 2023 00:03:54 -0400
parents 929655c0e613
children 0159b014f3ab
files hgext/win32mbcs.py
diffstat 1 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/win32mbcs.py	Tue Jul 04 12:30:31 2023 +0200
+++ b/hgext/win32mbcs.py	Thu Jun 08 00:03:54 2023 -0400
@@ -82,7 +82,7 @@
         uarg = arg.decode(_encoding)
         if arg == uarg.encode(_encoding):
             return uarg
-        raise UnicodeError(b"Not local encoding")
+        raise UnicodeError("Not local encoding")
     elif isinstance(arg, tuple):
         return tuple(map(decode, arg))
     elif isinstance(arg, list):
@@ -111,8 +111,8 @@
     try:
         us = decode(s)
     except UnicodeError:
-        us = s
-    if us and us[-1] not in b':/\\':
+        us = s  # TODO: how to handle this bytes case??
+    if us and us[-1] not in ':/\\':
         s += pycompat.ossep
     return s
 
@@ -148,13 +148,13 @@
     if args:
         args = list(args)
         args[0] = appendsep(args[0])
-    if b'path' in kwds:
-        kwds[b'path'] = appendsep(kwds[b'path'])
+    if 'path' in kwds:
+        kwds['path'] = appendsep(kwds['path'])
     return func(*args, **kwds)
 
 
-def wrapname(name, wrapper):
-    module, name = name.rsplit(b'.', 1)
+def wrapname(name: str, wrapper):
+    module, name = name.rsplit('.', 1)
     module = sys.modules[module]
     func = getattr(module, name)
 
@@ -168,7 +168,7 @@
 # List of functions to be wrapped.
 # NOTE: os.path.dirname() and os.path.basename() are safe because
 #       they use result of os.path.split()
-funcs = b'''os.path.join os.path.split os.path.splitext
+funcs = '''os.path.join os.path.split os.path.splitext
  os.path.normpath os.makedirs mercurial.util.endswithsep
  mercurial.util.splitpath mercurial.util.fscasesensitive
  mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath
@@ -178,11 +178,11 @@
 # These functions are required to be called with local encoded string
 # because they expects argument is local encoded string and cause
 # problem with unicode string.
-rfuncs = b'''mercurial.encoding.upper mercurial.encoding.lower
+rfuncs = '''mercurial.encoding.upper mercurial.encoding.lower
  mercurial.util._filenamebytestr'''
 
 # List of Windows specific functions to be wrapped.
-winfuncs = b'''os.path.splitunc'''
+winfuncs = '''os.path.splitunc'''
 
 # codec and alias names of sjis and big5 to be faked.
 problematic_encodings = b'''big5 big5-tw csbig5 big5hkscs big5-hkscs
@@ -208,15 +208,15 @@
         if pycompat.iswindows:
             for f in winfuncs.split():
                 wrapname(f, wrapper)
-        wrapname(b"mercurial.util.listdir", wrapperforlistdir)
-        wrapname(b"mercurial.windows.listdir", wrapperforlistdir)
+        wrapname("mercurial.util.listdir", wrapperforlistdir)
+        wrapname("mercurial.windows.listdir", wrapperforlistdir)
         # wrap functions to be called with local byte string arguments
         for f in rfuncs.split():
             wrapname(f, reversewrapper)
         # Check sys.args manually instead of using ui.debug() because
         # command line options is not yet applied when
         # extensions.loadall() is called.
-        if b'--debug' in sys.argv:
+        if '--debug' in sys.argv:
             ui.writenoi18n(
                 b"[win32mbcs] activated with encoding: %s\n" % _encoding
             )