mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-02 23:05:51 +01:00
Move force_uniceode to utils package
This commit is contained in:
20
ebook_converter/utils/encoding.py
Normal file
20
ebook_converter/utils/encoding.py
Normal file
@@ -0,0 +1,20 @@
|
||||
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
|
||||
Reference in New Issue
Block a user