##// END OF EJS Templates
win32mbcs: wrapper supports keyword arguments and dict result....
Shun-ichi GOTO -
r9131:2bbb8419 default
parent child Browse files
Show More
@@ -52,6 +52,9 b' def decode(arg):'
52 52 return tuple(map(decode, arg))
53 53 elif isinstance(arg, list):
54 54 return map(decode, arg)
55 elif isinstance(arg, dict):
56 for k, v in arg.items():
57 arg[k] = decode(v)
55 58 return arg
56 59
57 60 def encode(arg):
@@ -61,17 +64,20 b' def encode(arg):'
61 64 return tuple(map(encode, arg))
62 65 elif isinstance(arg, list):
63 66 return map(encode, arg)
67 elif isinstance(arg, dict):
68 for k, v in arg.items():
69 arg[k] = encode(v)
64 70 return arg
65 71
66 def wrapper(func, args):
72 def wrapper(func, args, kwds):
67 73 # check argument is unicode, then call original
68 74 for arg in args:
69 75 if isinstance(arg, unicode):
70 return func(*args)
76 return func(*args, **kwds)
71 77
72 78 try:
73 79 # convert arguments to unicode, call func, then convert back
74 return encode(func(*decode(args)))
80 return encode(func(*decode(args), **decode(kwds)))
75 81 except UnicodeError:
76 82 # If not encoded with encoding.encoding, report it then
77 83 # continue with calling original function.
@@ -82,8 +88,8 b' def wrapname(name):'
82 88 module, name = name.rsplit('.', 1)
83 89 module = sys.modules[module]
84 90 func = getattr(module, name)
85 def f(*args):
86 return wrapper(func, args)
91 def f(*args, **kwds):
92 return wrapper(func, args, kwds)
87 93 try:
88 94 f.__name__ = func.__name__ # fail with python23
89 95 except Exception:
General Comments 0
You need to be logged in to leave comments. Login now