mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Micro-optimization
This commit is contained in:
parent
b3b2c36be1
commit
f53fdebabd
@ -638,21 +638,21 @@ def prepare_string_for_xml(raw, attribute=False):
|
|||||||
|
|
||||||
|
|
||||||
def isbytestring(obj):
|
def isbytestring(obj):
|
||||||
return isinstance(obj, (str, bytes))
|
return isinstance(obj, bytes)
|
||||||
|
|
||||||
|
|
||||||
def force_unicode(obj, enc=preferred_encoding):
|
def force_unicode(obj, enc=preferred_encoding):
|
||||||
if isbytestring(obj):
|
if isbytestring(obj):
|
||||||
try:
|
try:
|
||||||
obj = obj.decode(enc)
|
obj = obj.decode(enc)
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
obj = obj.decode(filesystem_encoding if enc ==
|
obj = obj.decode(filesystem_encoding if enc ==
|
||||||
preferred_encoding else preferred_encoding)
|
preferred_encoding else preferred_encoding)
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
obj = obj.decode('utf-8')
|
obj = obj.decode('utf-8')
|
||||||
except:
|
except Exception:
|
||||||
obj = repr(obj)
|
obj = repr(obj)
|
||||||
if isbytestring(obj):
|
if isbytestring(obj):
|
||||||
obj = obj.decode('utf-8')
|
obj = obj.decode('utf-8')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user