Mercurial > hg-stable
changeset 9131:2bbb8419720d
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.
author | Shun-ichi GOTO <shunichi.goto@gmail.com> |
---|---|
date | Fri, 10 Jul 2009 15:52:01 +0900 |
parents | 335f749cc369 |
children | b47d7b440c5c |
files | hgext/win32mbcs.py |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/win32mbcs.py Fri Jul 10 19:45:31 2009 +0200 +++ b/hgext/win32mbcs.py Fri Jul 10 15:52:01 2009 +0900 @@ -52,6 +52,9 @@ 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 @@ 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 @@ 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: