def node(self, key): """Returns node based on name This is currently O(N). Could use a lookup table""" try: if key.node_id in self._graph: return DmNode(self, key.node_id) except AttributeError: # doesn't have node_id, likely a label string, search on label for node in self: if str(node) == key: return node elif node.id == key: # label could be "a b" -> "a_b" (ie folder safe, etc) # TODO: need to fix this discrepancy return node print "Unable to find node", key, "in", self return None
def __iter__(self): return iter(DmNode(self, node) for node in self._graph)
def src(self): return DmNode(self.nidb, self.src_id)
def boundary_nodes(self, nbunch, nbunch2=None): nbunch = (n.node_id for n in nbunch) # only store the id in overlay return iter( DmNode(self, node) for node in nx.node_boundary(self._graph, nbunch, nbunch2))
def dst(self): return DmNode(self.nidb, self.dst_id)