資源簡介
解決ride日志中文顯示為unicode編碼的問題
代碼片段和文件信息
#??Copyright?2008-2015?Nokia?Networks
#??Copyright?2016-?????Robot?framework?Foundation
#
#??Licensed?under?the?Apache?License?Version?2.0?(the?“License“);
#??you?may?not?use?this?file?except?in?compliance?with?the?License.
#??You?may?obtain?a?copy?of?the?License?at
#
#??????http://www.apache.org/licenses/LICENSE-2.0
#
#??Unless?required?by?applicable?law?or?agreed?to?in?writing?software
#??distributed?under?the?License?is?distributed?on?an?“AS?IS“?BASIS
#??WITHOUT?WARRANTIES?OR?CONDITIONS?OF?ANY?KIND?either?express?or?implied.
#??See?the?License?for?the?specific?language?governing?permissions?and
#??limitations?under?the?License.
from?pprint?import?PrettyPrinter
from?.platform?import?IRONPYTHON?JYTHON?PY2
from?.robottypes?import?is_bytes?is_unicode
import?json
if?PY2:
????def?unic(item):
????????if?isinstance(item?unicode):
????????????return?item
????????if?isinstance(item?(bytes?bytearray)):
????????????try:
????????????????return?item.decode(‘ASCII‘)
????????????except?UnicodeError:
????????????????return?u‘‘.join(chr(b)?if?b?128?else?‘\\x%x‘?%?b
????????????????????????????????for?b?in?bytearray(item))
????????????????????????????????
????????if?isinstance(item?(list?dict?tuple)):
????????????try:
????????????????item?=?json.dumps(item?ensure_ascii=False?encoding=‘utf-8‘)
????????????except?UnicodeDecodeError:
????????????????try:
????????????????????item?=?json.dumps(item?ensure_ascii=False?encoding=‘gbk‘)
????????????????except:
????????????????????pass
????????????except:
????????????????pass
????????try:
????????????try:
????????????????return?unicode(item)
???????
評論
共有 條評論