mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-24 19:33:33 +01:00
11 lines
295 B
Python
11 lines
295 B
Python
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)
|