U
    ?h+                     @   s   d Z ddlmZ ddddddd	d
dddg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                   @   s\   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   L/var/www/html/venv/lib/python3.8/site-packages/networkx/classes/coreviews.py__getstate__%   s    zAtlasView.__getstate__c                 C   s   |d | _ d S r   r   r   stater   r   r   __setstate__(   s    zAtlasView.__setstate__c                 C   s
   || _ d S Nr   )r   dr   r   r   __init__+   s    zAtlasView.__init__c                 C   s
   t | jS r   )lenr   r   r   r   r   __len__.   s    zAtlasView.__len__c                 C   s
   t | jS r   )iterr   r   r   r   r   __iter__1   s    zAtlasView.__iter__c                 C   s
   | j | S r   r   r   keyr   r   r   __getitem__4   s    zAtlasView.__getitem__c                    s    fdd j D S )Nc                    s   i | ]}| |   qS r   copy.0nr   r   r   
<dictcomp>8   s      z"AtlasView.copy.<locals>.<dictcomp>r   r   r   r   r   r$   7   s    zAtlasView.copyc                 C   s
   t | jS r   )strr   r   r   r   r   __str__:   s    zAtlasView.__str__c                 C   s   | j j d| jdS )N())	__class____name__r   r   r   r   r   __repr__=   s    zAtlasView.__repr__Nr.   
__module____qualname____doc__	__slots__r   r   r   r   r   r"   r$   r*   r/   r   r   r   r   r      s   c                   @   s$   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   s   t | j| S r   )r   r   r   namer   r   r   r"   P   s    zAdjacencyView.__getitem__c                    s    fdd j D S )Nc                    s   i | ]}| |   qS r   r#   r%   r   r   r   r(   T   s      z&AdjacencyView.copy.<locals>.<dictcomp>r   r   r   r   r   r$   S   s    zAdjacencyView.copyNr.   r1   r2   r3   r4   r"   r$   r   r   r   r   r   A   s   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )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   s   t | j| S r   )r   r   r5   r   r   r   r"   f   s    zMultiAdjacencyView.__getitem__c                    s    fdd j D S )Nc                    s   i | ]}| |   qS r   r#   r%   r   r   r   r(   j   s      z+MultiAdjacencyView.copy.<locals>.<dictcomp>r   r   r   r   r   r$   i   s    zMultiAdjacencyView.copyNr7   r   r   r   r   r   W   s   c                   @   s\   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   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   s   | j | jdS Nr8   r8   r   r   r   r   r   }   s    zUnionAtlas.__getstate__c                 C   s   |d | _ |d | _d S Nr9   r:   r8   r   r   r   r   r      s    
zUnionAtlas.__setstate__c                 C   s   || _ || _d S r   r8   r   succpredr   r   r   r      s    zUnionAtlas.__init__c                 C   s   t | j | j B S r   )r   r9   keysr:   r   r   r   r   r      s    zUnionAtlas.__len__c                 C   s    t t| j t| j B S r   )r   setr9   r@   r:   r   r   r   r   r      s    zUnionAtlas.__iter__c                 C   s0   z| j | W S  tk
r*   | j|  Y S X d S r   )r9   KeyErrorr:   r    r   r   r   r"      s    zUnionAtlas.__getitem__c                 C   sP   dd | j  D }| j D ],\}}||kr>|| | q| ||< q|S )Nc                 S   s   i | ]\}}||  qS r   r#   )r&   nbrddr   r   r   r(      s      z#UnionAtlas.copy.<locals>.<dictcomp>)r9   itemsr:   updater$   )r   resultrC   rD   r   r   r   r$      s    zUnionAtlas.copyc                    s   t  fdd D S )Nc                    s   i | ]}| | qS r   r   r&   rC   r   r   r   r(      s      z&UnionAtlas.__str__.<locals>.<dictcomp>r)   r   r   r   r   r*      s    zUnionAtlas.__str__c                 C   s   | j j d| jd| jdS Nr+   z, r,   r-   r.   r9   r:   r   r   r   r   r/      s    zUnionAtlas.__repr__Nr0   r   r   r   r   r   m   s   	c                   @   s\   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   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
    r8   c                 C   s   | j | jdS r;   r8   r   r   r   r   r      s    zUnionAdjacency.__getstate__c                 C   s   |d | _ |d | _d S r<   r8   r   r   r   r   r      s    
