human
Complete this python program:
def _poll_until_success_returning_result(should_retry, steps, sleep, function, args, kwargs):
assistant
#Here is the Python program you requested.

    """Call a function until it does not raise an exception or ``should_retry``
    says it shouldn\t be tried anymore, whichever comes first.
    :param should_retry: See ``should_retry`` parameter of ``with_retry``.
    :param steps: See ``steps`` parameter of ``with_retry``.
    :param sleep: See ``sleep`` parameter of ``with_retry``.
    :param function: The function to try calling.
    :param args: Position arguments to pass to the function.
    :param kwargs: Keyword arguments to pass to the function.
    :return: The value returned by ``function`` on the first call where it
    returns a value instead of raising an exception.
    """
    saved_result = [None]
    def pollable():
        Message.new(message_type=_TRY_RETRYING).write()
        try:
            result = function(*args, **kwargs)
        except Exception as e:
            saved_result[0] = exc_info()
            should_retry(*saved_result[0])
            Message.new(message_type=_TRY_FAILURE, exception=str(e)).write()
            return False
        else:
            Message.new(message_type=_TRY_SUCCESS, result=result).write()
            saved_result[0] = result
            return True
    try:
        poll_until(pollable, (step.total_seconds() for step in steps), sleep=sleep)
    except LoopExceeded:
        thing = saved_result.pop()
        try:
            raise thing[0], thing[1], thing[2]
        finally:
            del thing
    else:
        return saved_result[0]