prevent crashing when logging object unable to be converted to unicode

This commit is contained in:
Alan Hamlett 2017-02-08 19:24:26 -08:00
parent a69c50f470
commit c574234927

View file

@ -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):