#NEWLINE# def _topological_sort( data , head , top_node , raise_exception = False , result = None , visited = None ) : #NEWLINE# #INDENT# ' Internal function\n    ' #NEWLINE# if ( not result ) : #NEWLINE# #INDENT# result = [ ] #NEWLINE# #UNINDENT# if ( not visited ) : #NEWLINE# #INDENT# visited = [ ] #NEWLINE# #UNINDENT# deps = data . get ( head , list ( ) ) #NEWLINE# if ( head in visited ) : #NEWLINE# #INDENT# if ( ( head == top_node ) and raise_exception ) : #NEWLINE# #INDENT# raise DagError ( head , head , result ) #NEWLINE# #UNINDENT# return result #NEWLINE# #UNINDENT# visited . append ( head ) #NEWLINE# for i in deps : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result . index ( i ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# result = _topological_sort ( data , i , data , raise_exception , result , visited ) #NEWLINE# #UNINDENT# #UNINDENT# result . append ( head ) #NEWLINE# return result