1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-03-10 11:35:50 +01:00

Removed isbytestring function

This commit is contained in:
2020-06-14 12:10:40 +02:00
parent a69884d724
commit be671ef2d8
10 changed files with 29 additions and 40 deletions

View File

@@ -117,9 +117,9 @@ def sanitize_file_name(name, substitute='_'):
**WARNING:** This function also replaces path separators, so only pass file names
and not full paths to it.
'''
if isbytestring(name):
if isinstance(name, bytes):
name = name.decode(filesystem_encoding, 'replace')
if isbytestring(substitute):
if isinstance(substitute, bytes):
substitute = substitute.decode(filesystem_encoding, 'replace')
chars = (substitute if c in _filename_sanitize_unicode else c for c in name)
one = ''.join(chars)
@@ -569,12 +569,8 @@ def prepare_string_for_xml(raw, attribute=False):
return raw
def isbytestring(obj):
return isinstance(obj, bytes)
def force_unicode(obj, enc=preferred_encoding):
if isbytestring(obj):
if isinstance(obj, bytes):
try:
obj = obj.decode(enc)
except Exception:
@@ -586,13 +582,13 @@ def force_unicode(obj, enc=preferred_encoding):
obj = obj.decode('utf-8')
except Exception:
obj = repr(obj)
if isbytestring(obj):
if isinstance(obj, bytes):
obj = obj.decode('utf-8')
return obj
def as_unicode(obj, enc=preferred_encoding):
if not isbytestring(obj):
if not isinstance(obj, bytes):
try:
obj = str(obj)
except Exception: