
    hl                     b    S SK rSS/rSSS.r\4S jr\R
                  " SSS	9S
S\4S j5       rg)    Nadjacency_dataadjacency_graphidkey)r   r   c           
         U R                  5       nUS   nU(       d  SOUS   nX4:X  a  [        R                  " S5      e0 nU R                  5       US'   X%S'   [	        U R
                  R                  5       5      US'   / US'   / US	'   U R                  5        H  u  pgUS   R                  0 U R                  U   EX60E5        / nU(       aJ  UR                  5        H5  u  pU
R                  5        H  u  pUR                  0 UEX9XK0E5        M     M7     O/UR                  5        H  u  pUR                  0 UEX90E5        M     US	   R                  U5        M     U$ )
a  Returns data in adjacency format that is suitable for JSON serialization
and use in JavaScript documents.

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

attrs : dict
    A dictionary that contains two keys 'id' and 'key'. The corresponding
    values provide the attribute names for storing NetworkX-internal graph
    data. The values should be unique. Default value:
    :samp:`dict(id='id', key='key')`.

    If some user-defined graph data use these attribute names as data keys,
    they may be silently dropped.

Returns
-------
data : dict
   A dictionary with adjacency formatted data.

Raises
------
NetworkXError
    If values in attrs are not unique.

Examples
--------
>>> from networkx.readwrite import json_graph
>>> G = nx.Graph([(1, 2)])
>>> data = json_graph.adjacency_data(G)

To serialize with json

>>> import json
>>> s = json.dumps(data)

Notes
-----
Graph, node, and link attributes will be written when using this format
but attribute keys must be strings if you want to serialize the resulting
data with JSON.

The default value of attrs will be changed in a future release of NetworkX.

See Also
--------
adjacency_graph, node_link_data, tree_data
r   Nr   zAttribute names are not unique.directed
multigraphgraphnodes	adjacency)
is_multigraphnxNetworkXErroris_directedlistr
   itemsr   appendr   )Gattrsr	   id_r   datannbrdictadjnbrkeyskds                Y/var/www/html/env/lib/python3.13/site-packages/networkx/readwrite/json_graph/adjacency.pyr   r      sD   d "J
+C $eElC
z@AAD}}D#)DMDMDkkm
W3
3C34$]]_	 JJLDAJJ6!6Ss67 ) - "--/

?a??+ *[  % $ K    T)graphsreturns_graphFc                    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S   nU(       d  SOUS   n[        U R                  S/ 5      5      Ul        / nU S    Hd  nUR                  5       n	U	R                  U5      n
UR                  U
5        UR                  U
5        UR                  U
   R                  U	5        Mf     [        U S   5       H  u  pX{   nU H  nUR                  5       nUR                  U5      nU(       d)  UR                  X5        XL   U   R                  U5        MT  UR                  US5      nUR                  XUS	9  XL   U   U   R                  U5        M     M     U$ )
a  Returns graph from adjacency data format.

Parameters
----------
data : dict
    Adjacency list 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.

attrs : dict
    A dictionary that contains two keys 'id' and 'key'. The corresponding
    values provide the attribute names for storing NetworkX-internal graph
    data. The values should be unique. Default value:
    :samp:`dict(id='id', key='key')`.

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

Examples
--------
>>> from networkx.readwrite import json_graph
>>> G = nx.Graph([(1, 2)])
>>> data = json_graph.adjacency_data(G)
>>> H = json_graph.adjacency_graph(data)

Notes
-----
The default value of attrs will be changed in a future release of NetworkX.

See Also
--------
adjacency_graph, node_link_data, tree_data
r	   r   r   Nr   r
   r   r   )r   )getr   
MultiGraphGraphto_directeddictr
   copypopr   add_noder   update	enumerateadd_edge)r   r   r	   r   r
   r   r   mappingr   	node_datanodeisourcetdatatarget_datatargetkys                    r   r   r   T   s~   R ,
3Jxx
H-H
!!#
+C $eElCtxx,-EKG']FFH	}}S!ttD  +  ${+,E**,K __S)Fv.f%,,[9 __S$/v26f%b)00=  - Lr    )networkxr   __all___attrsr   _dispatchabler    r    r   <module>r=      sS    .
/U	# # IX T2#(T G 3Gr    