
    k"gc                         d dl Z ddlmZ  G d de      Z G d dej
                        Z G d d	e      Z G d
 de      Zd Z	y)    N   )collections_abcc                   X    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)DirectedGraphz&A graph structure with directed edges.c                 >    t               | _        i | _        i | _        y N)set	_vertices	_forwards
_backwardsselfs    W/var/www/html/djangosite/lib/python3.12/site-packages/pip/_vendor/resolvelib/structs.py__init__zDirectedGraph.__init__	   s        c                 ,    t        | j                        S r   )iterr
   r   s    r   __iter__zDirectedGraph.__iter__       DNN##r   c                 ,    t        | j                        S r   )lenr
   r   s    r   __len__zDirectedGraph.__len__   s    4>>""r   c                     || j                   v S r   )r
   r   keys     r   __contains__zDirectedGraph.__contains__   s    dnn$$r   c                 V   t               }t        | j                        |_        | j                  j	                         D ci c]  \  }}|t        |       c}}|_        | j
                  j	                         D ci c]  \  }}|t        |       c}}|_        |S c c}}w c c}}w )z$Return a shallow copy of this graph.)r   r	   r
   r   itemsr   )r   otherkvs       r   copyzDirectedGraph.copy   s~    dnn-151E1E1GHA1c!f9H26//2G2G2IJ$!QAs1vIJ IJs   B>B%c                     || j                   v rt        d      | j                   j                  |       t               | j                  |<   t               | j
                  |<   y)zAdd a new vertex to the graph.zvertex existsN)r
   
ValueErroraddr	   r   r   r   s     r   r%   zDirectedGraph.add   sK    $.. _--3!es"ur   c                 2   | j                   j                  |       | j                  j                  |      D ]   }| j                  |   j                  |       " | j                  j                  |      D ]   }| j                  |   j                  |       " y)zCRemove a vertex from the graph, disconnecting all edges from/to it.N)r
   remover   popr   )r   r   fts       r   r'   zDirectedGraph.remove'   s~    c"##C( 	+AOOA%%c*	+$$S) 	*ANN1$$S)	*r   c                 J    || j                   |   v xr || j                  |   v S r   )r   r   r   r)   r*   s      r   	connectedzDirectedGraph.connected/   s)    DOOA&&A1q0A+AAr   c                     || j                   vrt        |      | j                  |   j                  |       | j                  |   j                  |       y)zgConnect two existing vertices.

        Nothing happens if the vertices are already connected.
        N)r
   KeyErrorr   r%   r   r,   s      r   connectzDirectedGraph.connect2   sH    
 DNN"1+qa q!r   c              #   j   K   | j                   j                         D ]  \  }}|D ]  }||f 
  y wr   )r   r   )r   r)   childrenr*   s       r   
iter_edgeszDirectedGraph.iter_edges<   s>     >>//1 	KAx d
	s   13c                 2    t        | j                  |         S r   )r   r   r   s     r   iter_childrenzDirectedGraph.iter_childrenA   s    DNN3'((r   c                 2    t        | j                  |         S r   )r   r   r   s     r   iter_parentszDirectedGraph.iter_parentsD   s    DOOC())r   N)__name__
__module____qualname____doc__r   r   r   r   r"   r%   r'   r-   r0   r3   r5   r7    r   r   r   r      sB    0
$#%%*B"
)*r   r   c                   <    e Zd Zd	dZd Zd ZeZd Zd Zd Z	d Z
y)
IteratorMappingNc                 6    || _         || _        |xs i | _        y r   )_mapping	_accessor_appends)r   mappingaccessorappendss       r   r   zIteratorMapping.__init__I   s    !2r   c                 d    dj                  | j                  | j                  | j                        S )Nz!IteratorMapping({!r}, {!r}, {!r}))formatr@   rA   rB   r   s    r   __repr__zIteratorMapping.__repr__N   s*    299MMNNMM
 	
