Skip to content

Commit

Permalink
improve decode behavior, only utf8 as lartin will cause some messy code
Browse files Browse the repository at this point in the history
  • Loading branch information
wjo1212 committed Dec 27, 2018
1 parent bd8320f commit 603c93c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions aliyun/log/pulllog_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from .log_logs_raw_pb2 import LogGroupListRaw
import six

DEFAULT_DECODE_LIST = ('utf8',)


class PullLogResponse(LogResponse):
""" The response of the pull_logs API from log.
Expand Down Expand Up @@ -117,15 +119,17 @@ def _transfer_to_json(self):
'tags': tags}
self.loggroup_list_json.append(log_items)

DEFAULT_DECODE_LIST = ('utf8', 'latin1', 'gbk8')

@staticmethod
def _b2u(content):
if six.PY3 and isinstance(content, six.binary_type):
for d in PullLogResponse.DEFAULT_DECODE_LIST:
if len(DEFAULT_DECODE_LIST) == 1:
return content.decode(DEFAULT_DECODE_LIST[0], 'ignore')

for d in DEFAULT_DECODE_LIST:
try:
return content.decode(d)
except UnicodeDecodeError as ex:
except Exception as ex:
continue

# force to use utf8
Expand Down

0 comments on commit 603c93c

Please sign in to comment.