zUnionAdjacency.__setstate__c                 C   s4   t t| t| A dks$t|| _|| _d S )Nr   )r   rA   r@   AssertionErrorr9   r:   r=   r   r   r   r      s    $zUnionAdjacency.__init__c                 C   s
   t | jS r   )r   r9   r   r   r   r   r      s    zUnionAdjacency.__len__c                 C   s
   t | jS r   )r   r9   r   r   r   r   r      s    zUnionAdjacency.__iter__c                 C   s   t | j| | j| S r   )r   r9   r:   )r   rC   r   r   r   r"      s    zUnionAdjacency.__getitem__c                    s    fdd j D S )Nc                    s   i | ]}| |   qS r   r#   r%   r   r   r   r(      s      z'UnionAdjacency.copy.<locals>.<dictcomp>)r9   r   r   r   r   r$      s    zUnionAdjacency.copyc                    s   t  fdd D S )Nc                    s   i | ]}| | qS r   r   rH   r   r   r   r(      s      z*UnionAdjacency.__str__.<locals>.<dictcomp>rI   r   r   r   r   r*      s    zUnionAdjacency.__str__c                 C   s   | j j d| jd| jdS rJ   rK   r   r   r   r   r/      s    zUnionAdjacency.__repr__Nr0   r   r   r   r   r      s   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )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 k}|| jk}|rB|r2t| j | | j| S t| j | i S ti | j| S r   )r9   r:   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                    s   i | ]}| |   qS r   r#   r%   r   r   r   r(      s      z(UnionMultiInner.copy.<locals>.<dictcomp>)rA   r9   r@   r:   )r   nodesr   r   r   r$      s    zUnionMultiInner.copyNr7   r   r   r   r   r      s   	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   s   t | j| | j| S r   )r   r9   r:   )r   rM   r   r   r   r"     s    zUnionMultiAdjacency.__getitem__N)r.   r1   r2   r3   r4   r"   r   r   r   r   r	      s   c                   @   s<   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   s   || _ || _d S r   )r   NODE_OK)r   r   rO   r   r   r   r     s    zFilterAtlas.__init__c                 C   s   t dd | D S )Nc                 s   s   | ]
}d V  qdS    Nr   r%   r   r   r   	<genexpr>  s     z&FilterAtlas.__len__.<locals>.<genexpr>sumr   r   r   r   r     s    zFilterAtlas.__len__c                    sf   zdt  jj t  jk }W n tk
r6   d}Y nX |rR fdd jjD S  fdd jD S )N   Fc                 3   s   | ]}| j kr|V  qd S r   r   r%   r   r   r   rR     s     
 z'FilterAtlas.__iter__.<locals>.<genexpr>c                 3   s   | ]}  |r|V  qd S r   rO   r%   r   r   r   rR     s     
 r   rO   rN   r   AttributeErrorr   node_ok_shorterr   r   r   r     s    
zFilterAtlas.__iter__c                 C   s2   || j kr| |r| j | S td| dd S )NKey 
 not found)r   rO   rB   r    r   r   r   r"     s    
zFilterAtlas.__getitem__c                    s   t  fdd D S )Nc                    s   i | ]}| | qS r   r   rH   r   r   r   r(   !  s      z'FilterAtlas.__str__.<locals>.<dictcomp>rI   r   r   r   r   r*      s    zFilterAtlas.__str__c                 C   s   | j j d| jd| jdS rJ   )r-   r.   r   rO   r   r   r   r   r/   #  s    zFilterAtlas.__repr__N	r.   r1   r2   r   r   r   r"   r*   r/   r   r   r   r   r
   
  s   	c                   @   s<   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   s   || _ || _|| _d S r   )r   rO   EDGE_OK)r   r   rO   r^   r   r   r   r   (  s    zFilterAdjacency.__init__c                 C   s   t dd | D S )Nc                 s   s   | ]
}d V  qdS rP   r   r%   r   r   r   rR   .  s     z*FilterAdjacency.__len__.<locals>.<genexpr>rS   r   r   r   r   r   -  s    zFilterAdjacency.__len__c                    sf   zdt  jj t  jk }W n tk
r6   d}Y nX |rR fdd jjD S  fdd jD S )NrU   Fc                 3   s   | ]}| j kr|V  qd S r   r   r%   r   r   r   rR   6  s     
 z+FilterAdjacency.__iter__.<locals>.<genexpr>c                 3   s   | ]}  |r|V  qd S r   rV   r%   r   r   r   rR   7  s     
 rW   rY   r   r   r   r   0  s    
zFilterAdjacency.__iter__c                    sF    j kr2 r2 fdd}tj   |S td  dd S )Nc                    s    | o | S r   rO   r^   )rC   rM   r   r   r   new_node_ok<  s    z0FilterAdjacency.__getitem__.<locals>.new_node_okr[   r\   r   rO   r
   rB   )r   rM   ra   r   r`   r   r"   9  s    zFilterAdjacency.__getitem__c                    s   t  fdd D S )Nc                    s   i | ]}| | qS r   r   rH   r   r   r   r(   C  s      z+FilterAdjacency.__str__.<locals>.<dictcomp>rI   r   r   r   r   r*   B  s    zFilterAdjacency.__str__c                 C   s*   | j j}| d| jd| jd| jdS rJ   )r-   r.   r   rO   r^   r5   r   r   r   r/   E  s    zFilterAdjacency.__repr__Nr]   r   r   r   r   r   '  s   		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k
r6   d}Y nX |rT fdd jjD }n fdd jD }|D ]:}d} j| D ]} ||r~d} qq~|dkrl|V  qld S )NrU   Fc                 3   s   | ]}| j kr|V  qd S r   r   r%   r   r   r   rR   Q  s     
 z,FilterMultiInner.__iter__.<locals>.<genexpr>c                 3   s   | ]}  |r|V  qd S r   rV   r%   r   r   r   rR   S  s     
 T)r   rO   rN   r   rX   r^   )r   rZ   Zmy_nodesr'   Zsome_keys_okr!   r   r   r   r   K  s    
zFilterMultiInner.__iter__c                    sF    j kr2 r2 fdd}tj   |S td  dd S )Nc                    s     | S r   )r^   )r!   rC   r   r   r   ra   `  s    z1FilterMultiInner.__getitem__.<locals>.new_node_okr[   r\   rb   )r   rC   ra   r   rc   r   r"   ]  s    zFilterMultiInner.__getitem__N)r.   r1   r2   r   r"   r   r   r   r   r   J  s   c                   @   s   e Zd Zdd ZdS )r   c                    sJ    j kr6 r6 fdd}tj   j|S td  dd S )Nc                    s    | o | |S r   r_   )rC   r!   r`   r   r   edge_okk  s    z1FilterMultiAdjacency.__getitem__.<locals>.edge_okr[   r\   )r   rO   r   rB   )r   rM   rd   r   r`   r   r"   h  s    z FilterMultiAdjacency.__getitem__N)r.   r1   r2   r"   r   r   r   r   r   g  s   N)r3   collections.abcr   __all__r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   <module>   s0   +74#