human
Complete this python program:
def _writeFlattenedData(state, write, result):
assistant
#Here is the Python code you requested.

    """Take strings from an iterator and pass them to a writer function.
    @param state: An iterator of L{str} and L{Deferred}.  L{str} instances will
    be passed to C{write}.  L{Deferred} instances will be waited on before
    resuming iteration of C{state}.
    @param write: A callable which will be invoked with each L{str}
    produced by iterating C{state}.
    @param result: A L{Deferred} which will be called back when C{state} has
    been completely flattened into C{write} or which will be errbacked if
    an exception in a generator passed to C{state} or an errback from a
    L{Deferred} from state occurs.
    @return: L{None}
    """
    while True:
        try:
            element = next(state)
        except StopIteration:
            result.callback(None)
        except:
            result.errback()
        else:
            def cby(original):
                _writeFlattenedData(state, write, result)
                return original
            element.addCallbacks(cby, result.errback)
        break