B
    oºˆdc  ã               @   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
   úP/var/www/html/venv/lib/python3.7/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 ¡ D ƒ|_dd„ | 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  |¡ 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  |¡ x$| j |¡D ]}| j|  |¡ qW x$| j |¡D ]}| 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|  |¡ 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  ¡ 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ÚaccessorÚappendsr
   r
   r   r   I   s    zIteratorMapping.__init__c             C   s   d  | 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 |d¡¡S )Nr
   )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|¡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.   r6   r7   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   r:   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   r3   r5   Ú__nonzero__r   r9   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 | _d S )N)Ú_factoryÚ	_iterable)r	   Úfactoryr
   r
   r   r   v   s    z_FactoryIterableView.__init__c             C   s   d  t| ƒjt| ƒ¡S )Nz{}({}))r2   Útyper'   Úlist)r	   r
   r
   r   r3   z   s    z_FactoryIterableView.__repr__c             C   s*   yt t| ƒƒ W n tk
r$   dS X dS )NFT)Únextr   ÚStopIteration)r	   r
   r
   r   r5   }   s
    z_FactoryIterableView.__bool__c             C   s,   | j d kr|  ¡ n| j }t |¡\| _ }|S )N)r@   r?   r6   Útee)r	   ÚiterableÚcurrentr
   r
   r   r   †   s    z_FactoryIterableView.__iter__N)	r'   r(   r)   r*   r   r3   r5   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  t| ƒj| j¡S )Nz{}({}))r2   rB   r'   rJ   )r	   r
   r
   r   r3   ˜   s    z_SequenceIterableView.__repr__c             C   s
   t | jƒS )N)r4   rJ   )r	   r
   r
   r   r5   ›   s    z_SequenceIterableView.__bool__c             C   s
   t | jƒS )N)r   rJ   )r	   r
   r
   r   r       s    z_SequenceIterableView.__iter__N)	r'   r(   r)   r*   r   r3   r5   r=   r   r
   r
   r
   r   rI   Ž   s   rI   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   ÚSequencerC   rI   )Úmatchesr
   r
   r   Úbuild_iter_view¤   s
    rP   )
r6   Úcompatr   Úobjectr   ÚMappingr+   r>   rI   rP   r
   r
   r
   r   Ú<module>   s   B%!