a
    º”h„}  ã                   @   sæ   d Z ddlZddlZddlmZ ddlZddlmZ g d¢Z	G dd„ 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d#dd„Zeddƒd$dd„ƒZdd„ Zd%dd „Zd!d"„ ZdS )&z-
Text-based visual representations of graphs
é    N)Údefaultdict)Ú	open_file)Ú
forest_strÚgenerate_network_textÚwrite_network_textc                   @   s   e Zd Zedd„ ƒZdS )Ú
BaseGlyphsc                    s   ‡ fdd„t ˆ ƒD ƒS )Nc                    s*   i | ]"}|  d ¡s|dkr|tˆ |ƒ“qS )Ú_Úas_dict)Ú
startswithÚgetattr)Ú.0Úa©Úcls© úE/var/www/auris/lib/python3.9/site-packages/networkx/readwrite/text.pyÚ
<dictcomp>   s   þz&BaseGlyphs.as_dict.<locals>.<dictcomp>)Údirr   r   r   r   r	      s    
þzBaseGlyphs.as_dictN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr	   r   r   r   r   r      s   r   c                   @   sV   e Zd ZU dZeed< dZeed< dZeed< dZeed< dZ	eed	< d
Z
eed< dS )ÚAsciiBaseGlyphsú+Úemptyz+-- Únewtree_lastÚnewtree_midú    Úendof_forestz:   Úwithin_forestz|   Úwithin_treeN©r   r   r   r   ÚstrÚ__annotations__r   r   r   r   r    r   r   r   r   r      s   
r   c                   @   s>   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	S )
ÚAsciiDirectedGlyphszL-> Úlastz|-> Úmidz<-Úbackedgeú!Úvertical_edgeN©	r   r   r   r%   r"   r#   r&   r'   r)   r   r   r   r   r$   !   s   
r$   c                   @   s>   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	S )
ÚAsciiUndirectedGlyphszL-- r%   z|-- r&   ú-r'   ú|r)   Nr*   r   r   r   r   r+   (   s   
r+   c                   @   sV   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	Z	eed
< dZ
eed< dS )ÚUtfBaseGlyphsu   â•™r   u
   â•™â”€â”€ r   u
   â•Ÿâ”€â”€ r   r   r   u   â•Ž   r   u   â”‚   r    Nr!   r   r   r   r   r.   /   s   
r.   c                   @   s>   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	S )
ÚUtfDirectedGlyphsu
   â””â”€â•¼ r%   u
   â”œâ”€â•¼ r&   u   â•¾r'   u   â•½r)   Nr*   r   r   r   r   r/   ;   s   
r/   c                   @   s>   e Zd ZU dZeed< dZeed< dZeed< dZeed< d	S )
ÚUtfUndirectedGlyphsu
   â””â”€â”€ r%   u
   â”œâ”€â”€ r&   u   â”€r'   u   â”‚r)   Nr*   r   r   r   r   r0   B   s   
