def read(string):
dotG = pydot.graph_from_dot_data(string)<EOL>if (dotG.get_type() == "<STR_LIT>"):<EOL><INDENT>G = graph()<EOL><DEDENT>elif (dotG.get_type() == "<STR_LIT>"):<EOL><INDENT>G = digraph()<EOL><DEDENT>elif (dotG.get_type() == "<STR_LIT>"):<EOL><INDENT>return read_hypergraph(string)<EOL><DEDENT>else:<EOL><INDENT>raise InvalidGraphType<EOL><DEDENT>for each_node in dotG.get_nodes():<EOL><INDENT>G.add_node(each_node.get_name())<EOL>for each_attr_key, each_attr_val in each_node.get_attributes().items():<EOL><INDENT>G.add_node_attribute(each_node.get_name(), (each_attr_key, each_attr_val))<EOL><DEDENT><DEDENT>for each_edge in dotG.get_edges():<EOL><INDENT>if not G.has_node(each_edge.get_source()):<EOL><INDENT>G.add_node(each_edge.get_source())<EOL><DEDENT>if not G.has_node(each_edge.get_destination()):<EOL><INDENT>G.add_node(each_edge.get_destination())<EOL><DEDENT>if '<STR_LIT>' in each_edge.get_attributes().keys():<EOL><INDENT>_wt = each_edge.get_attributes()['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>_wt = <NUM_LIT:1><EOL><DEDENT>if '<STR_LIT:label>' in each_edge.get_attributes().keys():<EOL><INDENT>_label = each_edge.get_attributes()['<STR_LIT:label>']<EOL><DEDENT>else:<EOL><INDENT>_label = '<STR_LIT>'<EOL><DEDENT>G.add_edge((each_edge.get_source(), each_edge.get_destination()), wt = _wt, label = _label)<EOL>for each_attr_key, each_attr_val in each_edge.get_attributes().items():<EOL><INDENT>if not each_attr_key in ['<STR_LIT>', '<STR_LIT:label>']:<EOL><INDENT>G.add_edge_attribute((each_edge.get_source(), each_edge.get_destination()),(each_attr_key, each_attr_val))<EOL><DEDENT><DEDENT><DEDENT>return G<EOL>
Read a graph from a string in Dot language and return it. Nodes and edges specified in the
input will be added to the current graph.

@type  string: string
@param string: Input string in Dot format specifying a graph.

@rtype: graph
@return: Graph