资源简介
解决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)
- 上一篇:基于PYQT编写的人脸识别软件
- 下一篇:python 3.6 socket传输视频
评论
共有 条评论