r0   TFc           "      #   sF  ddl m‰ m} G ‡ fdd„d|ƒ‰d}ˆ ¡ }|rN|r<tnt}	ˆj}
ˆj}n|rVtnt	}	ˆj
}
ˆj
}t|tƒrv|‰n|r€d‰nd‰|dkrœ|	jd V  n¦tˆjƒdkr¶|	jV  nŒ|du rÆtˆƒ}t|ƒd	 ‰‡‡fd
d„t|ƒD ƒddd… }tdd„ ƒ}tƒ ‰|rB| ¡ \}}}}}|tur´|ˆv }|rF||  d	7  < |r || r |dur d}ˆ|t||dƒ}| |¡ d}ˆ|||||ƒ}| |¡ q|rªqˆ |¡ |sø|rÞd}||	jg }||	jg }n||	jg }||	jg }nH|r|}|}n8|r(||	jg }||	jg }n||	jg }||	jg }|tu rZd}d}g }n<ˆdur|tˆj|  ˆ|¡ƒ}nt|ƒ}|dur¢ˆj|  |d¡}nd}|rÀt |
| ƒ}|h‰n"‡fdd„|
| D ƒ}h |£|’‰|durt|ƒ|d	 kr|r
tg}|h‰|r(|r"tg}|h‰‡fdd„|| D ƒ}|r’ˆdurjd !‡‡fdd„|D ƒ¡}nd !dd„ |D ƒ¡}d !d|	j"|g¡}nd}|r°d !||	j#g ¡V  d !|||g ¡V  |rú|rÞtt|ƒƒ}ntt|ƒ|h ƒ}|d	k}nd}t|ddd… ƒD ],\} }!| dk}ˆ||!|||ƒ}| |¡ qqdS )un  Generate lines in the "network text" format

    This works via a depth-first traversal of the graph and writing a line for
    each unique node encountered. Non-tree edges are written to the right of
    each node, and connection to a non-tree edge is indicated with an ellipsis.
    This representation works best when the input graph is a forest, but any
    graph can be represented.

    This notation is original to networkx, although it is simple enough that it
    may be known in existing literature. See #5602 for details. The procedure
    is summarized as follows:

    1. Given a set of source nodes (which can be specified, or automatically
    discovered via finding the (strongly) connected components and choosing one
    node with minimum degree from each), we traverse the graph in depth first
    order.

    2. Each reachable node will be printed exactly once on it's own line.

    3. Edges are indicated in one of four ways:

        a. a parent "L-style" connection on the upper left. This corresponds to
        a traversal in the directed DFS tree.

        b. a backref "<-style" connection shown directly on the right. For
        directed graphs, these are drawn for any incoming edges to a node that
        is not a parent edge. For undirected graphs, these are drawn for only
        the non-parent edges that have already been represented (The edges that
        have not been represented will be handled in the recursive case).

        c. a child "L-style" connection on the lower right. Drawing of the
        children are handled recursively.

        d. if ``vertical_chains`` is true, and a parent node only has one child
        a "vertical-style" edge is drawn between them.

    4. The children of each node (wrt the directed DFS tree) are drawn
    underneath and to the right of it. In the case that a child node has already
    been drawn the connection is replaced with an ellipsis ("...") to indicate
    that there is one or more connections represented elsewhere.

    5. If a maximum depth is specified, an edge to nodes past this maximum
    depth will be represented by an ellipsis.

    6. If a a node has a truthy "collapse" value, then we do not traverse past
    that node.

    Parameters
    ----------
    graph : nx.DiGraph | nx.Graph
        Graph to represent

    with_labels : bool | str
        If True will use the "label" attribute of a node to display if it
        exists otherwise it will use the node value itself. If given as a
        string, then that attribute name will be used instead of "label".
        Defaults to True.

    sources : List
        Specifies which nodes to start traversal from. Note: nodes that are not
        reachable from one of these sources may not be shown. If unspecified,
        the minimal set of nodes needed to reach all others will be used.

    max_depth : int | None
        The maximum depth to traverse before stopping. Defaults to None.

    ascii_only : Boolean
        If True only ASCII characters are used to construct the visualization

    vertical_chains : Boolean
        If True, chains of nodes will be drawn vertically when possible.

    Yields
    ------
    str : a line of generated text

    Examples
    --------
    >>> graph = nx.path_graph(10)
    >>> graph.add_node('A')
    >>> graph.add_node('B')
    >>> graph.add_node('C')
    >>> graph.add_node('D')
    >>> graph.add_edge(9, 'A')
    >>> graph.add_edge(9, 'B')
    >>> graph.add_edge(9, 'C')
    >>> graph.add_edge('C', 'D')
    >>> graph.add_edge('C', 'E')
    >>> graph.add_edge('C', 'F')
    >>> nx.write_network_text(graph)
    â•™â”€â”€ 0
        â””â”€â”€ 1
            â””â”€â”€ 2
                â””â”€â”€ 3
                    â””â”€â”€ 4
                        â””â”€â”€ 5
                            â””â”€â”€ 6
                                â””â”€â”€ 7
                                    â””â”€â”€ 8
                                        â””â”€â”€ 9
                                            â”œâ”€â”€ A
                                            â”œâ”€â”€ B
                                            â””â”€â”€ C
                                                â”œâ”€â”€ D
                                                â”œâ”€â”€ E
                                                â””â”€â”€ F
    >>> nx.write_network_text(graph, vertical_chains=True)
    â•™â”€â”€ 0
        â”‚
        1
        â”‚
        2
        â”‚
        3
        â”‚
        4
        â”‚
        5
        â”‚
        6
        â”‚
        7
        â”‚
        8
        â”‚
        9
        â”œâ”€â”€ A
        â”œâ”€â”€ B
        â””â”€â”€ C
            â”œâ”€â”€ D
            â”œâ”€â”€ E
            â””â”€â”€ F
    r   )ÚAnyÚ
