def dfs_edges(G, source, condition=None):
    """Traverse a graph (DFS) with an optional condition to filter out nodes
        """
    if isinstance(source, list):
        nodes = source
    else:
        nodes = [source]
    visited = set()
    for start in nodes:
        if start in visited:
            continue
        visited.add(start)
        stack = [(start, G.out_edges(start).__iter__())]
        while stack:
            parent, children = stack[-1]
            try:
                e = next(children)
                if e.dst not in visited:
                    visited.add(e.dst)
                    if condition is None or condition(e.src, e.dst, e.data):
                        yield e
                        stack.append((e.dst, G.out_edges(e.dst).__iter__()))
            except StopIteration:
                stack.pop()
