Ñò Š„[Jc @ s¤ d Z d d k l Z d d k l Z d d d g Z d „ Z d „ Z e d „ Z d e f d „ ƒ YZ d e f d „ ƒ YZ e e d „ Z d „ Z d „ Z d S( sM Topological sorting algorithms. The topological sort is an algorithm that receives this list of dependencies as a *partial ordering*, that is a list of pairs which might say, *X is dependent on Y*, *Q is dependent on Z*, but does not necessarily tell you anything about Q being dependent on X. Therefore, its not a straight sort where every element can be compared to another... only some of the elements have any sorting preference, and then only towards just some of the other elements. For a particular partial ordering, there can be many possible sorts that satisfy the conditions. iÿÿÿÿ( t CircularDependencyError( t utilt sortt sort_with_cyclest sort_as_treec C s7 g } t | | d t d t ƒD] } | | i q ~ S( sw sort the given list of items by dependency. 'tuples' is a list of tuples representing a partial ordering. t allow_cyclest ignore_self_cycles( t _sortt Falset Truet item( t tuplest allitemst _[1]t n( ( s: /usr/lib/python2.6/site-packages/sqlalchemy/topological.pyR s c C s_ g } t | | d t ƒD]> } | | i g } | i p g D] } | | i q> ~ f q ~ S( s! sort the given list of items by dependency, cutting out cycles. returns results as an iterable of 2-tuples, containing the item, and a list containing items involved in a cycle with this item, if any. 'tuples' is a list of tuples representing a partial ordering. R ( R R R t cycles( R R R R t _[2]( ( s: /usr/lib/python2.6/site-packages/sqlalchemy/topological.pyR " s c C s t t | | d | ƒƒ S( s sort the given list of items by dependency, and return results as a hierarchical tree structure. returns results as an iterable of 3-tuples, containing the item, a list containing items involved in a cycle with this item, if any, and a list of child tuples. if with_cycles is False, the returned structure is of the same form but the second element of each tuple, i.e. the 'cycles', is an empty list. 'tuples' is a list of tuples representing a partial ordering. R ( t _organize_as_treeR ( R R t with_cycles( ( s: /usr/lib/python2.6/site-packages/sqlalchemy/topological.pyR - s t _Nodec B s> e Z d Z d „ Z d „ Z d d „ Z d „ Z d „ Z RS( s Represent each item in the sort.c C s+ | | _ t ƒ | _ g | _ d | _ d S( N( R t sett dependenciest childrent NoneR ( t selfR ( ( s: /usr/lib/python2.6/site-packages/sqlalchemy/topological.pyt __init__A s c C s | i ƒ S( N( t safestr( R ( ( s: /usr/lib/python2.6/site-packages/sqlalchemy/topological.pyt __str__G s i c C s~ d | d t | i ƒ | i d j o3 d t g } | i D] } | | q<