NamedTuplec                       s6   e Zd ZU ” ed< ” ed< eed< eed< eed< dS )z)generate_network_text.<locals>.StackFrameÚparentÚnodeÚindentsÚthis_islastÚthis_verticalN)r   r   r   r#   ÚlistÚboolr   )r1   r   r   Ú
StackFrameØ   s
   
r:   ÚcollapseÚlabelNz ...é   c                    s$   g | ]\}}ˆ d |g |ˆkdƒ‘qS )NFr   )r   Úidxr4   )r:   Úlast_idxr   r   Ú
<listcomp>  s   ÿz)generate_network_text.<locals>.<listcomp>éÿÿÿÿc                   S   s   dS )Nr   r   r   r   r   r   Ú<lambda>	  ó    z'generate_network_text.<locals>.<lambda>TFÚ c                    s   g | ]}|ˆ vr|‘qS r   r   )r   Úchild)Ú
seen_nodesr   r   r@   b  s   c                    s   g | ]}|ˆ vr|‘qS r   r   ©r   Úp)Úhandled_parentsr   r   r@   y  rC   ú, c                    s"   g | ]}t ˆ j|  ˆ|¡ƒ‘qS r   )r"   ÚnodesÚgetrG   )ÚgraphÚ
label_attrr   r   r@   }  s   ÿc                 S   s   g | ]}t |ƒ‘qS r   )r"   rG   r   r   r   r@   „  rC   ú )$Útypingr1   r2   Úis_directedr$   r/   ÚsuccÚpredr+   r0   ZadjÚ
isinstancer"   r   ÚlenrK   Ú_find_sourcesÚ	enumerater   ÚsetÚpopÚEllipsisÚappendÚaddr   r   r   r   r%   r&   r    rL   r8   Újoinr'   r)   )"rM   Úwith_labelsÚsourcesÚ	max_depthÚ
ascii_onlyÚvertical_chainsr2   Zcollapse_attrrQ   ÚglyphsrR   rS   ÚstackZnum_skipped_childrenr3   r4   r5   r6   r7   ÚskipZnext_islastZ	try_frameZthis_prefixZnext_prefixr<   ÚsuffixÚchildrenr;   Zother_parentsZother_parents_labelsZnum_childrenZnext_is_verticalr>   rE   r   )r1   r:   rM   rI   rN   r?   rF   r   r   I   sò     
þý

ÿ

ÿ





ÿ
þÿÿ

