
    hq                     (   S r SSKrSSKrSSKJr  SSKrSSKJr  SS/r	 " S S5      r
 " S	 S
\
5      r " S S\5      r " S S\5      r " S S\
5      r " S S\5      r " S S\5      r     SS jr\" SS5             SS j5       rS rS rg)z-
Text-based visual representations of graphs
    N)defaultdict)	open_filegenerate_network_textwrite_network_textc                   $    \ rS rSr\S 5       rSrg)
BaseGlyphs   c                     [        U 5       Vs0 s H/  nUR                  S5      (       a  M  US:w  d  M#  U[        X5      _M1     sn$ s  snf )N_as_dict)dir
startswithgetattr)clsas     I/var/www/html/env/lib/python3.13/site-packages/networkx/readwrite/text.pyr   BaseGlyphs.as_dict   sP     X
<<$ )*i Aws
 	
 
s   AAA N)__name__
__module____qualname____firstlineno__classmethodr   __static_attributes__r       r   r   r      s    
 
r   r   c                   j    \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\\S'   S	r
\\S
'   Sr\\S'   Srg)AsciiBaseGlyphs   +emptyz+-- newtree_lastnewtree_mid    endof_forestz:   within_forestz|   within_treer   Nr   r   r   r   r    str__annotations__r!   r"   r$   r%   r&   r   r   r   r   r   r      s>    E3L#KL#M3Kr   r   c                   N    \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\\S	'   S
r
g)AsciiDirectedGlyphs"   zL-> lastz|-> midz<-backedge!vertical_edger   Nr   r   r   r   r-   r(   r)   r.   r/   r1   r   r   r   r   r+   r+   "   s*    D#CHcM3r   r+   c                   N    \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\\S	'   S
r
g)AsciiUndirectedGlyphs)   zL-- r-   z|-- r.   -r/   |r1   r   Nr2   r   r   r   r4   r4   )   s*    D#CHcM3r   r4   c                   j    \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\\S	'   S
r
\\S'   Sr\\S'   Srg)UtfBaseGlyphs0   u   ╙r    u
   ╙── r!   u
   ╟── r"   r#   r$   u   ╎   r%   u   │   r&   r   Nr'   r   r   r   r9   r9   0   s@     E3$L#$#K#L#!M3!Kr   r9   c                   N    \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\\S	'   S
r
g)UtfDirectedGlyphs<   u
   └─╼ r-   u
   ├─╼ r.   u   ╾r/   u   ╽r1   r   Nr2   r   r   r   r<   r<   <   *    D#CHcM3r   r<   c                   N    \ rS rSr% Sr\\S'   Sr\\S'   Sr\\S'   Sr	\\S	'   S
