#NEWLINE# def getclasstree( classes , unique = 0 ) : #NEWLINE# #INDENT# "Arrange the given list of classes into a hierarchy of nested lists.\n\n    Where a nested list appears, it contains classes derived from the class\n    whose entry immediately precedes the list.  Each entry is a 2-tuple\n    containing a class and a tuple of its base classes.  If the 'unique'\n    argument is true, exactly one entry appears in the returned structure\n    for each class in the given list.  Otherwise, classes using multiple\n    inheritance and their descendants will appear multiple times." #NEWLINE# children = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# roots = [ ] #NEWLINE# for c in classes : #NEWLINE# #INDENT# if c . __bases__ : #NEWLINE# #INDENT# for parent in c . __bases__ : #NEWLINE# #INDENT# if ( not ( parent in children ) ) : #NEWLINE# #INDENT# children [ parent ] = [ ] #NEWLINE# #UNINDENT# children [ parent ] . append ( c ) #NEWLINE# if ( unique and ( parent in classes ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( c not in roots ) : #NEWLINE# #INDENT# roots . append ( c ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for parent in children : #NEWLINE# #INDENT# if ( parent not in classes ) : #NEWLINE# #INDENT# roots . append ( parent ) #NEWLINE# #UNINDENT# #UNINDENT# return walktree ( roots , children , None )