ÿr   r=   ÚwÚ
c           
      C   sh   |du rt jj}n,t|dƒr$|j}nt|ƒr2|}ntt|ƒƒ‚t| |||||dD ]}	||	| ƒ qRdS )u¾  Creates a nice text representation of a graph

    This works via a depth-first traversal of the graph and writing a line for
    each unique node encountered. Non-tree edges are written to the right of
    each node, and connection to a non-tree edge is indicated with an ellipsis.
    This representation works best when the input graph is a forest, but any
    graph can be represented.

    Parameters
    ----------
    graph : nx.DiGraph | nx.Graph
        Graph to represent

    path : string or file or callable or None
       Filename or file handle for data output.
       if a function, then it will be called for each generated line.
       if None, this will default to "sys.stdout.write"

    with_labels : bool | str
        If True will use the "label" attribute of a node to display if it
        exists otherwise it will use the node value itself. If given as a
        string, then that attribute name will be used instead of "label".
        Defaults to True.

    sources : List
        Specifies which nodes to start traversal from. Note: nodes that are not
        reachable from one of these sources may not be shown. If unspecified,
        the minimal set of nodes needed to reach all others will be used.

    max_depth : int | None
        The maximum depth to traverse before stopping. Defaults to None.

    ascii_only : Boolean
        If True only ASCII characters are used to construct the visualization

    end : string
        The line ending character

    vertical_chains : Boolean
        If True, chains of nodes will be drawn vertically when possible.

    Examples
    --------
    >>> graph = nx.balanced_tree(r=2, h=2, create_using=nx.DiGraph)
    >>> nx.write_network_text(graph)
    â•™â”€â”€ 0
        â”œâ”€â•¼ 1
        â”‚   â”œâ”€â•¼ 3
        â”‚   â””â”€â•¼ 4
        â””â”€â•¼ 2
            â”œâ”€â•¼ 5
            â””â”€â•¼ 6

    >>> # A near tree with one non-tree edge
    >>> graph.add_edge(5, 1)
    >>> nx.write_network_text(graph)
    â•™â”€â”€ 0
        â”œâ”€â•¼ 1 â•¾ 5
        â”‚   â”œâ”€â•¼ 3
        â”‚   â””â”€â•¼ 4
        â””â”€â•¼ 2
            â”œâ”€â•¼ 5
            â”‚   â””â”€â•¼  ...
            â””â”€â•¼ 6

    >>> graph = nx.cycle_graph(5)
    >>> nx.write_network_text(graph)
    â•™â”€â”€ 0
        â”œâ”€â”€ 1
        â”‚   â””â”€â”€ 2
        â”‚       â””â”€â”€ 3
        â”‚           â””â”€â”€ 4 â”€ 0
        â””â”€â”€  ...

    >>> graph = nx.cycle_graph(5, nx.DiGraph)
    >>> nx.write_network_text(graph, vertical_chains=True)
    â•™â”€â”€ 0 â•¾ 4
        â•½
        1
        â•½
        2
        â•½
        3
        â•½
        4
        â””â”€â•¼  ...

    >>> nx.write_network_text(graph, vertical_chains=True, ascii_only=True)
    +-- 0 <- 4
        !
        1
        !
        2
        !
        3
        !
        4
        L->  ...

    >>> graph = nx.generators.barbell_graph(4, 2)
    >>> nx.write_network_text(graph, vertical_chains=False)
    â•™â”€â”€ 4
        â”œâ”€â”€ 5
        â”‚   â””â”€â”€ 6
        â”‚       â”œâ”€â”€ 7
        â”‚       â”‚   â”œâ”€â”€ 8 â”€ 6
        â”‚       â”‚   â”‚   â””â”€â”€ 9 â”€ 6, 7
        â”‚       â”‚   â””â”€â”€  ...
        â”‚       â””â”€â”€  ...
        â””â”€â”€ 3
            â”œâ”€â”€ 0
            â”‚   â”œâ”€â”€ 1 â”€ 3
            â”‚   â”‚   â””â”€â”€ 2 â”€ 0, 3
            â”‚   â””â”€â”€  ...
            â””â”€â”€  ...
    >>> nx.write_network_text(graph, vertical_chains=True)
    â•™â”€â”€ 4
        â”œâ”€â”€ 5
        â”‚   â”‚
        â”‚   6
        â”‚   â”œâ”€â”€ 7
        â”‚   â”‚   â”œâ”€â”€ 8 â”€ 6
        â”‚   â”‚   â”‚   â”‚
        â”‚   â”‚   â”‚   9 â”€ 6, 7
        â”‚   â”‚   â””â”€â”€  ...
        â”‚   â””â”€â”€  ...
        â””â”€â”€ 3
            â”œâ”€â”€ 0
            â”‚   â”œâ”€â”€ 1 â”€ 3
            â”‚   â”‚   â”‚
            â”‚   â”‚   2 â”€ 0, 3
            â”‚   â””â”€â”€  ...
            â””â”€â”€  ...

    >>> graph = nx.complete_graph(5, create_using=nx.Graph)
    >>> nx.write_network_text(graph)
    â•™â”€â”€ 0
        â”œâ”€â”€ 1
        â”‚   â”œâ”€â”€ 2 â”€ 0
        â”‚   â”‚   â”œâ”€â”€ 3 â”€ 0, 1
        â”‚   â”‚   â”‚   â””â”€â”€ 4 â”€ 0, 1, 2
        â”‚   â”‚   â””â”€â”€  ...
        â”‚   â””â”€â”€  ...
        â””â”€â”€  ...

    >>> graph = nx.complete_graph(3, create_using=nx.DiGraph)
    >>> nx.write_network_text(graph)
    â•™â”€â”€ 0 â•¾ 1, 2
        â”œâ”€â•¼ 1 â•¾ 2
        â”‚   â”œâ”€â•¼ 2 â•¾ 0
        â”‚   â”‚   â””â”€â•¼  ...
        â”‚   â””â”€â•¼  ...
        â””â”€â•¼  ...
    NÚwrite)r^   r_   r`   ra   rb   )ÚsysÚstdoutrj   ÚhasattrÚcallableÚ	TypeErrorÚtyper   )
rM   Úpathr^   r_   r`   ra   Úendrb   Ú_writeÚliner   r   r   r   ¦  s"     &

