mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-17 19:43:34 +02:00
Move force_uniceode to utils package
This commit is contained in:
@@ -111,22 +111,3 @@ def prepare_string_for_xml(raw, attribute=False):
|
||||
if attribute:
|
||||
raw = raw.replace('"', '"').replace("'", ''')
|
||||
return raw
|
||||
|
||||
|
||||
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