
(ฐh8  ใ               @   sb   d  d l  m Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z d d	   Z d
 S)้   )ฺcollections_abcc               @   sฆ   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d S)ฺDirectedGraphz&A graph structure with directed edges.c             C   s"   t    |  _ i  |  _ i  |  _ d  S)N)ฺsetฺ	_verticesฺ	_forwardsฺ
_backwards)ฺselfฉ r	   ๚=/tmp/pip-build-kmztzv_d/pip/pip/_vendor/resolvelib/structs.pyฺ__init__   s    	zDirectedGraph.__init__c             C   s   t  |  j  S)N)ฺiterr   )r   r	   r	   r
   ฺ__iter__   s    zDirectedGraph.__iter__c             C   s   t  |  j  S)N)ฺlenr   )r   r	   r	   r
   ฺ__len__   s    zDirectedGraph.__len__c             C   s   | |  j  k S)N)r   )r   ฺkeyr	   r	   r
   ฺ__contains__   s    zDirectedGraph.__contains__c             C   s]   t    } t |  j  | _ d d   |  j j   D | _ d d   |  j j   D | _ | S)z$Return a shallow copy of this graph.c             S   s%   i  |  ] \ } } t  |  |  q Sr	   )r   )ฺ.0ฺkฺvr	   r	   r
   ๚
<dictcomp>   s   	 z&DirectedGraph.copy.<locals>.<dictcomp>c             S   s%   i  |  ] \ } } t  |  |  q Sr	   )r   )r   r   r   r	   r	   r
   r      s   	 )r   r   r   r   ฺitemsr   )r   ฺotherr	   r	   r
   ฺcopy   s
    	zDirectedGraph.copyc             C   sO   | |  j  k r t d   |  j  j |  t   |  j | <t   |  j | <d S)zAdd a new vertex to the graph.zvertex existsN)r   ฺ
ValueErrorฺaddr   r   r   )r   r   r	   r	   r
   r      s
    zDirectedGraph.addc             C   sv   |  j  j |  x. |  j j |  D] } |  j | j |  q# Wx. |  j j |  D] } |  j | j |  qT Wd S)zCRemove a vertex from the graph, disconnecting all edges from/to it.N)r   ฺremover   ฺpopr   )r   r   ฺfฺtr	   r	   r
   r   %   s
    zDirectedGraph.removec             C   s$   | |  j  | k o# | |  j | k S)N)r   r   )r   r   r   r	   r	   r
   ฺ	connected-   s    zDirectedGraph.connectedc             C   sG   | |  j  k r t |   |  j | j |  |  j | j |  d S)zgConnect two existing vertices.

        Nothing happens if the vertices are already connected.
        N)r   ฺKeyErrorr   r   r   )r   r   r   r	   r	   r
   ฺconnect0   s    zDirectedGraph.connectc             c   s@   x9 |  j  j   D]( \ } } x | D] } | | f Vq# Wq Wd  S)N)r   r   )r   r   ฺchildrenr   r	   r	   r
   ฺ
iter_edges:   s    zDirectedGraph.iter_edgesc             C   s   t  |  j |  S)N)r   r   )r   r   r	   r	   r
   ฺiter_children?   s    zDirectedGraph.iter_childrenc             C   s   t  |  j |  S)N)r   r   )r   r   r	   r	   r
   ฺiter_parentsB   s    zDirectedGraph.iter_parentsN)ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__r   r   r   r   r   r   r   r   r!   r#   r$   r%   r	   r	   r	   r
   r      s   