ú
r   c           
         sØ   ˆ   ¡ r¨tt ˆ ¡ƒ}t ˆ |¡}dd„ | ¡ D ƒ}|jd }ˆ jD ]}|| }||  |¡ qDg }| ¡ D ]8}|j| dkrl|| }t	|‡ fdd„d}	| |	¡ qln,‡ fdd	„t 
ˆ ¡D ƒ}t|‡ fd
d„d}|S )zR
    Determine a minimal set of nodes such that the entire graph is reachable
    c                 S   s   i | ]
}|g “qS r   r   )r   Úsnr   r   r   r   o  rC   z!_find_sources.<locals>.<dictcomp>Úmappingr   c                    s
   ˆ j |  S ©N)Ú	in_degree©Ún©rM   r   r   rB   z  rC   z_find_sources.<locals>.<lambda>©Úkeyc                    s    g | ]}t |‡ fd d„d‘qS )c                    s
   ˆ j |  S rw   ©Zdegreery   r{   r   r   rB   €  rC   z*_find_sources.<locals>.<listcomp>.<lambda>r|   )Úmin)r   Úccr{   r   r   r@     s   ÿz!_find_sources.<locals>.<listcomp>c                    s
   ˆ j |  S rw   r~   ry   r{   r   r   rB   ƒ  rC   )rQ   r8   ÚnxZstrongly_connected_componentsZcondensationrK   rM   r[   rx   r   Zconnected_componentsÚsorted)
rM   ZsccsZ	scc_graphZsupernode_to_nodesrv   rz   ru   r_   Zsccr4   r   r{   r   rV   b  s&    


þrV   c                 C   st   d}t  |t¡ t| jƒdkr2t | ¡s2t d¡‚g }|du rF|j}n|}t	| ||||dd |du rpd 
|¡S dS )u  Creates a nice utf8 representation of a forest

    This function has been superseded by
    :func:`nx.readwrite.text.generate_network_text`, which should be used
    instead.

    Parameters
    ----------
    graph : nx.DiGraph | nx.Graph
        Graph to represent (must be a tree, forest, or the empty graph)

    with_labels : bool
        If True will use the "label" attribute of a node to display if it
        exists otherwise it will use the node value itself. Defaults to True.

    sources : List
        Mainly relevant for undirected forests, specifies which nodes to list
        first. If unspecified the root nodes of each tree will be used for
        directed forests; for undirected forests this defaults to the nodes
        with the smallest degree.

    write : callable
        Function to use to write to, if None new lines are appended to
        a list and returned. If set to the `print` function, lines will
        be written to stdout as they are generated. If specified,
        this function will return None. Defaults to None.

    ascii_only : Boolean
        If True only ASCII characters are used to construct the visualization

    Returns
    -------
    str | None :
        utf8 representation of the tree / forest

    Examples
    --------
    >>> graph = nx.balanced_tree(r=2, h=3, create_using=nx.DiGraph)
    >>> print(nx.forest_str(graph))
    â•™â”€â”€ 0
        â”œâ”€â•¼ 1
        â”‚   â”œâ”€â•¼ 3
        â”‚   â”‚   â”œâ”€â•¼ 7
        â”‚   â”‚   â””â”€â•¼ 8
        â”‚   â””â”€â•¼ 4
        â”‚       â”œâ”€â•¼ 9
        â”‚       â””â”€â•¼ 10
        â””â”€â•¼ 2
            â”œâ”€â•¼ 5
            â”‚   â”œâ”€â•¼ 11
            â”‚   â””â”€â•¼ 12
            â””â”€â•¼ 6
                â”œâ”€â•¼ 13
                â””â”€â•¼ 14


    >>> graph = nx.balanced_tree(r=1, h=2, create_using=nx.Graph)
    >>> print(nx.forest_str(graph))
    â•™â”€â”€ 0
        â””â”€â”€ 1
            â””â”€â”€ 2

    >>> print(nx.forest_str(graph, ascii_only=True))
    +-- 0
        L-- 1
            L-- 2
    z‰
