import six


def bitcast_to_bytes(s):
    """
    Take a string and return a string(PY2) or a bytes(PY3) object. The returned
    object contains the exact same bytes as the input string. (latin1 <->
    unicode transformation is an identity operation for the first 256 code
    points).
    """
    return s if six.PY2 else s.encode("latin1")