
    h%,                         S r / SQrSSKrSSKJr  SS jr\" SSS9SS	 j5       r\R                  " SS
S9 SS j5       r	\" SSS9\R                  " SS
S9      SS j5       5       r
g)a  
*************************
Multi-line Adjacency List
*************************
Read and write NetworkX graphs as multi-line adjacency lists.

The multi-line adjacency list format is useful for graphs with
nodes that can be meaningfully represented as strings.  With this format
simple edge data can be stored but node or graph data is not.

Format
------
The first label in a line is the source node label followed by the node degree
d.  The next d lines are target node labels and optional edge data.
That pattern repeats for all nodes in the graph.

The graph with edges a-b, a-c, d-e can be represented as the following
adjacency list (anything following the # in a line is a comment)::

     # example.multiline-adjlist
     a 2
     b
     c
     d 1
     e
)generate_multiline_adjlistwrite_multiline_adjlistparse_multiline_adjlistread_multiline_adjlist    N)	open_filec           
   #     #    U R                  5       (       GaZ  U R                  5       (       a  U R                  5        H  u  p#UR                  5        VVVVs/ s H"  u  pEUR                  5         H  u  pgXG4PM
     M$     nnnnn[	        U5      n	[        U5      U-   [        U	5      -   v   U H3  u  pJU
c  [        U5      v   M  [        U5      U-   [        U
5      -   v   M5     M     gU R                  5        Hs  u  p#[	        U5      n	[        U5      U-   [        U	5      -   v   UR                  5        H3  u  pJU
c  [        U5      v   M  [        U5      U-   [        U
5      -   v   M5     Mu     gU R                  5       (       a  [        5       nU R                  5        H  u  p#UR                  5        VVVVs/ s H)  u  pEXK;  d  M  UR                  5         H  u  pgXG4PM
     M+     nnnnn[	        U5      n	[        U5      U-   [        U	5      -   v   U H3  u  pJU
c  [        U5      v   M  [        U5      U-   [        U
5      -   v   M5     UR                  U5        M     g[        5       nU R                  5        H  u  p#UR                  5        VV
s/ s H  u  pJXK;  d  M  XJ4PM     nnn
[	        U5      n	[        U5      U-   [        U	5      -   v   U H3  u  pJU
c  [        U5      v   M  [        U5      U-   [        U
5      -   v   M5     UR                  U5        M     gs  snnnnf s  snnnnf s  sn
nf 7f)a  Generate a single line of the graph G in multiline adjacency list format.

Parameters
----------
G : NetworkX graph

delimiter : string, optional
   Separator for node labels

Returns
-------
lines : string
    Lines of data in multiline adjlist format.

Examples
--------
>>> G = nx.lollipop_graph(4, 3)
>>> for line in nx.generate_multiline_adjlist(G):
...     print(line)
0 3
1 {}
2 {}
3 {}
1 2
2 {}
3 {}
2 1
3 {}
3 1
4 {}
4 1
5 {}
5 1
6 {}
6 0

See Also
--------
write_multiline_adjlist, read_multiline_adjlist
N)is_directedis_multigraph	adjacencyitemslenstrsetadd)G	delimitersnbrsudatadictkeydata	nbr_edgesdegdseens               V/var/www/html/env/lib/python3.13/site-packages/networkx/readwrite/multiline_adjlist.pyr   r   '   s    R 	}}??;;= (,zz|'3%-^^%5	 I%5 '3  
 )n!fy(3s833%DAy!!f!!fy03q699	 & ) ;;=$i!fy(3s833 JJLDAy!!f!!fy03q699	 ) ) ??5D;;= (,zz|'3}  &.^^%5	 I &6 '3   )n!fy(3s833%DAy!!f!!fy03q699	 &
  )  5D;;=04

NVaV	N)n!fy(3s833%DAy!!f!!fy03q699	 &
  )S2" Os9   AL>)L(D;L><L0!L0,B-L>L8(L8/BL>   wb)modec                 ~   SSK nSSKnUSR                  UR                  5      -   nU S3U-   SUR	                  UR                  5       5       S3-   U-   SU R                   S3-   nUR                  UR                  U5      5        [        X5       H(  n	U	S-  n	UR                  U	R                  U5      5        M*     g)aD  Write the graph G in multiline adjacency list format to path

Parameters
----------
G : NetworkX graph

path : string or file
   Filename or file handle to write to.
   Filenames ending in .gz or .bz2 will be compressed.

comments : string, optional
   Marker for comment lines

delimiter : string, optional
   Separator for node labels

encoding : string, optional
   Text encoding.

Examples
--------
>>> G = nx.path_graph(4)
>>> nx.write_multiline_adjlist(G, "test.adjlist")

The path can be a file handle or a string with the name of the file. If a
file handle is provided, it has to be opened in 'wb' mode.

>>> fh = open("test.adjlist", "wb")
>>> nx.write_multiline_adjlist(G, fh)

Filenames ending in .gz or .bz2 will be compressed.

>>> nx.write_multiline_adjlist(G, "test.adjlist.gz")

See Also
--------
read_multiline_adjlist
r   N 
z GMT )
systimejoinargvasctimegmtimenamewriteencoder   )
r   pathr   commentsencodingr$   r%   pargsheader	multilines
             r   r   r      s    P sxx))E'
	$,,t{{}-.b
1	2 	 affXR.		  	JJv}}X&'/=	T	

9##H-. >    T)graphsreturns_graphc           	      P   SSK Jn  [        R                  " SU5      nU  GHF  nUR	                  U5      n	U	S:  a  USU	 nU(       d  M)   UR                  S5      R                  U5      u  p[        U5      nUb	   U" U
5      n
UR                  U
5        [        U5       H  n  [        U 5      nUR	                  U5      n	U	S:  a  USU	 nU(       a  OM2  UR                  S5      R                  U5      n[        U5      nUS
:  a  Mi  UR                  S5      nSR!                  U5      nUb	   U" U5      nUb   SU" U5      0nO	 U" U5      nUR"                  " U
U40 UD6  M     GMI     U$ ! [         a  n[        SU S35      UeSnAff = f! [         a  n[        SU
 SU 35      UeSnAff = f! [         a  nS	U
 S3n[        U5      UeSnAff = f! [         a  n[        SU SU 35      UeSnAff = f! [         a  n[        SU SU 35      UeSnAff = f!   0 n N= f)a  Parse lines of a multiline adjacency list representation of a graph.

Parameters
----------
lines : list or iterator of strings
    Input data in multiline adjlist format

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

nodetype : Python type, optional
   Convert nodes to this type.

edgetype : Python type, optional
   Convert edges to this type.

comments : string, optional
   Marker for comment lines

delimiter : string, optional
   Separator for node labels.  The default is whitespace.

Returns
-------
G: NetworkX graph
    The graph corresponding to the lines in multiline adjacency list format.

Examples
--------
>>> lines = [
...     "1 2",
...     "2 {'weight':3, 'name': 'Frodo'}",
...     "3 {}",
...     "2 1",
...     "5 {'weight':6, 'name': 'Saruman'}",
... ]
>>> G = nx.parse_multiline_adjlist(iter(lines), nodetype=int)
>>> list(G)
[1, 2, 3, 5]

r   )literal_evalNr#   z(Failed to read node and degree on line ()zFailed to convert node (z
) to type z"Failed to find neighbor for node (r    weightzFailed to convert edge data ()astr7   nxempty_graphfindrstripsplitintBaseException	TypeErroradd_noderangenextStopIterationr   popr&   add_edge)linesr.   r   create_usingnodetypeedgetyper7   r   linepr   r   errimsgvlistnumbvr   edgedatas                       r   r   r      s{   Z !
q,'AIIh68D	Y{{4(..y9HQc(C QK
 	


1sA2;D IIh'68D  KK%++I6Eu:Dax		!A775>D# A
 # ((4.9H"+D1H JJq!(x(K ' t Hc  	YFtfANOUXX	Y
 ! .qcH:F % 2>qcCC#C.c12" % #21#ZzJ % #7vZzR"!Hs   
-E-;F$F3.G:
G;H-
F7FF
F0F++F03
G=GG
G8!G33G8;
HHHH%rbc           	      8   ^ U4S jU  5       n[        UUUUUUS9$ )a&  Read graph in multi-line adjacency list format from path.

Parameters
----------
path : string or file
   Filename or file handle to read.
   Filenames ending in .gz or .bz2 will be uncompressed.

create_using : NetworkX graph constructor, optional (default=nx.Graph)
   Graph type to create. If graph instance, then cleared before populated.

nodetype : Python type, optional
   Convert nodes to this type.

edgetype : Python type, optional
   Convert edge data to this type.

comments : string, optional
   Marker for comment lines

delimiter : string, optional
   Separator for node labels.  The default is whitespace.

Returns
-------
G: NetworkX graph

Examples
--------
>>> G = nx.path_graph(4)
>>> nx.write_multiline_adjlist(G, "test.adjlist")
>>> G = nx.read_multiline_adjlist("test.adjlist")

The path can be a file or a string with the name of the file. If a
file s provided, it has to be opened in 'rb' mode.

>>> fh = open("test.adjlist", "rb")
>>> G = nx.read_multiline_adjlist(fh)

Filenames ending in .gz or .bz2 will be compressed.

>>> nx.write_multiline_adjlist(G, "test.adjlist.gz")
>>> G = nx.read_multiline_adjlist("test.adjlist.gz")

The optional nodetype is a function to convert node strings to nodetype.

For example

>>> G = nx.read_multiline_adjlist("test.adjlist", nodetype=int)

will attempt to convert all nodes to integer type.

The optional edgetype is a function to convert edge data strings to
edgetype.

>>> G = nx.read_multiline_adjlist("test.adjlist")

The optional create_using parameter is a NetworkX graph container.
The default is Graph(), an undirected graph.  To read the data as
a directed graph use

>>> G = nx.read_multiline_adjlist("test.adjlist", create_using=nx.DiGraph)

Notes
-----
This format does not store graph, node, or edge data.

See Also
--------
write_multiline_adjlist
c              3   D   >#    U  H  oR                  T5      v   M     g 7f)N)decode).0rN   r/   s     r   	<genexpr>)read_multiline_adjlist.<locals>.<genexpr>  s     4tt[[""ts    )r.   r   rK   rL   rM   )r   )r-   r.   r   rK   rL   rM   r/   rJ   s         ` r   r   r   /  s/    d 5t4E"! r3   )r"   )r"   #utf-8)r^   NNNN)r^   NNNNr_   )__doc____all__networkxr<   networkx.utilsr   r   r   _dispatchabler   r    r3   r   <module>rf      s   6  $^B 146/ 6/r T2TXi 3iX 14T2 X 3 Xr3   