f = open(filename, 'r')
graph = [[]]
while True:
    line = f.readline()
if not line:
    break
if declare_new_graph(line):
    graph.append([])
graph[-1].append(line)
str = '\n'.join(graph[i])
parse multiple digraph in one dot file