2020-01-21 06:35:58 +00:00
|
|
|
from django.utils import six
|
|
|
|
|
|
|
|
|
|
|
|
def utf8bytes(maybe_text):
|
|
|
|
if maybe_text is None:
|
|
|
|
return
|
|
|
|
if isinstance(maybe_text, six.binary_type):
|
|
|
|
return maybe_text
|
2022-05-14 17:57:27 +00:00
|
|
|
return maybe_text.encode("utf-8")
|
2020-01-21 06:35:58 +00:00
|
|
|
|
|
|
|
|
2022-05-14 17:57:27 +00:00
|
|
|
def utf8text(maybe_bytes, errors="strict"):
|
2020-01-21 06:35:58 +00:00
|
|
|
if maybe_bytes is None:
|
|
|
|
return
|
|
|
|
if isinstance(maybe_bytes, six.text_type):
|
|
|
|
return maybe_bytes
|
2022-05-14 17:57:27 +00:00
|
|
|
return maybe_bytes.decode("utf-8", errors)
|