
    h(*              
           S SK r S SKJr  S SKrSS/rS rSSSS	SS
SS.S jr\R                  " SSS9  SSSSS	SS
SS.S jj5       r	g)    N)countnode_link_datanode_link_graphc                 p    [        U [        [        -  5      (       d  U $ [        [        [        U 5      5      $ )a  Converts lists to tuples, including nested lists.

All other non-list inputs are passed through unmodified. This function is
intended to be used to convert potentially nested lists from json files
into valid nodes.

Examples
--------
>>> _to_tuple([1, 2, [3, 4]])
(1, 2, (3, 4))
)
isinstancetuplelistmap	_to_tuple)xs    Y/var/www/html/env/lib/python3.13/site-packages/networkx/readwrite/json_graph/node_link.pyr   r   	   s,     a&&Y"##    sourcetargetidkeynodes)r   r   namer   edgesr   linkc                   Ub+  [         R                  " S[        SS9  Ub  [        S5      eUnO Uc  [         R                  " S[        5        SnU R                  5       nU(       d  SOUn[        XU15      S:  a  [        R                  " S	5      eS
U R                  5       SUSU R                  X` V	s/ s H  n	0 U R                  U	   EX90EPM     sn	0n
U(       a5  U R                  SSS9 VVVVs/ s H  u  pp0 UEXX,XM0EPM     snnnnX'   U
$ U R                  SS9 VVVs/ s H  u  pn0 UEXX,0EPM     snnnX'   U
$ s  sn	f s  snnnnf s  snnnf )a
  Returns data in node-link format that is suitable for JSON serialization
and use in JavaScript documents.

Parameters
----------
G : NetworkX graph
source : string
    A string that provides the 'source' attribute name for storing NetworkX-internal graph data.
target : string
    A string that provides the 'target' attribute name for storing NetworkX-internal graph data.
name : string
    A string that provides the 'name' attribute name for storing NetworkX-internal graph data.
key : string
    A string that provides the 'key' attribute name for storing NetworkX-internal graph data.
edges : string
    A string that provides the 'edges' attribute name for storing NetworkX-internal graph data.
nodes : string
    A string that provides the 'nodes' attribute name for storing NetworkX-internal graph data.
link : string
    .. deprecated:: 3.4

       The `link` argument is deprecated and will be removed in version `3.6`.
       Use the `edges` keyword instead.

    A string that provides the 'edges' attribute name for storing NetworkX-internal graph data.

Returns
-------
data : dict
   A dictionary with node-link formatted data.

Raises
------
NetworkXError
    If the values of 'source', 'target' and 'key' are not unique.

Examples
--------
>>> from pprint import pprint
>>> G = nx.Graph([("A", "B")])
>>> data1 = nx.node_link_data(G, edges="edges")
>>> pprint(data1)
{'directed': False,
 'edges': [{'source': 'A', 'target': 'B'}],
 'graph': {},
 'multigraph': False,
 'nodes': [{'id': 'A'}, {'id': 'B'}]}

To serialize with JSON

>>> import json
>>> s1 = json.dumps(data1)
>>> s1
'{"directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "A"}, {"id": "B"}], "edges": [{"source": "A", "target": "B"}]}'

A graph can also be serialized by passing `node_link_data` as an encoder function.

>>> s1 = json.dumps(G, default=nx.node_link_data)
>>> s1
'{"directed": false, "multigraph": false, "graph": {}, "nodes": [{"id": "A"}, {"id": "B"}], "links": [{"source": "A", "target": "B"}]}'

The attribute names for storing NetworkX-internal graph data can
be specified as keyword options.

>>> H = nx.gn_graph(2)
>>> data2 = nx.node_link_data(
...     H, edges="links", source="from", target="to", nodes="vertices"
... )
>>> pprint(data2)
{'directed': True,
 'graph': {},
 'links': [{'from': 1, 'to': 0}],
 'multigraph': False,
 'vertices': [{'id': 0}, {'id': 1}]}

Notes
-----
Graph, node, and link attributes are stored in this format.  Note that
attribute keys will be converted to strings in order to comply with JSON.

Attribute 'key' is only used for multigraphs.

To use `node_link_data` in conjunction with `node_link_graph`,
the keyword names for the attributes must match.

See Also
--------
node_link_graph, adjacency_data, tree_data
N:Keyword argument 'link' is deprecated; use 'edges' instead   
stacklevel]Both 'edges' and 'link' are specified. Use 'edges', 'link' will be remove in a future releasea  
The default value will be `edges="edges" in NetworkX 3.6.

To make this warning go away, explicitly set the edges kwarg, e.g.:

  nx.node_link_data(G, edges="links") to preserve current behavior, or
  nx.node_link_data(G, edges="edges") for forward compatibility.links   zAttribute names are not unique.directed
multigraphgraphT)keysdata)r#   )warningswarnDeprecationWarning
ValueErrorFutureWarningis_multigraphlennxNetworkXErroris_directedr!   r   r   )Gr   r   r   r   r   r   r   r    nr#   uvkds                  r   r   r      s   L H	

 o  E=MMW
  E "J !$cC
FC !A%@AAAMMOj3A'1771:'t'3	D   gg4dg;
;
a 0q/&V/;
 K CD''t'BTUBTwqQ2!2V2BTUK 4

 Vs   3E1E
$ET)graphsreturns_graphc          	      &   U	b+  [         R                  " S[        SS9  Ub  [        S5      eU	nO Uc  [         R                  " S[        5        SnU R                  SU5      nU R                  S	U5      nU(       a  [        R                  " 5       n
O[        R                  " 5       n
U(       a  U
R                  5       n
U(       d  SOUnU R                  S
0 5      U
l
        [        5       nX    Ho  n[        UR                  U[        U5      5      5      nUR                  5        VVs0 s H  u  pX:w  d  M  [        U5      U_M     nnnU
R                   " U40 UD6  Mq     X    GH  n[#        X   [$        5      (       a  ['        X   5      OX   n[#        X   [$        5      (       a  ['        X   5      OX   nU(       dR  UR                  5        VVs0 s H  u  pX:w  d  M  X:w  d  M  [        U5      U_M!     nnnU
R(                  " UU40 UD6  M  UR                  US5      nUR                  5        VVs0 s H&  u  pX:w  d  M  X:w  d  M  X:w  d  M  [        U5      U_M(     nnnU
R(                  " UUU40 UD6  GM     U
$ s  snnf s  snnf s  snnf )a  Returns graph from node-link data format.

Useful for de-serialization from JSON.

Parameters
----------
data : dict
    node-link formatted graph data

directed : bool
    If True, and direction not specified in data, return a directed graph.

multigraph : bool
    If True, and multigraph not specified in data, return a multigraph.

source : string
    A string that provides the 'source' attribute name for storing NetworkX-internal graph data.
target : string
    A string that provides the 'target' attribute name for storing NetworkX-internal graph data.
name : string
    A string that provides the 'name' attribute name for storing NetworkX-internal graph data.
key : string
    A string that provides the 'key' attribute name for storing NetworkX-internal graph data.
edges : string
    A string that provides the 'edges' attribute name for storing NetworkX-internal graph data.
nodes : string
    A string that provides the 'nodes' attribute name for storing NetworkX-internal graph data.
link : string
    .. deprecated:: 3.4

       The `link` argument is deprecated and will be removed in version `3.6`.
       Use the `edges` keyword instead.

    A string that provides the 'edges' attribute name for storing NetworkX-internal graph data.

Returns
-------
G : NetworkX graph
    A NetworkX graph object

Examples
--------

Create data in node-link format by converting a graph.

>>> from pprint import pprint
>>> G = nx.Graph([("A", "B")])
>>> data = nx.node_link_data(G, edges="edges")
>>> pprint(data)
{'directed': False,
 'edges': [{'source': 'A', 'target': 'B'}],
 'graph': {},
 'multigraph': False,
 'nodes': [{'id': 'A'}, {'id': 'B'}]}

Revert data in node-link format to a graph.

>>> H = nx.node_link_graph(data, edges="edges")
>>> print(H.edges)
[('A', 'B')]

To serialize and deserialize a graph with JSON,

>>> import json
>>> d = json.dumps(nx.node_link_data(G, edges="edges"))
>>> H = nx.node_link_graph(json.loads(d), edges="edges")
>>> print(G.edges, H.edges)
[('A', 'B')] [('A', 'B')]


Notes
-----
Attribute 'key' is only used for multigraphs.

To use `node_link_data` in conjunction with `node_link_graph`,
the keyword names for the attributes must match.

See Also
--------
node_link_data, adjacency_data, tree_data
Nr   r   r   r   a  
The default value will be changed to `edges="edges" in NetworkX 3.6.

To make this warning go away, explicitly set the edges kwarg, e.g.:

  nx.node_link_graph(data, edges="links") to preserve current behavior, or
  nx.node_link_graph(data, edges="edges") for forward compatibility.r   r    r   r!   )r$   r%   r&   r'   r(   getr+   
MultiGraphGraphto_directedr!   r   r   nextitemsstradd_noder   r	   r   add_edge)r#   r   r    r   r   r   r   r   r   r   r!   cr3   noder2   r1   nodedatasrctgtedgedatakys                        r   r   r      sN   B H	

 o  E=MM[
  E ,
3Jxx
H-H
!!# !$cC((7B'EKA[tT!W-.*+'')A)$!qyICFAI)At(x(  [",QY"="=eAI19",QY"="=eAI19./ggiWida1;	1;	A	iHWNN30x0sD!B GGI%DA; #$; 348 A	%  
 NN3R484  L! B Xs6   &J5JJ J'J5JJJJ)FT)
r$   	itertoolsr   networkxr+   __all__r   r   _dispatchabler    r   r   <module>rL      s      .
/$( 	

	Sl T2 Y
 	

	Y 3Yr   