r   c               @   sd   e  Z d  Z d Z d d   Z d d   Z d d   Z e Z d d	   Z d
 d   Z	 d d   Z
 d S)ฺ_FactoryIterableViewa:  Wrap an iterator factory returned by `find_matches()`.

    Calling `iter()` on this class would invoke the underlying iterator
    factory, making it a "collection with ordering" that can be iterated
    through multiple times, but lacks random access methods presented in
    built-in Python sequence types.
    c             C   s   | |  _  d  S)N)ฺ_factory)r   ฺfactoryr	   r	   r
   r   O   s    z_FactoryIterableView.__init__c             C   s%   d j  t |   j t |  j     S)Nz{}({}))ฺformatฺtyper&   ฺlistr+   )r   r	   r	   r
   ฺ__repr__R   s    z_FactoryIterableView.__repr__c             C   s1   y t  |  j    Wn t k
 r, d SYn Xd S)NFT)ฺnextr+   ฺStopIteration)r   r	   r	   r
   ฺ__bool__U   s
    	z_FactoryIterableView.__bool__c             C   s
   |  j    S)N)r+   )r   r	   r	   r
   r   ^   s    z_FactoryIterableView.__iter__c             C   s
   |  j    S)z4Provide an candidate iterable for `get_preference()`)r+   )r   r	   r	   r
   ฺfor_preferencea   s    z#_FactoryIterableView.for_preferencec                s%      f d d   } t    |  S)z5Create a new instance excluding specified candidates.c                  s     f d d    j    D S)Nc             3   s!   |  ] } |   k r | Vq d  S)Nr	   )r   ฺc)ฺ
candidatesr	   r
   ๚	<genexpr>i   s    zB_FactoryIterableView.excluding.<locals>.factory.<locals>.<genexpr>)r+   r	   )r6   r   r	   r
   r,   h   s    z/_FactoryIterableView.excluding.<locals>.factory)r.   )r   r6   r,   r	   )r6   r   r
   ฺ	excludinge   s    z_FactoryIterableView.excludingN)r&   r'   r(   r)   r   r0   r3   ฺ__nonzero__r   r4   r8   r	   r	   r	   r
   r*   F   s   r*   c               @   sp   e  Z d  Z d Z d d   Z d d   Z d d   Z e Z d d	   Z d
 d   Z	 d d   Z
 d d   Z d S)ฺ_SequenceIterableViewzฒWrap an iterable returned by find_matches().

    This is essentially just a proxy to the underlying sequence that provides
    the same interface as `_FactoryIterableView`.
    c             C   s   | |  _  d  S)N)ฺ	_sequence)r   ฺsequencer	   r	   r
   r   u   s    z_SequenceIterableView.__init__c             C   s   d j  t |   j |  j  S)Nz{}({}))r-   r.   r&   r;   )r   r	   r	   r
   r0   x   s    z_SequenceIterableView.__repr__c             C   s   t  |  j  S)N)ฺboolr;   )r   r	   r	   r
   r3   {   s    z_SequenceIterableView.__bool__c             C   s   t  |  j  S)N)r   r;   )r   r	   r	   r
   r      s    z_SequenceIterableView.__iter__c             C   s   t  |  j  S)N)r   r;   )r   r	   r	   r
   r      s    z_SequenceIterableView.__len__c             C   s   |  j  S)z4Provide an candidate iterable for `get_preference()`)r;   )r   r	   r	   r
   r4      s    z$_SequenceIterableView.for_preferencec                s&   t  |     f d d   |  j D  S)z5Create a new instance excluding specified candidates.c                s"   g  |  ] } |   k r |  q Sr	   r	   )r   r5   )r6   r	   r
   ๚
<listcomp>   s   	 z3_SequenceIterableView.excluding.<locals>.<listcomp>)r.   r;   )r   r6   r	   )r6   r
   r8      s    z_SequenceIterableView.excludingN)r&   r'   r(   r)   r   r0   r3   r9   r   r   r4   r8   r	   r	   r	   r
   r:   n   s   r:   c             C   s>   t  |   r t |   St |  t j  s4 t |   }  t |   S)zCBuild an iterable view from the value returned by `find_matches()`.)ฺcallabler*   ฺ
isinstancer   ฺSequencer/   r:   )ฺmatchesr	   r	   r
   ฺbuild_iter_view   s
    
rC   N)ฺcompatr   ฺobjectr   r*   r:   rC   r	   r	   r	   r
   ฺ<module>   s   B(!