Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Support cp932 decode
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajunsu committed Aug 30, 2018
1 parent 2881951 commit 8621545
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions calculator_of_Onmyoji/cal_mitama.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from calculator_of_Onmyoji import write_data


ENCODINGS = ['gbk', 'big5', 'cp932']


def str2bool(v):
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
Expand Down Expand Up @@ -83,13 +86,24 @@ def str2bool(v):
u'基础暴伤为150,生命*暴伤>=60000')


def win_decode(utf_str):
for encoding in ENCODINGS:
try:
uni_str = utf_str.decode(encoding)
break
except UnicodeDecodeError:
pass
else:
print('Decode failed %s' % utf_str)
raise UnicodeDecodeError

return uni_str


def sep_utf_str(utf_str):
# solve problem with get utf8 args from shell
if sysstr == 'Windows':
try:
uni_str = utf_str.decode('gbk')
except UnicodeDecodeError:
uni_str = utf_str.decode('big5')
uni_str = win_decode(utf_str)
else:
uni_str = utf_str.decode('utf8')
if ',' in uni_str:
Expand All @@ -103,10 +117,7 @@ def sep_utf_str_to_dict(utf_str):
return dict()

if sysstr == 'Windows':
try:
uni_str = utf_str.decode('gbk')
except UnicodeDecodeError:
uni_str = utf_str.decode('big5')
uni_str = win_decode(utf_str)
else:
uni_str = utf_str.decode('utf8')
limit_list = uni_str.split('.')
Expand Down

0 comments on commit 8621545

Please sign in to comment.