2016-12-26 17:20:12 +01:00
|
|
|
def _decode(string, encoding='utf8'):
|
2017-01-08 23:43:01 +01:00
|
|
|
"""Return a utf8 encoded unicode string.
|
|
|
|
|
|
|
|
Python2 and Python3 differ in how they handle strings.
|
|
|
|
So we do a few checks to see if the string is ascii or unicode.
|
|
|
|
Then we decode it if needed.
|
|
|
|
"""
|
2016-12-26 17:20:12 +01:00
|
|
|
if hasattr(string, 'decode'):
|
2017-01-08 23:43:01 +01:00
|
|
|
# If the string is already unicode we return it.
|
|
|
|
try:
|
|
|
|
if isinstance(string, unicode):
|
|
|
|
return string
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
|
2016-12-26 17:20:12 +01:00
|
|
|
return string.decode(encoding)
|
|
|
|
|
|
|
|
return string
|
|
|
|
|
|
|
|
|