def reverse(self):
assert self.DIRECTED, "<STR_LIT>" % self.__class__.__name__<EOL>N = self.__class__()<EOL>N.add_nodes( n for n in self.nodes() )<EOL>for (u, v) in self.edges():<EOL><INDENT>wt = self.edge_weight((u, v))<EOL>label = self.edge_label((u, v))<EOL>attributes = self.edge_attributes((u, v))<EOL>N.add_edge((v, u), wt, label, attributes)<EOL><DEDENT>return N<EOL>
Generate the reverse of a directed graph, returns an identical graph if not directed.
Attributes & weights are preserved.

@rtype: digraph
@return: The directed graph that should be reversed.