#NEWLINE# def from_agraph( A , create_using = None ) : #NEWLINE# #INDENT# 'Return a NetworkX Graph or DiGraph from a PyGraphviz graph.\n\n    Parameters\n    ----------\n    A : PyGraphviz AGraph\n      A graph created with PyGraphviz\n\n    create_using : NetworkX graph class instance\n      The output is created using the given graph class instance\n\n    Examples\n    --------\n    >>> K5=nx.complete_graph(5)\n    >>> A=nx.to_agraph(K5)\n    >>> G=nx.from_agraph(A)\n    >>> G=nx.from_agraph(A)\n\n\n    Notes\n    -----\n    The Graph G will have a dictionary G.graph_attr containing\n    the default graphviz attributes for graphs, nodes and edges.\n\n    Default node attributes will be in the dictionary G.node_attr\n    which is keyed by node.\n\n    Edge attributes will be returned as edge data in G.  With\n    edge_attr=False the edge data will be the Graphviz edge weight\n    attribute or the value 1 if no edge weight attribute is found.\n\n    ' #NEWLINE# if ( create_using is None ) : #NEWLINE# #INDENT# if A . is_directed ( ) : #NEWLINE# #INDENT# if A . is_strict ( ) : #NEWLINE# #INDENT# create_using = nx . DiGraph ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# create_using = nx . MultiDiGraph ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if A . is_strict ( ) : #NEWLINE# #INDENT# create_using = nx . Graph ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# create_using = nx . MultiGraph ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# N = nx . empty_graph ( 0 , str_attr ) #NEWLINE# N . name = '' #NEWLINE# if ( A . name is not None ) : #NEWLINE# #INDENT# N . name = A . name #NEWLINE# #UNINDENT# for n in A . nodes ( ) : #NEWLINE# #INDENT# str_attr = dict ( ( ( str ( k ) , v ) for ( k , v ) in n . attr . items ( ) ) ) #NEWLINE# N . add_node ( str ( n ) , ** str_attr ) #NEWLINE# #UNINDENT# for e in A . edges ( ) : #NEWLINE# #INDENT# ( u , v ) = ( str ( e [ 0 ] ) , str ( e [ 1 ] ) ) #NEWLINE# attr = dict ( e . attr ) #NEWLINE# str_attr = dict ( ( ( str ( k ) , v ) for ( k , v ) in attr . items ( ) ) ) #NEWLINE# if ( not N . is_multigraph ( ) ) : #NEWLINE# #INDENT# if ( e . name is not None ) : #NEWLINE# #INDENT# str_attr [ 'key' ] = e . name #NEWLINE# #UNINDENT# N . add_edge ( u , v , ** str_attr ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# N . add_edge ( u , v , key = e . name , ** str_attr ) #NEWLINE# #UNINDENT# #UNINDENT# N . graph [ 'graph' ] = dict ( A . graph_attr ) #NEWLINE# N . graph [ 'node' ] = dict ( A . node_attr ) #NEWLINE# N . graph [ 'edge' ] = dict ( A . edge_attr ) #NEWLINE# return N