prevent crashing when logging object unable to be converted to unicode
This commit is contained in:
parent
a69c50f470
commit
c574234927
1 changed files with 7 additions and 2 deletions
|
@ -47,6 +47,8 @@ if is_py2:
|
||||||
def u(text):
|
def u(text):
|
||||||
if text is None:
|
if text is None:
|
||||||
return None
|
return None
|
||||||
|
if isinstance(text, unicode):
|
||||||
|
return text
|
||||||
try:
|
try:
|
||||||
return text.decode('utf-8')
|
return text.decode('utf-8')
|
||||||
except:
|
except:
|
||||||
|
@ -58,8 +60,11 @@ if is_py2:
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
return text.decode('utf-8', 'replace')
|
return text.decode('utf-8', 'replace')
|
||||||
except AttributeError:
|
except:
|
||||||
|
try:
|
||||||
return unicode(str(text))
|
return unicode(str(text))
|
||||||
|
except:
|
||||||
|
return unicode('')
|
||||||
|
|
||||||
elif is_py3:
|
elif is_py3:
|
||||||
def u(text):
|
def u(text):
|
||||||
|
|
Loading…
Reference in a new issue