import networkx as nx


def reachable_from(graph, node):
    """
    Given an nx graph and a node within this graph,
    return all of the nodes in the same connected component as the input node.
    """
    if isinstance(graph, nx.DiGraph):
        conn = nx.all_pairs_node_connectivity(graph)
        return [n1 for (n1, dist) in conn[node].iteritems() if dist > 0]

    elif isinstance(graph, nx.Graph):
        for comp in nx.connected_components(graph):
            if node in comp:
                return comp


    # Shouldn't get here
    # since the node should appear in some connected component of the graph
    raise Exception("Node {} not in graph".format(node))