

def _drive(iterable, finished):
    '\n    Spin an iterable returned by L{nevow.flat.iterflatten}, setting up\n    callbacks and errbacks on Deferreds it spits out so as to continue spinning\n    it after those Deferreds fire.\n    '
    try:
        next = iterable.next()
    except StopIteration:
        finished.callback('')
    except:
        finished.errback()
    else:
        (deferred, returner) = next

        def cb(result):
            "\n            Pass the result of a Deferred on to the callable which is\n            waiting for it and then resume driving the iterable.\n\n            No one has any business whatsoever being on the callback chain\n            after this callback, so we can swallow the Deferred's result to\n            ease the garbage collector's job and for consistency with C{eb}\n            below.\n            "
            returner(result)
            _drive(iterable, finished)

        def eb(failure):
            '\n            Handle asynchronous failures in the iterable by passing them on\n            to the outer Deferred.  The iterable will not be resumed by this\n            driver any further.\n\n            Like C{cb} above, we swallow this result intentionally.  The\n            only thing that could reasonably happen to it were we to return\n            it here is for it to be logged as an unhandled Deferred, since\n            we are supposed to be the last errback on the chain.\n            '
            finished.errback(failure)
        deferred.addCallback(cb).addErrback(eb)

dataset/ETHPy150Open twisted/nevow/nevow/flat/twist.py _drive/original