r
g)UtfUndirectedGlyphsC   u
   └── r-   u
   ├── r.   u   ─r/   u   │r1   r   Nr2   r   r   r   r@   r@   C   r>   r   r@   c              #   l
  ^(#    SSK Jm(Jn   " U(4S jSU5      nSnU R                  5       n	U	(       a,  U(       a  [        O[
        n
U R                  nU R                  nO+U(       a  [        O[        n
U R                  nU R                  n[        U[        5      (       a  UnOU(       a  SnOSnUS:X  a  U
R                  S-   v   g[        U R                  5      S:X  a  U
R                  v   gUc  [!        U 5      n[        U5      S	-
  n[#        U5       VVs/ s H  u  nnU" SU/ X:H  S
5      PM     snnSSS2   n[%        S 5      n['        5       nU(       Ga  UR)                  5       u  nnnnnU[*        La  UU;   nU(       a  UU==   S	-  ss'   U(       aQ  UU   (       aG  UbD  SnU" U[*        UUS
5      nUR-                  U5        S
nU" UUUUU5      nUR-                  U5        M  U(       a  M  UR/                  U5        U(       dK  U(       a#  S
nUU
R0                  /-   nUU
R2                  /-   nOuUU
R4                  /-   nUU
R6                  /-   nOTU(       a  UnUnOHU(       a!  UU
R8                  /-   nUU
R2                  /-   nO UU
R:                  /-   nUU
R<                  /-   nU[*        L a  SnSn/ nGOUb)  [        U R                  U   R?                  UU5      5      nO[        U5      nUb   U R                  U   R?                  US
5      n OS
n U	(       a  [A        UU   5      nU1n!O#UU    V"s/ s H  n"U"U;  d  M  U"PM     nn"1 UkUin!Ub#  [        U5      US	-
  :X  a  U(       a  [*        /nU1n!U (       a  U(       a  [*        /nU1n!UU    V#s/ s H  n#U#U!;  d  M  U#PM     n$n#U$(       a  UbI  SRC                  U$ V#s/ s H+  n#[        U R                  U#   R?                  UU#5      5      PM-     sn#5      n%O+SRC                  U$ V#s/ s H  n#[        U#5      PM     sn#5      n%SRC                  SU
RD                  U%/5      nOSnU(       a!  SRC                  UU
RF                  /-   5      v   SRC                  UUU/-   5      v   U(       a:  U	(       a  [        ['        U5      5      n&O[        ['        U5      U1-
  5      n&U&S	:H  n'OS
n'[#        USSS2   5       H(  u  nn"US:H  nU" UU"UUU'5      nUR-                  U5        M*     U(       a  GM  ggs  snnf s  sn"f s  sn#f s  sn#f s  sn#f 7f)u  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 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                   N   > \ rS rSr%  Y \S'    Y \S'   \\S'   \\S'   \\S'   Srg)	)generate_network_text.<locals>.StackFrame   parentnodeindentsthis_islastthis_verticalr   N)r   r   r   r   r)   listboolr   rC   s   r   
StackFramerF      s    	r   rP   collapselabelNz ...   Fc                      g)Nr   r   r   r   r   <lambda>'generate_network_text.<locals>.<lambda>
  s    1r   T ,  )$typingrC   rD   is_directedr+   r<   succpredr4   r@   adj
isinstancer(   r    lennodes_find_sources	enumerater   setpopEllipsisappendaddr!   r$   r"   r%   r-   r.   r&   getrM   joinr/   r1   ))graphwith_labelssources	max_depth
ascii_onlyvertical_chainsrD   rP   collapse_attrr\   glyphsr]   r^   
label_attrlast_idxidxrI   stacknum_skipped_children
seen_nodesrH   rJ   rK   rL   skipnext_islast	try_framethis_prefixnext_prefixrR   suffixchildrenrQ   handled_parentschildpother_parentsother_parents_labelsnum_childrennext_is_verticalrC   s)                                           @r   r   r   J   s7    Z 'Z  M##%K(2$8Izzzz*4&:Myyyy+s## 
	

A~llV##	U[[	Q	ll ?#E*G w<!# 'w/
/	T tT2%@/
 B$
  +95U
@E		=FD';8#z)(0A50 ,F38J&*$. (G[%%	 Y/ ',$."D';%	 Y/ t$ $)M")V-@-@,A"AK")V-@-@,A"AK")V-?-?,@"@K")V-A-A,B"BK !")K")K"&-&=&-1D1D0E&E&-&<&-1C1C0D&Dx)D 1 5 5j$ GHEIE !,${{4044]EJH$H
   $DJ/H (.hO
 ,0: +5%j9P:    ':&9&&9O(S\Y]-J$,:'-hO$,:'-hO -1J SJq!?:RJ S !-/3yy *7)6A !$EKKN$6$6z1$E F)60, 04yy-:;]SV];0, !XXr6??<P&QRFF ggkV-A-A,BBCC''+788#&s8}#5L#&s8}x'?#@L $01#4 #(  (27
U!Qh&%k;K	 Y' 8g e
| . !T <sW   DT4T3HT48
T T AT4
T%'T%-T42T*:T4T/&C/T4T4rS   wc           	         Uc  [         R                  R                  nOE[        US5      (       a  UR                  nO'[	        U5      (       a  UnO[        [        U5      5      e[        U UUUUUS9 H  n	U" X-   5        M     g)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)rm   rn   ro   rp   rq   )sysstdoutr   hasattrcallable	TypeErrortyper   )
rl   pathrm   rn   ro   rp   endrq   _writelines
             r   r   r     sy    J |!!	w			$T
##%' 	tzr   c                   ^  T R                  5       (       a  [        [        R                  " T 5      5      n[        R                  " T U5      nUR                  5        Vs0 s H  o3/ _M     nnUR                  S   nT R
                   H  nXV   nXC   R                  U5        M     / nUR                  5        H;  nUR                  U   S:X  d  M  XC   n[        UU 4S jS9n	UR                  U	5        M=     U$ [        R                  " T 5       V
s/ s H  n
[        U
U 4S jS9PM     nn
[        UU 4S jS9nU$ s  snf s  sn
f )zJ
Determine a minimal set of nodes such that the entire graph is reachable
mappingr   c                 "   > TR                   U    $ N)	in_degreenrl   s    r   rV   _find_sources.<locals>.<lambda>{  s    eooa.@r   )keyc                 "   > TR                   U    $ r   degreer   s    r   rV   r     s    %,,q/r   c                 "   > TR                   U    $ r   r   r   s    r   rV   r     s    Qr   )r\   rM   nxstrongly_connected_componentscondensationrb   rl   rh   r   minconnected_componentssorted)rl   sccs	scc_graphsnsupernode_to_nodesr   r   rn   sccrI   ccs   `          r   rc   rc   c  s8    B44U;< OOE40	/8/@A/@"f/@A //),AB"))!,  //#B""2&!+(,3$@At$	 $ N --e4
4 124 	 
 &?@N+ B 
s   D;E c                 b
  ^)^* SSK Jn  SSKJm)JnJn   " U)4S jSU5      n[        U 5      nSnSn/ n [        U5      n	UR                  U	5        U	S   n
U
[        R                  [        R                  S   [        R                  S   1;   a  SnOJU
[        R                  [        R                  S   [        R                  S   1;   a  SnO[        S	U
 35      eU(       a)  [         R#                  5       n[$        R#                  5       nO([&        R#                  5       n[(        R#                  5       n[+        UR-                  5       5      n[+        UR-                  5       5      n/ nU H9  nUnU Vs/ s H  nUU;   d  M  UPM     nnU(       a  M(  UR                  U5        M;     / nU H9  nUnU Vs/ s H  nUU;   d  M  UPM     nnU(       a  M(  UR                  U5        M;     U HP  m*UR                  T*5        [/        U*4S
 jU 5       5      (       a  Sn  O"[/        U*4S jU 5       5      (       d  MN  Sn  O   Uc  SnU(       a  UOUnSUS   -   S-   nU" X5      n/ n/ nSn[1        5       nU" USS5      /nU GH!  m*T*US   :X  a  SnM  UT*;   a  T*R3                  U5      u  nnUR3                  S5       Vs/ s H  nUR5                  5       PM     n nUR7                  5       nUR9                  SS5      u  n!n"U"R5                  5       n"UR;                  U  Vs/ s H  nUU"4PM	     sn5        O%T*R9                  SS5      u  n!n"U"R5                  5       n"UR=                  5       n#U"US   ;   a2  U" U#R>                  U#R@                  S5      n$UR                  U$5        GM$  [C        U!5      n%U" U"U%S5      n&U#RD                  (       a  OFU&R@                  U#R@                  ::  a,  UR=                  5       n#U&R@                  U#R@                  ::  a  M,  U"S:X  a  UR                  U#5        GM  UR                  U#5        UR                  U&5        UR                  U&R>                  5        U#R>                  ULd  GM  UR                  U#R>                  U&R>                  45        GM$     U(       a  [C        U5      S:X  d   eU(       a  [F        RH                  O[F        RJ                  n'U'" 5       n(U(RM                  U5        U(RO                  U5        U($ ! [         a     GN?f = fs  snf s  snf s  snf s  snf )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)rC   rD   Unionc                   >   > \ rS rSr%  Y \S'   \\S'   \S-  \S'   Srg),_parse_network_text.<locals>.ParseStackFramei  rI   indentNhas_vertical_childr   )r   r   r   r   r)   intr   rO   s   r   ParseStackFramer     s    	$J&r   r   NFTzUnexpected first character: c              3   ,   >#    U  H	  oT;   v   M     g 7fr   r   .0itemr   s     r   	<genexpr>&_parse_network_text.<locals>.<genexpr>  s     E(Dt|(D   c              3   ,   >#    U  H	  oT;   v   M     g 7fr   r   r   s     r   r   r     s     E*D$*Dr   rZ   r/   rT   r    rY   rS   r1   z...)(	itertoolsr   r[   rC   rD   r   iternextrh   r9   r    r"   r!   r   AssertionErrorStopIterationr+   r   r4   r<   r@   re   valuesanyobjectsplitstriprstriprsplitextendrf   rI   r   ra   r   r   DiGraphGraphadd_nodes_fromadd_edges_from)+linesr   rD   r   r   initial_line_iteris_asciir\   initial_lines
first_line
first_chardirected_glyphsundirected_glyphsdirected_itemsundirected_itemsunambiguous_directed_itemsr   other_itemsotherother_supersetsunambiguous_undirected_itemsrs   backedge_symbolparsing_line_iteredgesrb   is_emptynoparentrw   	node_partbackedge_partubackedge_nodesprefixrI   prevmodified_prevr   currr   newrC   r   s+                                            @@r   _parse_network_textr     s   &  --'* '
 UHK MN+,
 	Z(]
%%a(&&q)
 

 H!!''*((+
 

 H #?
|!LMM-557199;+335/779 //12N,3356!#&.9KkUTU]5kK&--d3	 
 $&  $.9KkUTU]5kK(//5	 ! "T"E(DEEEKE*DEEEK "  +_1BF F:..4O m? EEHxH Xr401E!6'?" Hd"'+zz/'B$I}1>1D1DT1JK1JAaggi1JNK!((*I$++C3LFD::<DLL^<^1d)^<=  ;;sA.LFD::<Dyy{6/** ,		M
 LL'
 VtVT2""  ++,yy{ ++, 5= LL LLLL LL#yy(dii34K "N 5zQ $"**C
%CuuJE  J L Lb L =s5   T 1
T?T2
T" T":T'T,

TT)TNNFF)NTNNF
F)__doc__r   warningscollectionsr   networkxr   networkx.utilsr   __all__r   r   r+   r4   r9   r<   r@   r   r   rc   r   r   r   r   <module>r      s      #  $"$8
9
 
j / O 	 J 	  -  Z(z
 1c 
x xv"JLr   