Skip to content
Snippets Groups Projects
Commit 48d9af6b authored by Matt Harbison's avatar Matt Harbison
Browse files

win32mbcs: unbyteify some strings for py3 support

A crash was reported on the TortoiseHg bug tracker for this[1].

[1] mercurial/tortoisehg/thg#5905
parent 929655c0
No related branches found
No related tags found
2 merge requests!634merge stable into default,!632win32mbcs: unbyteify some strings for py3 support
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
uarg = arg.decode(_encoding) uarg = arg.decode(_encoding)
if arg == uarg.encode(_encoding): if arg == uarg.encode(_encoding):
return uarg return uarg
raise UnicodeError(b"Not local encoding") raise UnicodeError("Not local encoding")
elif isinstance(arg, tuple): elif isinstance(arg, tuple):
return tuple(map(decode, arg)) return tuple(map(decode, arg))
elif isinstance(arg, list): elif isinstance(arg, list):
...@@ -111,8 +111,8 @@ ...@@ -111,8 +111,8 @@
try: try:
us = decode(s) us = decode(s)
except UnicodeError: except UnicodeError:
us = s us = s # TODO: how to handle this bytes case??
if us and us[-1] not in b':/\\': if us and us[-1] not in ':/\\':
s += pycompat.ossep s += pycompat.ossep
return s return s
...@@ -148,8 +148,8 @@ ...@@ -148,8 +148,8 @@
if args: if args:
args = list(args) args = list(args)
args[0] = appendsep(args[0]) args[0] = appendsep(args[0])
if b'path' in kwds: if 'path' in kwds:
kwds[b'path'] = appendsep(kwds[b'path']) kwds['path'] = appendsep(kwds['path'])
return func(*args, **kwds) return func(*args, **kwds)
...@@ -153,8 +153,8 @@ ...@@ -153,8 +153,8 @@
return func(*args, **kwds) return func(*args, **kwds)
def wrapname(name, wrapper): def wrapname(name: str, wrapper):
module, name = name.rsplit(b'.', 1) module, name = name.rsplit('.', 1)
module = sys.modules[module] module = sys.modules[module]
func = getattr(module, name) func = getattr(module, name)
...@@ -168,7 +168,7 @@ ...@@ -168,7 +168,7 @@
# List of functions to be wrapped. # List of functions to be wrapped.
# NOTE: os.path.dirname() and os.path.basename() are safe because # NOTE: os.path.dirname() and os.path.basename() are safe because
# they use result of os.path.split() # 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 os.path.normpath os.makedirs mercurial.util.endswithsep
mercurial.util.splitpath mercurial.util.fscasesensitive mercurial.util.splitpath mercurial.util.fscasesensitive
mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath
...@@ -178,7 +178,7 @@ ...@@ -178,7 +178,7 @@
# These functions are required to be called with local encoded string # These functions are required to be called with local encoded string
# because they expects argument is local encoded string and cause # because they expects argument is local encoded string and cause
# problem with unicode string. # problem with unicode string.
rfuncs = b'''mercurial.encoding.upper mercurial.encoding.lower rfuncs = '''mercurial.encoding.upper mercurial.encoding.lower
mercurial.util._filenamebytestr''' mercurial.util._filenamebytestr'''
# List of Windows specific functions to be wrapped. # List of Windows specific functions to be wrapped.
...@@ -182,7 +182,7 @@ ...@@ -182,7 +182,7 @@
mercurial.util._filenamebytestr''' mercurial.util._filenamebytestr'''
# List of Windows specific functions to be wrapped. # 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. # codec and alias names of sjis and big5 to be faked.
problematic_encodings = b'''big5 big5-tw csbig5 big5hkscs big5-hkscs problematic_encodings = b'''big5 big5-tw csbig5 big5hkscs big5-hkscs
...@@ -208,11 +208,11 @@ ...@@ -208,11 +208,11 @@
if pycompat.iswindows: if pycompat.iswindows:
for f in winfuncs.split(): for f in winfuncs.split():
wrapname(f, wrapper) wrapname(f, wrapper)
wrapname(b"mercurial.util.listdir", wrapperforlistdir) wrapname("mercurial.util.listdir", wrapperforlistdir)
wrapname(b"mercurial.windows.listdir", wrapperforlistdir) wrapname("mercurial.windows.listdir", wrapperforlistdir)
# wrap functions to be called with local byte string arguments # wrap functions to be called with local byte string arguments
for f in rfuncs.split(): for f in rfuncs.split():
wrapname(f, reversewrapper) wrapname(f, reversewrapper)
# Check sys.args manually instead of using ui.debug() because # Check sys.args manually instead of using ui.debug() because
# command line options is not yet applied when # command line options is not yet applied when
# extensions.loadall() is called. # extensions.loadall() is called.
...@@ -213,10 +213,10 @@ ...@@ -213,10 +213,10 @@
# wrap functions to be called with local byte string arguments # wrap functions to be called with local byte string arguments
for f in rfuncs.split(): for f in rfuncs.split():
wrapname(f, reversewrapper) wrapname(f, reversewrapper)
# Check sys.args manually instead of using ui.debug() because # Check sys.args manually instead of using ui.debug() because
# command line options is not yet applied when # command line options is not yet applied when
# extensions.loadall() is called. # extensions.loadall() is called.
if b'--debug' in sys.argv: if '--debug' in sys.argv:
ui.writenoi18n( ui.writenoi18n(
b"[win32mbcs] activated with encoding: %s\n" % _encoding b"[win32mbcs] activated with encoding: %s\n" % _encoding
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment