def MakePathFromNodes(self, nodes): """Generate a path from a sequence of nodes.""" path = Path() for node in nodes: path.AddNode(node) if len(nodes) > 1: tail = nodes[0] for head in nodes[1:]: found = False for edge in self.adjacentEdges[tail]: if ( ( edge.node1 is tail ) and ( edge.node2 is head ) ) or \ ( ( edge.node2 is tail ) and ( edge.node1 is head ) ) : found = True path.AddEdge(edge) break if not found: raise GraphError( "Unable to find edge between two putative path nodes.") tail = head return path