B
    ,[A                 @   s   d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZmZ ddlZddd	d
dddddddddgZdddZeefddZdd	 Zdd Zeefdd
Zdd Zdd Zdd Zdd ZeZe Z ZZ dS )a  View of Graphs as SubGraph, Reverse, Directed, Undirected.

In some algorithms it is convenient to temporarily morph
a graph to exclude some nodes or edges. It should be better
to do that via a view than to remove and then re-add.
In other algorithms it is convenient to temporarily morph
a graph to reverse directed edges, or treat a directed graph
as undirected, etc. This module provides those graph views.

The resulting views are essentially read-only graphs that
report data from the orignal graph object. We provide an
attribute G._graph which points to the underlying graph object.

Note: Since graphviews look like graphs, one can end up with
view-of-view-of-view chains. Be careful with chains because
they become very slow with about 15 nested views.
For the common simple case of node induced subgraphs created
from the graph class, we short-cut the chain by returning a
subgraph of the original graph directly rather than a subgraph
of a subgraph. We are careful not to disrupt any edge filter in
the middle subgraph. In general, determining how to short-cut
the chain is tricky and much harder with restricted_views than
with induced subgraphs.
Often it is easiest to use .copy() to avoid chains.
    )UnionAdjacencyUnionMultiAdjacencyFilterAtlasFilterAdjacencyFilterMultiAdjacency)	no_filter)NetworkXErrorNetworkXNotImplemented)GraphDiGraph
MultiGraphMultiDiGraphNgeneric_graph_viewsubgraph_viewreverse_viewSubGraph
SubDiGraphSubMultiGraphSubMultiDiGraphReverseViewMultiReverseViewDiGraphViewMultiDiGraphView	GraphViewMultiGraphViewc             C   s   |d kr|   }ntd|}|  | kr6tdt|}| |_| j|_| j|_|	 r| 	 r| j
|_
| j|_| j
|_q| j|_
| j|_| j|_n<| 	 r|  rt| j
| j|_qt| j
| j|_n| j|_|S )Nr   z-Multigraph for G must agree with create_using)	__class__nxZempty_graphis_multigraphr   freeze_graphgraph_nodeis_directed_succ_pred_adjr   r   )GZcreate_usingnewG r(   :lib/python3.7/site-packages/networkx/classes/graphviews.pyr   5   s.    



c                s   t |  }||_ |_| |_| j|_t| j||_| 	 rPt
} fdd}nt} fdd}|  r|| j| |_|| j|||_|j|_n|| j| |_|S )Nc                s    || |S )Nr(   )uvk)filter_edger(   r)   reverse_edgec   s    z#subgraph_view.<locals>.reverse_edgec                s
    || S )Nr(   )r*   r+   )r-   r(   r)   r.   g   s    )r   r   r   Z_NODE_OKZ_EDGE_OKr   r    r   r!   r   r   r   r"   r#   r$   r%   )r&   filter_noder-   r'   ZAdjr.   r(   )r-   r)   r   V   s"    
c             C   s:   |   sd}t|t| }| j| j |_|_|j|_|S )Nz#not implemented for undirected type)r"   r	   r   r$   r#   r%   )r&   msgr'   r(   r(   r)   r   q   s    c             C   s$   dd l }d}|j|tdd t| S )Nr   z3ReverseView is deprecated. Use reverse_view instead   )category
stacklevel)warningswarnDeprecationWarningr   )r&   r4   r0   r(   r(   r)   r   |   s    c             C   s(   dd l }d}|j|tdd t| ||S )Nr   z1SubGraph is deprecated. Use subgraph_view insteadr1   )r2   r3   )r4   r5   r6   r   )r&   r/   r-   r4   r0   r(   r(   r)   r      s    c             C   s&   dd l }d}|j|tdd t| tS )Nr   z7GraphView is deprecated. Use generic_graph_view insteadr1   )r2   r3   )r4   r5   r6   r   r
   )r&   r4   r0   r(   r(   r)   r      s    c             C   s&   dd l }d}|j|tdd t| tS )Nr   z7GraphView is deprecated. Use generic_graph_view insteadr1   )r2   r3   )r4   r5   r6   r   r   )r&   r4   r0   r(   r(   r)   r      s    c             C   s&   dd l }d}|j|tdd t| tS )Nr   z7GraphView is deprecated. Use generic_graph_view insteadr1   )r2   r3   )r4   r5   r6   r   r   )r&   r4   r0   r(   r(   r)   r      s    c             C   s&   dd l }d}|j|tdd t| tS )Nr   z7GraphView is deprecated. Use generic_graph_view insteadr1   )r2   r3   )r4   r5   r6   r   r   )r&   r4   r0   r(   r(   r)   r      s    )N)!__doc__Znetworkx.classes.coreviewsr   r   r   r   r   Znetworkx.classes.filtersr   Znetworkx.exceptionr   r	   Znetworkx.classesr
   r   r   r   Znetworkxr   __all__r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   <module>#   s*   
!