mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-01-17 17:54:11 +01:00
21 lines
721 B
Python
21 lines
721 B
Python
from ebook_converter import constants_old
|
|
|
|
|
|
def force_unicode(obj, enc=constants_old.preferred_encoding):
|
|
if isinstance(obj, bytes):
|
|
try:
|
|
obj = obj.decode(enc)
|
|
except Exception:
|
|
try:
|
|
obj = obj.decode(constants_old.filesystem_encoding
|
|
if enc == constants_old.preferred_encoding
|
|
else constants_old.preferred_encoding)
|
|
except Exception:
|
|
try:
|
|
obj = obj.decode('utf-8')
|
|
except Exception:
|
|
obj = repr(obj)
|
|
if isinstance(obj, bytes):
|
|
obj = obj.decode('utf-8')
|
|
return obj
|