2020-03-16 07:55:36 +00:00
|
|
|
def str_to_bytes(data: str) -> bytes:
|
|
|
|
'''Convert a string to bytes with .encode(), utf8'''
|
2019-06-25 08:21:36 +00:00
|
|
|
try:
|
2019-06-26 20:13:36 +00:00
|
|
|
data = data.encode('UTF-8')
|
2019-06-25 08:21:36 +00:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
return data
|
|
|
|
|
2020-03-16 07:55:36 +00:00
|
|
|
|
|
|
|
def bytes_to_str(data: bytes) -> str:
|
|
|
|
"""Convert bytes to strings with .decode(), utf8"""
|
2019-06-25 08:21:36 +00:00
|
|
|
try:
|
2019-06-26 20:13:36 +00:00
|
|
|
data = data.decode('UTF-8')
|
2019-06-25 08:21:36 +00:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
2019-08-09 20:41:27 +00:00
|
|
|
return data
|