##// END OF EJS Templates
win32mbcs: add reversing wrapper for some unicode-incompatible functions....
Shun-ichi GOTO -
r17798:4091b032 default
parent child Browse files
Show More
@@ -89,19 +89,28 b' def appendsep(s):'
89 89 s += os.sep
90 90 return s
91 91
92 def wrapper(func, args, kwds):
93 # check argument is unicode, then call original
92
93 def basewrapper(func, argtype, enc, dec, args, kwds):
94 # check check already converted, then call original
94 95 for arg in args:
95 if isinstance(arg, unicode):
96 if isinstance(arg, argtype):
96 97 return func(*args, **kwds)
97 98
98 99 try:
99 # convert arguments to unicode, call func, then convert back
100 return encode(func(*decode(args), **decode(kwds)))
100 # convert string arguments, call func, then convert back the
101 # return value.
102 return enc(func(*dec(args), **dec(kwds)))
101 103 except UnicodeError:
102 104 raise util.Abort(_("[win32mbcs] filename conversion failed with"
103 105 " %s encoding\n") % (_encoding))
104 106
107 def wrapper(func, args, kwds):
108 return basewrapper(func, unicode, encode, decode, args, kwds)
109
110
111 def reversewrapper(func, args, kwds):
112 return basewrapper(func, str, decode, encode, args, kwds)
113
105 114 def wrapperforlistdir(func, args, kwds):
106 115 # Ensure 'path' argument ends with os.sep to avoids
107 116 # misinterpreting last 0x5c of MBCS 2nd byte as path separator.
@@ -133,6 +142,11 b" funcs = '''os.path.join os.path.split os"
133 142 mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath
134 143 mercurial.util.checkwinfilename mercurial.util.checkosfilename'''
135 144
145 # These functions are required to be called with local encoded string
146 # because they expects argument is local encoded string and cause
147 # problem with unicode string.
148 rfuncs = '''mercurial.encoding.upper mercurial.encoding.lower'''
149
136 150 # List of Windows specific functions to be wrapped.
137 151 winfuncs = '''os.path.splitunc'''
138 152
@@ -159,6 +173,9 b' def extsetup(ui):'
159 173 for f in winfuncs.split():
160 174 wrapname(f, wrapper)
161 175 wrapname("mercurial.osutil.listdir", wrapperforlistdir)
176 # wrap functions to be called with local byte string arguments
177 for f in rfuncs.split():
178 wrapname(f, reversewrapper)
162 179 # Check sys.args manually instead of using ui.debug() because
163 180 # command line options is not yet applied when
164 181 # extensions.loadall() is called.
General Comments 0
You need to be logged in to leave comments. Login now