Skip to content

Instantly share code, notes, and snippets.

@ypochien
Created December 20, 2016 02:19
Show Gist options
  • Save ypochien/d257fe82265ca678e81b3d8c0dc80aa8 to your computer and use it in GitHub Desktop.
Save ypochien/d257fe82265ca678e81b3d8c0dc80aa8 to your computer and use it in GitHub Desktop.
cp950 to UTF8
def decorate_to_utf8(func):
"""只要參數是str就要to cp950給t4.dll
只要回傳值是bytes就要to utf8給 Api caller"""
def func_wrapper(*args):
new_args = list(args)
for idx, arg in enumerate(args):
if isinstance(arg, str):
new_args[idx] = args[idx].encode('utf-8')
res = func(*new_args)
if isinstance(res, bytes):
return str(res, 'cp950')
else:
return res
return func_wrapper
@decorate_to_utf8
def do_register(cls, reg):
return do_register(reg)
@decorate_to_utf8
def add_acc_ca(cls, branch, account, account_id, ca_path, ca_password):
return add_acc_ca(branch, account, account_id, ca_path, ca_password)
@decorate_to_utf8
def show_list(cls):
return show_list()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment