# HG changeset patch # User Shun-ichi GOTO # Date 2009-07-10 06:52:01 # Node ID 2bbb8419720d4f387db8092187aba1923c41a417 # Parent 335f749cc36915b80ba1397cd9d11f7605f5d50c win32mbcs: wrapper supports keyword arguments and dict result. The keyword arguments are also decoded before calling original. And dict of return value is also encoded back. diff --git a/hgext/win32mbcs.py b/hgext/win32mbcs.py --- a/hgext/win32mbcs.py +++ b/hgext/win32mbcs.py @@ -52,6 +52,9 @@ def decode(arg): return tuple(map(decode, arg)) elif isinstance(arg, list): return map(decode, arg) + elif isinstance(arg, dict): + for k, v in arg.items(): + arg[k] = decode(v) return arg def encode(arg): @@ -61,17 +64,20 @@ def encode(arg): return tuple(map(encode, arg)) elif isinstance(arg, list): return map(encode, arg) + elif isinstance(arg, dict): + for k, v in arg.items(): + arg[k] = encode(v) return arg -def wrapper(func, args): +def wrapper(func, args, kwds): # check argument is unicode, then call original for arg in args: if isinstance(arg, unicode): - return func(*args) + return func(*args, **kwds) try: # convert arguments to unicode, call func, then convert back - return encode(func(*decode(args))) + return encode(func(*decode(args), **decode(kwds))) except UnicodeError: # If not encoded with encoding.encoding, report it then # continue with calling original function. @@ -82,8 +88,8 @@ def wrapname(name): module, name = name.rsplit('.', 1) module = sys.modules[module] func = getattr(module, name) - def f(*args): - return wrapper(func, args) + def f(*args, **kwds): + return wrapper(func, args, kwds) try: f.__name__ = func.__name__ # fail with python23 except Exception: