def _dfs_connections(G, source, visited, reverse=False):
    """Produce connections in a depth-first-search starting at source."""
    # Slightly modified version of the networkx function dfs_edges

    if reverse:
        neighbors = G.predecessors_iter
    else:
        neighbors = G.successors_iter

    stack = []
    if source in G:
        stack.append((source, neighbors(source)))
    while stack:
        parent, children = stack[-1]
        try:
            child = next(children)
            if reverse:
                tup = (child, parent)
            else:
                tup = (parent, child)
            if tup not in visited:
                yield tup
                visited.add(tup)
                stack.append((child, neighbors(child)))
        except __HOLE__:
            stack.pop()
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/depgraph.py/_dfs_connections