o
    &?e+                     @   s   d Z ddlmZ g dZG dd deZG dd deZG dd	 d	eZG d
d deZG dd deZG dd deZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZdS )zViews of core data structures such as nested Mappings (e.g. dict-of-dicts).
These ``Views`` often restrict element access, with either the entire view or
layers of nested mappings being read-only.
    )Mapping)	AtlasViewAdjacencyViewMultiAdjacencyView
UnionAtlasUnionAdjacencyUnionMultiInnerUnionMultiAdjacencyFilterAtlasFilterAdjacencyFilterMultiInnerFilterMultiAdjacencyc                   @   \   e Zd 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S )r   aH  An AtlasView is a Read-only Mapping of Mappings.

    It is a View into a dict-of-dict data structure.
    The inner level of dict is read-write. But the
    outer level is read-only.

    See Also
    ========
    AdjacencyView: View into dict-of-dict-of-dict
    MultiAdjacencyView: View into dict-of-dict-of-dict-of-dict
    _atlasc                 C   s
   d| j iS Nr   r   self r   [/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/networkx/classes/coreviews.py__getstate__%      
zAtlasView.__getstate__c                 C   s   |d | _ d S r   r   r   stater   r   r   __setstate__(      zAtlasView.__setstate__c                 C   s
   || _ d S Nr   )r   dr   r   r   __init__+   r   zAtlasView.__init__c                 C   
   t | jS r   )lenr   r   r   r   r   __len__.   r   zAtlasView.__len__c                 C   r   r   )iterr   r   r   r   r   __iter__1   r   zAtlasView.__iter__c                 C   s
   | j | S r   r   r   keyr   r   r   __getitem__4   r   zAtlasView.__getitem__c                        fdd j D S )Nc                       i | ]	}| |   qS r   copy.0nr   r   r   
<dictcomp>8       z"AtlasView.copy.<locals>.<dictcomp>r   r   r   r   r   r*   7      zAtlasView.copyc                 C   r   r   )strr   r   r   r   r   __str__:   r   zAtlasView.__str__c                 C   s   | j j d| jdS )N())	__class____name__r   r   r   r   r   __repr__=      zAtlasView.__repr__Nr6   
__module____qualname____doc__	__slots__r   r   r   r!   r#   r&   r*   r2   r7   r   r   r   r   r      s    r   c                   @   $   e Zd ZdZdZdd Zdd ZdS )r   aJ  An AdjacencyView is a Read-only Map of Maps of Maps.

    It is a View into a dict-of-dict-of-dict data structure.
    The inner level of dict is read-write. But the
    outer levels are read-only.

    See Also
    ========
    AtlasView: View into dict-of-dict
    MultiAdjacencyView: View into dict-of-dict-of-dict-of-dict
    r   c                 C      t | j| S r   )r   r   r   namer   r   r   r&   P   r   zAdjacencyView.__getitem__c                    r'   )Nc                    r(   r   r)   r+   r   r   r   r.   T   r/   z&AdjacencyView.copy.<locals>.<dictcomp>r   r   r   r   r   r*   S   r0   zAdjacencyView.copyNr6   r:   r;   r<   r=   r&   r*   r   r   r   r   r   A   
    r   c                   @   r>   )r   aR  An MultiAdjacencyView is a Read-only Map of Maps of Maps of Maps.

    It is a View into a dict-of-dict-of-dict-of-dict data structure.
    The inner level of dict is read-write. But the
    outer levels are read-only.

    See Also
    ========
    AtlasView: View into dict-of-dict
    AdjacencyView: View into dict-of-dict-of-dict
    r   c                 C   r?   r   )r   r   r@   r   r   r   r&   f   r   zMultiAdjacencyView.__getitem__c                    r'   )Nc                    r(   r   r)   r+   r   r   r   r.   j   r/   z+MultiAdjacencyView.copy.<locals>.<dictcomp>r   r   r   r   r   r*   i   r0   zMultiAdjacencyView.copyNrB   r   r   r   r   r   W   rC   r   c                   @   r   )r   a  A read-only union of two atlases (dict-of-dict).

    The two dict-of-dicts represent the inner dict of
    an Adjacency:  `G.succ[node]` and `G.pred[node]`.
    The inner level of dict of both hold attribute key:value
    pairs and is read-write. But the outer level is read-only.

    See Also
    ========
    UnionAdjacency: View into dict-of-dict-of-dict
    UnionMultiAdjacency: View into dict-of-dict-of-dict-of-dict
    _succ_predc                 C      | j | jdS NrD   rD   r   r   r   r   r   }   r   zUnionAtlas.__getstate__c                 C      |d | _ |d | _d S NrE   rF   rD   r   r   r   r   r         
