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