NDOJ/judge/utils/unicode.py

18 lines
422 B
Python
Raw Permalink Normal View History

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
return maybe_text.encode('utf-8')
def utf8text(maybe_bytes, errors='strict'):
if maybe_bytes is None:
return
if isinstance(maybe_bytes, six.text_type):
return maybe_bytes
return maybe_bytes.decode('utf-8', errors)