def ensure_str(val):
    """Converts the argument to a string if it isn't one already"""
    if isinstance(val, str):
        return val
    elif isinstance(val, (bytes, bytearray)):
        return val.decode()
    else:
        raise ValueError('Expected bytes or string')