zUnionAtlas.__setstate__c                 C      || _ || _d S r   rD   r   succpredr   r   r   r         
zUnionAtlas.__init__c                 C   s   t | j | j B S r   )r    rE   keysrF   r   r   r   r   r!         zUnionAtlas.__len__c                 C   s    t t| j t| j B S r   )r"   setrE   rQ   rF   r   r   r   r   r#      s    zUnionAtlas.__iter__c                 C   s*   z| j | W S  ty   | j|  Y S w r   )rE   KeyErrorrF   r$   r   r   r   r&      s
   zUnionAtlas.__getitem__c                 C   sP   dd | j  D }| j D ]\}}||v r|| | q| ||< q|S )Nc                 S   s   i | ]	\}}||  qS r   r)   )r,   nbrddr   r   r   r.      r/   z#UnionAtlas.copy.<locals>.<dictcomp>)rE   itemsrF   updater*   )r   resultrU   rV   r   r   r   r*      s   zUnionAtlas.copyc                       t  fdd D S )Nc                       i | ]}| | qS r   r   r,   rU   r   r   r   r.          z&UnionAtlas.__str__.<locals>.<dictcomp>r1   r   r   r   r   r2      r8   zUnionAtlas.__str__c                 C      | j j d| jd| jdS Nr3   z, r4   r5   r6   rE   rF   r   r   r   r   r7         zUnionAtlas.__repr__Nr9   r   r   r   r   r   m   s    	r   c                   @   r   )r   a3  A read-only union of dict Adjacencies as a Map of Maps of Maps.

    The two input dict-of-dict-of-dicts represent the union of
    `G.succ` and `G.pred`. Return values are UnionAtlas
    The inner level of dict is read-write. But the
    middle and outer levels are read-only.

    succ : a dict-of-dict-of-dict {node: nbrdict}
    pred : a dict-of-dict-of-dict {node: nbrdict}
    The keys for the two dicts should be the same

    See Also
    ========
    UnionAtlas: View into dict-of-dict
    UnionMultiAdjacency: View into dict-of-dict-of-dict-of-dict
    rD   c                 C   rG   rH   rD   r   r   r   r   r      r   zUnionAdjacency.__getstate__c                 C   rI   rJ   rD   r   r   r   r   r      rK   zUnionAdjacency.__setstate__c                 C   s4   t t| t| A dksJ || _|| _d S )Nr   )r    rS   rQ   rE   rF   rM   r   r   r   r      s   $
zUnionAdjacency.__init__c                 C   r   r   )r    rE   r   r   r   r   r!      r   zUnionAdjacency.__len__c                 C   r   r   )r"   rE   r   r   r   r   r#      r   zUnionAdjacency.__iter__c                 C      t | j| | j| S r   )r   rE   rF   )r   rU   r   r   r   r&      r8   zUnionAdjacency.__getitem__c                    r'   )Nc                    r(   r   r)   r+   r   r   r   r.      r/   z'UnionAdjacency.copy.<locals>.<dictcomp>)rE   r   r   r   r   r*      r0   zUnionAdjacency.copyc                    rZ   )Nc                    r[   r   r   r\   r   r   r   r.      r]   z*UnionAdjacency.__str__.<locals>.<dictcomp>r^   r   r   r   r   r2      r8   zUnionAdjacency.__str__c                 C   r_   r`   ra   r   r   r   r   r7      rb   zUnionAdjacency.__repr__Nr9   r   r   r   r   r      s    r   c                   @   r>   )r   a  A read-only union of two inner dicts of MultiAdjacencies.

    The two input dict-of-dict-of-dicts represent the union of
    `G.succ[node]` and `G.pred[node]` for MultiDiGraphs.
    Return values are UnionAtlas.
    The inner level of dict is read-write. But the outer levels are read-only.

    See Also
    ========
    UnionAtlas: View into dict-of-dict
    UnionAdjacency:  View into dict-of-dict-of-dict
    UnionMultiAdjacency:  View into dict-of-dict-of-dict-of-dict
    r   c                 C   sR   || j v }|| jv }|r!|rt| j | | j| S t| j | i S ti | j| S r   )rE   rF   r   )r   nodeZin_succZin_predr   r   r   r&      s   

