def to_bytes(st, encoding='utf-8'):
    if isinstance(st, str):
      return st.encode(encoding)
    elif isinstance(st, bytes):
      return st
    else:
      raise ValueError('Cannot convert %s to bytes.' % type(st))
dataset/ETHPy150Open pantsbuild/pex/pex/compatibility.py/to_bytes/original