Show More
@@ -89,19 +89,28 def appendsep(s): | |||||
89 | s += os.sep |
|
89 | s += os.sep | |
90 | return s |
|
90 | return s | |
91 |
|
91 | |||
92 | def wrapper(func, args, kwds): |
|
92 | ||
93 | # check argument is unicode, then call original |
|
93 | def basewrapper(func, argtype, enc, dec, args, kwds): | |
|
94 | # check check already converted, then call original | |||
94 | for arg in args: |
|
95 | for arg in args: | |
95 |
if isinstance(arg, |
|
96 | if isinstance(arg, argtype): | |
96 | return func(*args, **kwds) |
|
97 | return func(*args, **kwds) | |
97 |
|
98 | |||
98 | try: |
|
99 | try: | |
99 |
# convert arguments |
|
100 | # convert string arguments, call func, then convert back the | |
100 | return encode(func(*decode(args), **decode(kwds))) |
|
101 | # return value. | |
|
102 | return enc(func(*dec(args), **dec(kwds))) | |||
101 | except UnicodeError: |
|
103 | except UnicodeError: | |
102 | raise util.Abort(_("[win32mbcs] filename conversion failed with" |
|
104 | raise util.Abort(_("[win32mbcs] filename conversion failed with" | |
103 | " %s encoding\n") % (_encoding)) |
|
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 | def wrapperforlistdir(func, args, kwds): |
|
114 | def wrapperforlistdir(func, args, kwds): | |
106 | # Ensure 'path' argument ends with os.sep to avoids |
|
115 | # Ensure 'path' argument ends with os.sep to avoids | |
107 | # misinterpreting last 0x5c of MBCS 2nd byte as path separator. |
|
116 | # misinterpreting last 0x5c of MBCS 2nd byte as path separator. | |
@@ -133,6 +142,11 funcs = '''os.path.join os.path.split os | |||||
133 | mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath |
|
142 | mercurial.util.fspath mercurial.util.pconvert mercurial.util.normpath | |
134 | mercurial.util.checkwinfilename mercurial.util.checkosfilename''' |
|
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 | # List of Windows specific functions to be wrapped. |
|
150 | # List of Windows specific functions to be wrapped. | |
137 | winfuncs = '''os.path.splitunc''' |
|
151 | winfuncs = '''os.path.splitunc''' | |
138 |
|
152 | |||
@@ -159,6 +173,9 def extsetup(ui): | |||||
159 | for f in winfuncs.split(): |
|
173 | for f in winfuncs.split(): | |
160 | wrapname(f, wrapper) |
|
174 | wrapname(f, wrapper) | |
161 | wrapname("mercurial.osutil.listdir", wrapperforlistdir) |
|
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 | # Check sys.args manually instead of using ui.debug() because |
|
179 | # Check sys.args manually instead of using ui.debug() because | |
163 | # command line options is not yet applied when |
|
180 | # command line options is not yet applied when | |
164 | # extensions.loadall() is called. |
|
181 | # extensions.loadall() is called. |
General Comments 0
You need to be logged in to leave comments.
Login now