def to_bytes(strlike, encoding="latin-1", errors="backslashreplace"):
    """Turns a str into bytes (Python 3) or a unicode to a str (Python 2)"""
    if strlike is None:
        return
    if not isinstance(strlike, bytes):
        return strlike.encode(encoding, errors)
    return strlike