forest_str is deprecated as of version 3.1 and will be removed in version 3.3. Use generate_network_text or write_network_text instead.
r   z)input must be a forest or the empty graphNrD   )r^   r_   ra   rr   ri   )ÚwarningsÚwarnÚDeprecationWarningrU   rK   r   Z	is_forestZNetworkXNotImplementedr[   r   r]   )rM   r^   r_   rj   ra   ÚmsgZprintbufrs   r   r   r   r   ‡  s(    Eÿ

ú	r   c           $         sÔ  ddl m} ddlm‰ m}m‰ G ‡ ‡fdd„d|ƒ}t| ƒ}d}d}g }zt|ƒ}W n tyh   Y nf0 | 	|¡ |d }	|	t
jt
jd t
jd hv ržd}n0|	tjtjd tjd hv rÀd}ntd	|	› ƒ‚|rät ¡ }
t ¡ }nt ¡ }
t ¡ }t|
 ¡ ƒ}t| ¡ ƒ}g }|D ],‰|}‡fd
d„|D ƒ}|s| 	ˆ¡ qg }|D ],‰|}‡fdd„|D ƒ}|sJ| 	ˆ¡ qJ|D ]V‰| 	ˆ¡ t‡fdd„|D ƒƒr®d} qÔn"t‡fdd„|D ƒƒr|d} qÔq||du râd}|rì|
n|}d|d  d }|||ƒ}g }g }d}tƒ }||ddƒg}|D ]Z‰ˆ|d krJd}q.|ˆv r°ˆ |¡\}}dd„ | d¡D ƒ}| ¡ }| dd¡\}‰ˆ ¡ ‰| ‡fdd„|D ƒ¡ nˆ dd¡\}‰ˆ ¡ ‰| ¡ }ˆ|d v rü||j|j dƒ}| 	|¡ q.t!|ƒ} |ˆ| dƒ}!|j"rn|!j |j kr4| ¡ }qˆdkrJ| 	|¡ n>| 	|¡ | 	|!¡ | 	|!j¡ |j|ur.| 	|j|!jf¡ q.|r¤t!|ƒdks¤J ‚|r°t#j$nt#j%}"|"ƒ }#|# &|¡ |# '|¡ |#S )a•  Reconstructs a graph from a network text representation.

    This is mainly used for testing.  Network text is for display, not
    serialization, as such this cannot parse all network text representations
    because node labels can be ambiguous with the glyphs and indentation used
    to represent edge structure. Additionally, there is no way to determine if
    disconnected graphs were originally directed or undirected.

    Parameters
    ----------
    lines : list or iterator of strings
        Input data in network text format

    Returns
    -------
    G: NetworkX graph
        The graph corresponding to the lines in network text format.
    r   )Úchain)r1   r2   ÚUnionc                       s.   e Zd ZU ” ed< eed< ”edf ed< dS )z,_parse_network_text.<locals>.ParseStackFramer4   ÚindentNÚhas_vertical_child)r   r   r   r#   Úintr   )r1   rˆ   r   r   ÚParseStackFrame   s   
