2017-05-03 16:13:08 +08:00
|
|
|
import sys
|
2018-11-04 20:13:34 -08:00
|
|
|
from libs.constants import DEFAULT_ENCODING
|
2017-05-03 16:13:08 +08:00
|
|
|
|
|
|
|
|
def ustr(x):
|
2021-03-15 00:56:14 +01:00
|
|
|
"""py2/py3 unicode helper"""
|
2017-05-03 16:13:08 +08:00
|
|
|
|
|
|
|
|
if sys.version_info < (3, 0, 0):
|
|
|
|
|
from PyQt4.QtCore import QString
|
|
|
|
|
if type(x) == str:
|
2018-11-04 20:13:34 -08:00
|
|
|
return x.decode(DEFAULT_ENCODING)
|
2017-05-03 16:13:08 +08:00
|
|
|
if type(x) == QString:
|
2021-03-15 00:56:14 +01:00
|
|
|
# https://blog.csdn.net/friendan/article/details/51088476
|
|
|
|
|
# https://blog.csdn.net/xxm524/article/details/74937308
|
2019-01-04 12:02:26 +08:00
|
|
|
return unicode(x.toUtf8(), DEFAULT_ENCODING, 'ignore')
|
2017-05-03 16:13:08 +08:00
|
|
|
return x
|
|
|
|
|
else:
|
2018-11-04 20:13:34 -08:00
|
|
|
return x
|