def to_str(strlike, encoding="latin-1", errors="strict"):
    """Turns a bytes into a str or leaves it alone.
    The default encoding is latin-1 (which will not raise
    a UnicodeDecodeError); best to use when you want to treat the data
    as arbitrary bytes, but some function is expecting a str.
    """
    if isinstance(strlike, bytes):
        return strlike.decode(encoding, errors)
    return strlike