rŒ   NFTzUnexpected first character: c                    s   g | ]}ˆ |v r|‘qS r   r   ©r   Úother©Úitemr   r   r@   9  rC   z'_parse_network_text.<locals>.<listcomp>c                    s   g | ]}ˆ |v r|‘qS r   r   r   r   r   r   r@   ?  rC   c                 3   s   | ]}|ˆ v V  qd S rw   r   ©r   r   ©rt   r   r   Ú	<genexpr>E  rC   z&_parse_network_text.<locals>.<genexpr>c                 3   s   | ]}|ˆ v V  qd S rw   r   r‘   r’   r   r   r“   H  rC   rO   r'   rA   r   c                 S   s   g | ]}|  ¡ ‘qS r   )Ústrip©r   Úur   r   r   r@   p  rC   rJ   r=   c                    s   g | ]}|ˆ f‘qS r   r   r•   )r4   r   r   r@   v  rC   r)   z...)(Ú	itertoolsr‡   rP   r1   r2   rˆ   ÚiterÚnextÚStopIterationr[   r.   r   r   r   r   ÚAssertionErrorr$   r	   r+   r/   r0   rX   ÚvaluesÚanyÚobjectÚsplitÚrstripÚrsplitr”   ÚextendrY   r4   r‰   rU   rŠ   r   ZDiGraphZGraphZadd_nodes_fromZadd_edges_from)$Úlinesr‡   r2   rŒ   Zinitial_line_iterZis_asciirQ   Zinitial_linesÚ
first_lineÚ
first_charZdirected_glyphsZundirected_glyphsZdirected_itemsZundirected_itemsZunambiguous_directed_itemsZother_itemsZother_supersetsZunambiguous_undirected_itemsrc   Zbackedge_symbolZparsing_line_iterÚedgesrK   Zis_emptyZnoparentrd   Z	node_partZbackedge_partZbackedge_nodesÚprefixÚprevZmodified_prevr‰   Úcurrr   Únewr   )r1   rˆ   r   rt   r4   r   Ú_parse_network_textê  sÒ    	
ýý






ý





r«   )TNNFF)NTNNFri   F)TNNF)Ú__doc__rk   rƒ   Úcollectionsr   Znetworkxr   Znetworkx.utilsr   Ú__all__r   r   r$   r+   r.   r/   r0   r   r   rV   r   r«   r   r   r   r   Ú<module>   sD   
		     ú
  _       ø <%
c