mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-08 22:13:34 +02:00
Removed polyglots unicode_type usage
This commit is contained in:
@@ -1,52 +1,50 @@
|
||||
from base64 import standard_b64decode, standard_b64encode
|
||||
from binascii import hexlify, unhexlify
|
||||
|
||||
from ebook_converter.polyglot.builtins import unicode_type
|
||||
|
||||
|
||||
def as_base64_bytes(x, enc='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode(enc)
|
||||
return standard_b64encode(x)
|
||||
|
||||
|
||||
def as_base64_unicode(x, enc='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode(enc)
|
||||
return standard_b64encode(x).decode('ascii')
|
||||
|
||||
|
||||
def from_base64_unicode(x, enc='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('ascii')
|
||||
return standard_b64decode(x).decode(enc)
|
||||
|
||||
|
||||
def from_base64_bytes(x):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('ascii')
|
||||
return standard_b64decode(x)
|
||||
|
||||
|
||||
def as_hex_bytes(x, enc='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode(enc)
|
||||
return hexlify(x)
|
||||
|
||||
|
||||
def as_hex_unicode(x, enc='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode(enc)
|
||||
return hexlify(x).decode('ascii')
|
||||
|
||||
|
||||
def from_hex_unicode(x, enc='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('ascii')
|
||||
return unhexlify(x).decode(enc)
|
||||
|
||||
|
||||
def from_hex_bytes(x):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
x = x.encode('ascii')
|
||||
return unhexlify(x)
|
||||
|
||||
@@ -13,7 +13,7 @@ def hasenv(x):
|
||||
|
||||
|
||||
def as_bytes(x, encoding='utf-8'):
|
||||
if isinstance(x, unicode_type):
|
||||
if isinstance(x, str):
|
||||
return x.encode(encoding)
|
||||
if isinstance(x, bytes):
|
||||
return x
|
||||
@@ -21,8 +21,8 @@ def as_bytes(x, encoding='utf-8'):
|
||||
return bytes(x)
|
||||
if isinstance(x, memoryview):
|
||||
return x.tobytes()
|
||||
ans = unicode_type(x)
|
||||
if isinstance(ans, unicode_type):
|
||||
ans = str(x)
|
||||
if isinstance(ans, str):
|
||||
ans = ans.encode(encoding)
|
||||
return ans
|
||||
|
||||
@@ -30,7 +30,7 @@ def as_bytes(x, encoding='utf-8'):
|
||||
def as_unicode(x, encoding='utf-8', errors='strict'):
|
||||
if isinstance(x, bytes):
|
||||
return x.decode(encoding, errors)
|
||||
return unicode_type(x)
|
||||
return str(x)
|
||||
|
||||
|
||||
def reraise(tp, value, tb=None):
|
||||
@@ -46,7 +46,6 @@ def reraise(tp, value, tb=None):
|
||||
|
||||
|
||||
codepoint_to_chr = chr
|
||||
unicode_type = str
|
||||
string_or_bytes = str, bytes
|
||||
string_or_unicode = str
|
||||
long_type = int
|
||||
@@ -57,9 +56,9 @@ getenv = os.getenv
|
||||
|
||||
def error_message(exc):
|
||||
args = getattr(exc, 'args', None)
|
||||
if args and isinstance(args[0], unicode_type):
|
||||
if args and isinstance(args[0], str):
|
||||
return args[0]
|
||||
return unicode_type(exc)
|
||||
return str(exc)
|
||||
|
||||
|
||||
def iteritems(d):
|
||||
|
||||
Reference in New Issue
Block a user