##// END OF EJS Templates
win32mbcs: add special wrapper for osutil.listdir()....
Shun-ichi GOTO -
r9132:b47d7b44 default
parent child Browse files
Show More
@@ -69,6 +69,16 b' def encode(arg):'
69 69 arg[k] = encode(v)
70 70 return arg
71 71
72 def appendsep(s):
73 # ensure the path ends with os.sep, appending it if necessary.
74 try:
75 us = decode(s)
76 except UnicodeError:
77 us = s
78 if us and us[-1] not in ':/\\':
79 s += os.sep
80 return s
81
72 82 def wrapper(func, args, kwds):
73 83 # check argument is unicode, then call original
74 84 for arg in args:
@@ -79,12 +89,20 b' def wrapper(func, args, kwds):'
79 89 # convert arguments to unicode, call func, then convert back
80 90 return encode(func(*decode(args), **decode(kwds)))
81 91 except UnicodeError:
82 # If not encoded with encoding.encoding, report it then
83 # continue with calling original function.
84 raise util.Abort(_("[win32mbcs] filename conversion fail with"
92 raise util.Abort(_("[win32mbcs] filename conversion failed with"
85 93 " %s encoding\n") % (encoding.encoding))
86 94
87 def wrapname(name):
95 def wrapperforlistdir(func, args, kwds):
96 # Ensure 'path' argument ends with os.sep to avoids
97 # misinterpreting last 0x5c of MBCS 2nd byte as path separator.
98 if args:
99 args = list(args)
100 args[0] = appendsep(args[0])
101 if kwds.has_key('path'):
102 kwds['path'] = appendsep(kwds['path'])
103 return func(*args, **kwds)
104
105 def wrapname(name, wrapper):
88 106 module, name = name.rsplit('.', 1)
89 107 module = sys.modules[module]
90 108 func = getattr(module, name)
@@ -119,7 +137,8 b' def reposetup(ui, repo):'
119 137 # fake is only for relevant environment.
120 138 if encoding.encoding.lower() in problematic_encodings.split():
121 139 for f in funcs.split():
122 wrapname(f)
140 wrapname(f, wrapper)
141 wrapname("mercurial.osutil.listdir", wrapperforlistdir)
123 142 ui.debug(_("[win32mbcs] activated with encoding: %s\n")
124 143 % encoding.encoding)
125 144
General Comments 0
You need to be logged in to leave comments. Login now