[PATCH] win32mbcs: add reversing wrapper for some unicode-incompatible functions
Matt Mackall
mpm at selenic.com
Tue Oct 16 14:02:13 CDT 2012
On Mon, 2012-09-24 at 21:27 +0900, Shun-ichi Goto wrote:
> # HG changeset patch
> # User Shun-ichi GOTO <shunichi.goto at gmail.com>
> # Date 1347635617 -32400
> # Node ID 2b017d07ef7cd11137f20d668bece48937172264
> # Parent 453d790fe0896cb7c62ecd8cc013128b3994fcb4
> win32mbcs: add reversing wrapper for some unicode-incompatible functions.
Looks like we're waiting on a cleaned-up version of this following
foozy's review.
My take is that this is a bit too hard to read. Something like this
would be better:
diff -r 823a7d79ef82 hgext/win32mbcs.py
--- a/hgext/win32mbcs.py Mon Oct 15 09:43:34 2012 -0700
+++ b/hgext/win32mbcs.py Tue Oct 16 13:54:20 2012 -0500
@@ -89,19 +89,25 @@
s += os.sep
return s
-def wrapper(func, args, kwds):
+def basewrapper(func, argtype, enc, dec, args, kwds):
# check argument is unicode, then call original
for arg in args:
- if isinstance(arg, unicode):
+ if isinstance(arg, argtype):
return func(*args, **kwds)
try:
# convert arguments to unicode, call func, then convert back
- return encode(func(*decode(args), **decode(kwds)))
+ return encode(func(*dec(args), **enc(kwds)))
except UnicodeError:
raise util.Abort(_("[win32mbcs] filename conversion failed with"
" %s encoding\n") % (_encoding))
+def wrapper(func, args, kwds):
+ return basewrapper(func, unicode, encode, decode, args, kwds)
+
+def reversewrapper(func, args, kwds):
+ return basewrapper(func, str, decode, encode, args, kwd)
+
def wrapperforlistdir(func, args, kwds):
# Ensure 'path' argument ends with os.sep to avoids
# misinterpreting last 0x5c of MBCS 2nd byte as path separator.
While we're on the topic, this bit looks iffy:
for arg in args:
if isinstance(arg, argtype):
return func(*args, **kwds)
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list