ó
HVc           @   s?   d  Z  d e f d     YZ d e f d     YZ d   Z d S(   sC   
toposort.py
Sorts dictionary keys based on lists of dependencies.
t   MissingDependencyc           B   s   e  Z d  Z RS(   sC   Exception raised when a listed dependency is not in the dictionary.(   t   __name__t
   __module__t   __doc__(    (    (    s   ../tools/toposort.pyR       s   t   Sorterc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s"   | |  _  t   |  _ d |  _ d  S(   N(    (   t   dependenciest   sett   visitedt   sorted(   t   selfR   (    (    s   ../tools/toposort.pyt   __init__
   s    	c         C   s(   x |  j  D] } |  j |  q
 W|  j S(   N(   R   t   _visitR   (   R	   t   key(    (    s   ../tools/toposort.pyt   sort   s    c         C   s~   | |  j  k rz |  j  j |  |  j j |  s@ t |   n  x" |  j | D] } |  j |  qN W|  j | f 7_ n  d  S(   N(   R   t   addR   t   has_keyR    R   R   (   R	   R   t   depends(    (    s   ../tools/toposort.pyR      s    (   R   R   R
   R   R   (    (    (    s   ../tools/toposort.pyR   	   s   		c         C   s   t  |   } | j   S(   sŐ   Returns a tuple of the dependencies dictionary keys sorted by entries
    in the dependency lists.  Given circular dependencies, sort will impose
    an order.  Raises MissingDependency if a key is not found.
    (   R   R   (   R   t   s(    (    s   ../tools/toposort.pyt   toposort   s    N(   R   t	   ExceptionR    t   objectR   R   (    (    (    s   ../tools/toposort.pyt   <module>   s   