mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-01-23 13:25:45 +01:00
14 lines
314 B
Python
14 lines
314 B
Python
import importlib
|
|
|
|
|
|
def as_bytes(x, encoding='utf-8'):
|
|
if isinstance(x, str):
|
|
return x.encode(encoding)
|
|
if isinstance(x, bytes):
|
|
return x
|
|
if isinstance(x, bytearray):
|
|
return bytes(x)
|
|
if isinstance(x, memoryview):
|
|
return x.tobytes()
|
|
return str(x).encode(encoding)
|