Skip to content
Snippets Groups Projects
Commit 48d9af6bd043 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 929655c0e613
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 @@
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,8 +148,8 @@
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)
......@@ -153,8 +153,8 @@
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,7 +178,7 @@
# 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.
......@@ -182,7 +182,7 @@
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,11 +208,11 @@
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.
......@@ -213,10 +213,10 @@
# 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
)
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