r   c                 H    t        | j                  xs | j                        S r   )boolr@   rB   r   s    r   __bool__zIteratorMapping.__bool__U   s    DMM2T]]33r   c                 >    || j                   v xs || j                  v S r   )r@   rB   r   s     r   r   zIteratorMapping.__contains__Z   s    dmm#;sdmm';;r   c                     	 | j                   |   }t	        j
                  | j                  |      | j                  j                  |d            S # t        $ r t        | j                  |         cY S w xY w)Nr<   )r@   r/   r   rB   	itertoolschainrA   get)r   r    r!   s      r   __getitem__zIteratorMapping.__getitem__]   sg    	*a A t~~a0$--2C2CAr2JKK  	*a())	*s   A !A43A4c                 n      fd j                   D        }t        j                   j                  |      S )Nc              3   @   K   | ]  }|j                   vs|  y wr   r@   .0r    r   s     r   	<genexpr>z+IteratorMapping.__iter__.<locals>.<genexpr>e   s     CaAT]],BC   )rB   rN   rO   r@   r   mores   ` r   r   zIteratorMapping.__iter__d   s&    C4==Ct}}d33r   c                 p     t         fd j                  D              }t         j                        |z   S )Nc              3   @   K   | ]  }|j                   vsd   yw)r   NrT   rU   s     r   rW   z*IteratorMapping.__len__.<locals>.<genexpr>i   s     Fq/E1FrX   )sumrB   r   r@   rY   s   ` r   r   zIteratorMapping.__len__h   s+    FdmmFF4==!D((r   r   )r8   r9   r:   r   rH   rK   __nonzero__r   rQ   r   r   r<   r   r   r>   r>   H   s-    &

4 K<L4)r   r>   c                   ,    e Zd ZdZd Zd Zd ZeZd Zy)_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                      || _         d | _        y r   )_factory	_iterable)r   factorys     r   r   z_FactoryIterableView.__init__v   s    r   c                 ^    dj                  t        |       j                  t        |             S Nz{}({}))rG   typer8   listr   s    r   rH   z_FactoryIterableView.__repr__z   s!    tDz22DJ??r   c                 L    	 t        t        |              y# t        $ r Y yw xY w)NFT)nextr   StopIterationr   s    r   rK   z_FactoryIterableView.__bool__}   s,    	d   		s    	##c                     | j                   | j                         n| j                   }t        j                  |      \  | _         }|S r   )rc   rb   rN   tee)r   iterablecurrents      r   r   z_FactoryIterableView.__iter__   s;    #~~5DMMO4>> 	 #,--"9r   N	r8   r9   r:   r;   r   rH   rK   r^   r   r<   r   r   r`   r`   m   s#    @ Kr   r`   c                   ,    e Zd ZdZd Zd Zd ZeZd Zy)_SequenceIterableViewzWrap an iterable returned by find_matches().

    This is essentially just a proxy to the underlying sequence that provides
    the same interface as `_FactoryIterableView`.
    c                     || _         y r   )	_sequence)r   sequences     r   r   z_SequenceIterableView.__init__   s	    !r   c                 `    dj                  t        |       j                  | j                        S rf   )rG   rg   r8   rt   r   s    r   rH   z_SequenceIterableView.__repr__   s!    tDz22DNNCCr   c                 ,    t        | j                        S r   )rJ   rt   r   s    r   rK   z_SequenceIterableView.__bool__   r   r   c                 ,    t        | j                        S r   )r   rt   r   s    r   r   z_SequenceIterableView.__iter__   r   r   Nrp   r<   r   r   rr   rr      s#    "D$ K$r   rr   c                     t        |       rt        |       S t        | t        j                        st        |       } t        |       S )zCBuild an iterable view from the value returned by `find_matches()`.)callabler`   
isinstancer   Sequencerh   rr   )matchess    r   build_iter_viewr~      s9    #G,,g778w- ))r   )
rN   compatr   objectr   Mappingr>   r`   rr   r~   r<   r   r   <module>r      sI     #?*F ?*D")o-- ")J6 B$F $,*r   