@@ -0,0 +1,2964 @@
+import networkx as nx%0D%0A%0D%0A# from gml_read import read_gml2%0D%0A# g = read_gml2(%22steiner-small.gml%22)%0D%0A%0D%0Adef read_gml2(path):%0D%0A%0D%0A    # Read file lines%0D%0A    f = open(path)%0D%0A    lines = f.readlines()%0D%0A    f.close()%0D%0A%0D%0A    # Split lines into symbols%0D%0A    syms = %5B%5D%0D%0A    for line in lines:%0D%0A        line = line.strip().split(' ')%0D%0A        if len(line) != 0 and line%5B0%5D == '#': # skip comments%0D%0A            continue%0D%0A        for sym in line:%0D%0A            syms.append(sym)%0D%0A    n_syms = len(syms)%0D%0A%0D%0A    # Find node labeled 'graph'%0D%0A    has_graph = False%0D%0A    i_sym = 0%0D%0A    while not has_graph and i_sym %3C n_syms:%0D%0A        sym = syms%5Bi_sym%5D%0D%0A        i_sym += 1%0D%0A        if sym == 'graph':%0D%0A            has_graph = True%0D%0A            break%0D%0A%0D%0A    if not has_graph:%0D%0A        print (%22Couldn't find a graph%22)%0D%0A        return%0D%0A%0D%0A    G = nx.Graph()%0D%0A%0D%0A    # Recurse the graph structure%0D%0A    level = 0%0D%0A    expect_value = True%0D%0A    attribs = %7B1:G.graph%7D%0D%0A    current_node = None%0D%0A    current_edge = None%0D%0A    while level %3E= 0 and i_sym %3C n_syms:%0D%0A        sym = syms%5Bi_sym%5D%0D%0A        if expect_value:%0D%0A            value = None%0D%0A            if sym == '%5B':       # list%0D%0A                level += 1%0D%0A            elif sym%5B0%5D == '%5C%22': # string%0D%0A                value = sym%0D%0A                while syms%5Bi_sym%5D%5B-1%5D != '%5C%22':%0D%0A                    i_sym += 1%0D%0A                    value += ' ' + syms%5Bi_sym%5D%0D%0A                value = value%5B1:-1%5D%0D%0A            elif '.' in sym:%0D%0A                value = float(sym)%0D%0A            else:%0D%0A                value = int(sym)%0D%0A            if value != None:%0D%0A                #if level not in attribs:%0D%0A                #    attribs%5Blevel%5D = %7B%7D%0D%0A                attribs%5Blevel%5D%5Bcurrent_key%5D = value%0D%0A            expect_value = False%0D%0A        else:%0D%0A            if sym == '%5D':       # list end%0D%0A                level -= 1%0D%0A                if level == 1:%0D%0A                    if current_node != None:%0D%0A                        id = current_node%5B'id'%5D%0D%0A                        current_node.pop('id', None)   # don't need id in attribs%0D%0A                        G.add_node(id, current_node)%0D%0A                        current_node = None%0D%0A                    elif current_edge != None:%0D%0A                        source = current_edge%5B'source'%5D%0D%0A                        target = current_edge%5B'target'%5D%0D%0A                        current_edge.pop('source', None)%0D%0A                        current_edge.pop('target', None)%0D%0A                        G.add_edge(source, target, current_edge)%0D%0A                        current_edge = None%0D%0A            else:%0D%0A                if level == 1:%0D%0A                    if sym == 'node':%0D%0A                        current_node = %7B%7D%0D%0A                        attribs%5Blevel + 1%5D = current_node%0D%0A                    elif sym == 'edge':%0D%0A                        current_edge = %7B%7D%0D%0A                        attribs%5Blevel + 1%5D = current_edge%0D%0A                current_key = sym%0D%0A                expect_value = True%0D%0A        i_sym += 1%0D%0A%0D%0A    return G%0D%0A

Add a fast GML reader (reads in seconds).