def bytestr(text):
# type: (Union[str, bytes]) -> bytes
if isinstance(text, binary_type):
return text
try:
return text.encode('utf-8')
except UnicodeEncodeError:
if HAS_FSCODEC:
return os.fsencode(text)
raise