zUnionMultiInner.__getitem__c                    s.   t  j t  j B } fdd|D S )Nc                    r(   r   r)   r+   r   r   r   r.      r/   z(UnionMultiInner.copy.<locals>.<dictcomp>)rS   rE   rQ   rF   )r   nodesr   r   r   r*      s   zUnionMultiInner.copyNrB   r   r   r   r   r      s
    	r   c                   @   s   e Zd ZdZdZdd ZdS )r	   a  A read-only union of two dict MultiAdjacencies.

    The two input dict-of-dict-of-dict-of-dicts represent the union of
    `G.succ` and `G.pred` for MultiDiGraphs. Return values are UnionAdjacency.
    The inner level of dict is read-write. But the outer levels are read-only.

    See Also
    ========
    UnionAtlas:  View into dict-of-dict
    UnionMultiInner:  View into dict-of-dict-of-dict
    r   c                 C   rc   r   )r   rE   rF   )r   rd   r   r   r   r&     r8   zUnionMultiAdjacency.__getitem__N)r6   r:   r;   r<   r=   r&   r   r   r   r   r	      s    r	   c                   @   <   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )r
   c                 C   rL   r   )r   NODE_OK)r   r   rg   r   r   r   r     rP   zFilterAtlas.__init__c                 C      t dd | D S )Nc                 s       | ]}d V  qdS    Nr   r+   r   r   r   	<genexpr>      z&FilterAtlas.__len__.<locals>.<genexpr>sumr   r   r   r   r!        zFilterAtlas.__len__c                    d   zdt  jj t  jk }W n ty   d}Y nw |r( fdd jjD S  fdd jD S )N   Fc                 3       | ]
}| j v r|V  qd S r   r   r+   r   r   r   rl         z'FilterAtlas.__iter__.<locals>.<genexpr>c                 3       | ]
}  |r|V  qd S r   rg   r+   r   r   r   rl     rt   r    rg   re   r   AttributeErrorr   node_ok_shorterr   r   r   r#        zFilterAtlas.__iter__c                 C   s.   || j v r| |r| j | S td| d)NKey 
 not found)r   rg   rT   r$   r   r   r   r&     s   
zFilterAtlas.__getitem__c                    rZ   )Nc                    r[   r   r   r\   r   r   r   r.   !  r]   z'FilterAtlas.__str__.<locals>.<dictcomp>r^   r   r   r   r   r2      r8   zFilterAtlas.__str__c                 C   r_   r`   )r5   r6   r   rg   r   r   r   r   r7   #  rb   zFilterAtlas.__repr__N	r6   r:   r;   r   r!   r#   r&   r2   r7   r   r   r   r   r
   
  s    	r
   c                   @   rf   )r   c                 C   s   || _ || _|| _d S r   )r   rg   EDGE_OK)r   r   rg   r   r   r   r   r   (  s   
zFilterAdjacency.__init__c                 C   rh   )Nc                 s   ri   rj   r   r+   r   r   r   rl   .  rm   z*FilterAdjacency.__len__.<locals>.<genexpr>rn   r   r   r   r   r!   -  rp   zFilterAdjacency.__len__c                    rq   )Nrr   Fc                 3   rs   r   r   r+   r   r   r   rl   6  rt   z+FilterAdjacency.__iter__.<locals>.<genexpr>c                 3   ru   r   rv   r+   r   r   r   rl   7  rt   rw   ry   r   r   r   r#   0  r{   zFilterAdjacency.__iter__c                    B    j v r r fdd}tj   |S td  d)Nc                    s    | o
 | S r   rg   r   )rU   rd   r   r   r   new_node_ok<  r8   z0FilterAdjacency.__getitem__.<locals>.new_node_okr|   r}   r   rg   r
   rT   )r   rd   r   r   r   r   r&   9     zFilterAdjacency.__getitem__c                    rZ   )Nc                    r[   r   r   r\   r   r   r   r.   C  r]   z+FilterAdjacency.__str__.<locals>.<dictcomp>r^   r   r   r   r   r2   B  r8   zFilterAdjacency.__str__c                 C   s*   | j j}| d| jd| jd| jdS r`   )r5   r6   r   rg   r   r@   r   r   r   r7   E  s   "zFilterAdjacency.__repr__Nr~   r   r   r   r   r   '  s    		r   c                   @   s   e Zd Zdd Zdd ZdS )r   c                 #   s    zdt  jj t  jk }W n ty   d}Y nw |r* fdd jjD }n
 fdd jD }|D ]}d} j| D ]} ||rKd} qLq?|du rS|V  q6d S )Nrr   Fc                 3   rs   r   r   r+   r   r   r   rl   Q  rt   z,FilterMultiInner.__iter__.<locals>.<genexpr>c                 3   ru   r   rv   r+   r   r   r   rl   S  rt   T)r    rg   re   r   rx   r   )r   rz   Zmy_nodesr-   Zsome_keys_okr%   r   r   r   r#   K  s(   zFilterMultiInner.__iter__c                    r   )Nc                    s     | S r   )r   )r%   rU   r   r   r   r   `  s   z1FilterMultiInner.__getitem__.<locals>.new_node_okr|   r}   r   )r   rU   r   r   r   r   r&   ]  r   zFilterMultiInner.__getitem__N)r6   r:   r;   r#   r&   r   r   r   r   r   J  s    r   c                   @   s   e Zd Zdd ZdS )r   c                    sF    j v r r fdd}tj   j|S td  d)Nc                    s    | o | |S r   r   )rU   r%   r   r   r   edge_okk  rR   z1FilterMultiAdjacency.__getitem__.<locals>.edge_okr|   r}   )r   rg   r   rT   )r   rd   r   r   r   r   r&   h  s   z FilterMultiAdjacency.__getitem__N)r6   r:   r;   r&   r   r   r   r   r   g  s    r   N)r<   collections.abcr   __all__r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   <module>   s    +74#