3
๔มgบ  ใ               @   sb   d dl Z ddlmZ G dd deZG dd dejZG dd	 d	eZG d
d deZdd Z	dS )้    N้   )ฺcollections_abcc               @   sp   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
   ๚\/var/www/tester-filtro-web/env/lib/python3.6/site-packages/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   sB   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S r
   )r   )ฺ.0ฺkฺvr
   r
   r   ๚
<dictcomp>   s    z&DirectedGraph.copy.<locals>.<dictcomp>c             S   s   i | ]\}}t ||qS r
   )r   )r   r   r   r
   r
   r   r      s    )r   r   r   r   ฺitemsr   )r	   ฺotherr
   r
   r   ฺcopy   s
    zDirectedGraph.copyc             C   s:   || 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   s\   | j j| x$| jj|D ]}| j| j| qW x$| jj|D ]}| j| j| q@W d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   s6   || 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   ฺconnect2   s    
zDirectedGraph.connectc             c   s4   x.| j j D ] \}}x|D ]}||fV  qW qW d 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_childrenA   s    zDirectedGraph.iter_childrenc             C   s   t | j| S )N)r   r   )r	   r   r
   r
   r   ฺiter_parentsD   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               @   sJ   e Zd Zd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 )ฺIteratorMappingNc             C   s   || _ || _|pi | _d S )N)ฺ_mappingฺ	_accessorฺ_appends)r	   ฺmappingฺaccessorZappendsr
   r
   r   r   I   s    zIteratorMapping.__init__c             C   s   dj | j| j| jS )Nz!IteratorMapping({!r}, {!r}, {!r}))ฺformatr,   r-   r.   )r	   r
   r
   r   ฺ__repr__N   s    zIteratorMapping.__repr__c             C   s   t | jp| jS )N)ฺboolr,   r.   )r	   r
   r
   r   ฺ__bool__U   s    zIteratorMapping.__bool__c             C   s   || j kp|| jkS )N)r,   r.   )r	   r   r
   r
   r   r   Z   s    zIteratorMapping.__contains__c             C   sJ   y| j | }W n tk
r,   t| j| S X tj| j|| jj|f S )N)r,   r!   r   r.   ฺ	itertoolsฺchainr-   ฺget)r	   r   r   r
   r
   r   ฺ__getitem__]   s
    zIteratorMapping.__getitem__c                s"    fdd j D }tj j|S )Nc             3   s   | ]}| j kr|V  qd S )N)r,   )r   r   )r	   r
   r   ๚	<genexpr>e   s    z+IteratorMapping.__iter__.<locals>.<genexpr>)r.   r5   r6   r,   )r	   ฺmorer
   )r	   r   r   d   s    zIteratorMapping.__iter__c                s&   t  fdd jD }t j| S )Nc             3   s   | ]}| j krd V  qdS )r   N)r,   )r   r   )r	   r
   r   r9   i   s    z*IteratorMapping.__len__.<locals>.<genexpr>)ฺsumr.   r   r,   )r	   r:   r
   )r	   r   r   h   s    zIteratorMapping.__len__)N)r'   r(   r)   r   r2   r4   ฺ__nonzero__r   r8   r   r   r
   r
   r
   r   r+   H   s   
r+   c               @   s4   e Zd ZdZdd Zdd Zdd Ze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   v   s    z_FactoryIterableView.__init__c             C   s   dj t| jt| j S )Nz{}({}))r1   ฺtyper'   ฺlistr>   )r	   r
   r
   r   r2   y   s    z_FactoryIterableView.__repr__c             C   s*   yt | j  W n tk
r$   dS X dS )NFT)ฺnextr>   ฺStopIteration)r	   r
   r
   r   r4   |   s
    z_FactoryIterableView.__bool__c             C   s   | j  S )N)r>   )r	   r
   r
   r   r      s    z_FactoryIterableView.__iter__N)	r'   r(   r)   r*   r   r2   r4   r<   r   r
   r
   r
   r   r=   m   s   r=   c               @   s4   e Zd ZdZdd Zdd Zdd Ze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      s    z_SequenceIterableView.__init__c             C   s   dj t| j| jS )Nz{}({}))r1   r@   r'   rE   )r	   r
   r
   r   r2      s    z_SequenceIterableView.__repr__c             C   s
   t | jS )N)r3   rE   )r	   r
   r
   r   r4      s    z_SequenceIterableView.__bool__c             C   s
   t | jS )N)r   rE   )r	   r
   r
   r   r      s    z_SequenceIterableView.__iter__N)	r'   r(   r)   r*   r   r2   r4   r<   r   r
   r
   r
   r   rD      s   rD   c             C   s,   t | rt| S t| tjs$t| } t| S )zCBuild an iterable view from the value returned by `find_matches()`.)ฺcallabler=   ฺ
isinstancer   ฺSequencerA   rD   )ฺmatchesr
   r
   r   ฺbuild_iter_view   s
    rK   )
r5   ฺcompatr   ฺobjectr   ฺMappingr+   r=   rD   rK   r
   r
   r
   r   ฺ<module>   s   B%