Ë
    D^(hw%  ã                   óê   — d Z ddlmZ ddlZddlmZ g d¢Z edd¬«      d	„ «       Z edd
¬«       ej                  ddd¬«      d„ «       «       Z
 ej                  dd¬«      d„ «       Zd„ Zdd„Zdd„Zy)aÈ  
*****
Pydot
*****

Import and export NetworkX graphs in Graphviz dot format using pydot.

Either this module or nx_agraph can be used to interface with graphviz.

Examples
--------
>>> G = nx.complete_graph(5)
>>> PG = nx.nx_pydot.to_pydot(G)
>>> H = nx.nx_pydot.from_pydot(PG)

See Also
--------
 - pydot:         https://github.com/erocarrera/pydot
 - Graphviz:      https://www.graphviz.org
 - DOT Language:  http://www.graphviz.org/doc/info/lang.html
é    )ÚgetpreferredencodingN)Ú	open_file)Ú	write_dotÚread_dotÚgraphviz_layoutÚpydot_layoutÚto_pydotÚ
from_pydoté   Úw)Úmodec                 óX   — t        | «      }|j                  |j                  «       «       y)zgWrite NetworkX graph G to Graphviz dot format on path.

    Path can be a string or a file handle.
    N)r	   ÚwriteÚ	to_string)ÚGÚpathÚPs      úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/drawing/nx_pydot.pyr   r   &   s"   € ô 	�‹€AØ‡J�Jˆq�{‰{‹}ÔØ
ó    ÚrÚpydot_read_dotT)ÚnameÚgraphsÚreturns_graphc                 óh   — ddl }| j                  «       }|j                  |«      }t        |d   «      S )aO  Returns a NetworkX :class:`MultiGraph` or :class:`MultiDiGraph` from the
    dot file with the passed path.

    If this file contains multiple graphs, only the first such graph is
    returned. All graphs _except_ the first are silently ignored.

    Parameters
    ----------
    path : str or file
        Filename or file handle.

    Returns
    -------
    G : MultiGraph or MultiDiGraph
        A :class:`MultiGraph` or :class:`MultiDiGraph`.

    Notes
    -----
    Use `G = nx.Graph(nx.nx_pydot.read_dot(path))` to return a :class:`Graph` instead of a
    :class:`MultiGraph`.
    r   N)ÚpydotÚreadÚgraph_from_dot_datar
   )r   r   ÚdataÚP_lists       r   r   r   1   s5   € ó0 à�9‰9‹;€Dð ×&Ñ& tÓ,€Fô �f˜Q‘iÓ Ð r   )r   r   c                 ór  — | j                  d«      rd}nd}| j                  «       dk(  r,|rt        j                  «       }n@t        j                  «       }n+|rt        j
                  «       }nt        j                  «       }| j                  «       j                  d«      }|dk7  r||_	        | j                  «       D ]G  }|j                  «       j                  d«      }|dv rŒ' |j                  |fi |j                  «       ¤Ž ŒI | j                  «       D �]  }|j                  «       }|j                  «       }|j                  «       }	g }
g }t!        |t"        «      r!|
j%                  |j                  d«      «       n*|d   D ]"  }|
j%                  |j                  d«      «       Œ$ t!        |t"        «      r!|j%                  |j                  d«      «       n*|d   D ]"  }|j%                  |j                  d«      «       Œ$ |
D ]  }|D ]  } |j&                  ||fi |	¤Ž Œ Œ �Œ | j                  «       }|r||j(                  d<   	 | j+                  «       d	   |j(                  d
<   	 | j1                  «       d	   |j(                  d<   |S # t,        t.        f$ r Y Œ4w xY w# t,        t.        f$ r Y |S w xY w)aØ  Returns a NetworkX graph from a Pydot graph.

    Parameters
    ----------
    P : Pydot graph
      A graph created with Pydot

    Returns
    -------
    G : NetworkX multigraph
        A MultiGraph or MultiDiGraph.

    Examples
    --------
    >>> K5 = nx.complete_graph(5)
    >>> A = nx.nx_pydot.to_pydot(K5)
    >>> G = nx.nx_pydot.from_pydot(A)  # return MultiGraph

    # make a Graph instead of MultiGraph
    >>> G = nx.Graph(nx.nx_pydot.from_pydot(A))

    NFTÚgraphú"Ú )Únoder"   ÚedgeÚnodesr   r%   r&   )Ú
get_strictÚget_typeÚnxÚ
MultiGraphÚGraphÚMultiDiGraphÚDiGraphÚget_nameÚstripr   Úget_node_listÚadd_nodeÚget_attributesÚget_edge_listÚ
get_sourceÚget_destinationÚ
isinstanceÚstrÚappendÚadd_edger"   Úget_node_defaultsÚ
IndexErrorÚ	TypeErrorÚget_edge_defaults)r   Ú
multiedgesÚNr   ÚpÚnÚeÚuÚvÚattrÚsÚdÚunodesÚvnodesÚsource_nodeÚdestination_nodeÚpattrs                    r   r
   r
   T   s‰  € ð2 	‡|�|�DÔØ‰
àˆ
à‡z�zƒ|�wÒÙÜ—‘“‰Aä—‘“
‰AáÜ—‘Ó!‰Aä—
‘
“ˆAð �:‰:‹<×Ñ˜cÓ"€DØˆr‚zØˆŒð �_‰_Óò ,ˆØ�J‰J‹L×Ñ˜sÓ#ˆØÐ)Ñ)ØØˆ�
‰
�1Ñ+˜×(Ñ(Ó*Ó+ð	,ð �_‰_Óó BˆØ�L‰L‹NˆØ×ÑÓˆØ×ÑÓ!ˆØˆØˆä�aœÔØ�H‰H�Q—W‘W˜S“\Õ"à˜G™*ò ,�Ø—‘˜Ÿ™ cÓ*Õ+ð,ô �aœÔØ�H‰H�Q—W‘W˜S“\Õ"à˜G™*ò ,�Ø—‘˜Ÿ™ cÓ*Õ+ð,ð ò 	BˆKØ$%ò BÐ Ø�—
‘
˜;Ð(8ÑA¸DÓAñBò	Bð'Bð0 ×ÑÓ€EÙØ ˆ�‰�ÑðØ×-Ñ-Ó/°Ñ2ˆ�‰�‰ðØ×-Ñ-Ó/°Ñ2ˆ�‰�‰ð €Høô œ	Ð"ò Ùðûô œ	Ð"ò ØØ€Hðús$   É J É, J# ÊJ ÊJ Ê#J6Ê5J6c           	      óž  — ddl }| j                  «       rd}nd}t        j                  | «      dk(  xr | j	                  «        }| j
                  }| j                  j                  di «      }|dk(  r |j                  d||dœ|¤Ž}n |j                  d|› d�f||dœ|¤Ž}	  |j                  di | j                  d   ¤Ž 	  |j                  di | j                  d	   ¤Ž | j                  d
¬«      D ]i  \  }}|j                  «       D �	�
ci c]  \  }	}
t        |	«      t        |
«      “Œ }}	}
t        |«      } |j                  |fi |¤Ž}|j!                  |«       Œk | j	                  «       r | j#                  d
d
¬«      D ]ˆ  \  }}
}}|j                  «       D �	�
ci c]   \  }	}
|	dk7  sŒt        |	«      t        |
«      “Œ" }}	}
t        |«      t        
«      }
} |j$                  ||
fdt        |«      i|¤Ž}|j'                  |«       ŒŠ |S | j#                  d
¬«      D ]v  \  }}
}|j                  «       D �	�
ci c]  \  }	}
t        |	«      t        |
«      “Œ }}	}
t        |«      t        
«      }
} |j$                  ||
fi |¤Ž}|j'                  |«       Œx |S # t        $ r Y �Œçw xY w# t        $ r Y �Œ×w xY wc c}
}	w c c}
}	w c c}
}	w )a  Returns a pydot graph from a NetworkX graph N.

    Parameters
    ----------
    N : NetworkX graph
      A graph created with NetworkX

    Examples
    --------
    >>> K5 = nx.complete_graph(5)
    >>> P = nx.nx_pydot.to_pydot(K5)

    Notes
    -----

    r   NÚdigraphr"   r$   )Ú
graph_typeÚstrictr#   r%   r&   T)r   )r   ÚkeysÚkey)r$   © )r   Úis_directedr*   Únumber_of_selfloopsÚis_multigraphr   r"   ÚgetÚDotÚset_node_defaultsÚKeyErrorÚset_edge_defaultsr'   Úitemsr8   ÚNoder2   ÚedgesÚEdger:   )r@   r   rP   rQ   r   Úgraph_defaultsr   rB   ÚnodedataÚkrE   Ústr_nodedatarA   rD   rS   ÚedgedataÚstr_edgedatar&   s                     r   r	   r	   °   sÃ  € ó" ð 	‡}�}„Ø‰
àˆ
Ü×#Ñ# AÓ&¨!Ñ+ÒE°A·O±OÓ4EÐ0E€Fà�6‰6€DØ—W‘W—[‘[ ¨"Ó-€NØˆr‚zØˆE�I‰IÐQ Z¸ÑQÀ.ÑQ‰àˆE�I‰IØ�ˆv�QˆKð
Ø$.°vñ
ØAOñ
ˆðØˆ×ÑÑ.˜aŸg™g f™oÒ.ðØˆ×ÑÑ.˜aŸg™g f™oÒ.ð —w‘w D�wÓ)ò ‰ˆˆ8Ø3;·>±>Ó3C×D©4¨1¨aœ˜A›¤ A£™ÐDˆÑDÜ�‹FˆØˆE�J‰J�qÑ)˜LÑ)ˆØ	�
‰
�1�ð	ð 	‡�ÔØ#$§7¡7°¸4 7Ó#@ò 	ÑˆAˆq�#�xØ7?·~±~Ó7G×V©t¨q°!È1ÐPUË:œC ›F¤C¨£F™NÐVˆLÑVÜ�q“6œ3˜q›6ˆqˆAØ�5—:‘:˜a ÑA¬¨C«ÐA°LÑAˆDØ�J‰J�tÕð		ð €Hð  Ÿg™g¨4˜gÓ0ò 	‰NˆAˆq�(Ø7?·~±~Ó7G×H©t¨q°!œC ›F¤C¨£F™NÐHˆLÑHÜ�q“6œ3˜q›6ˆqˆAØ�5—:‘:˜a Ñ3 lÑ3ˆDØ�J‰J�tÕð		ð
 €Høô5 ò Úðûô ò Úðüó Eùó Wùó Is<   Â#J ÃJ- ÄJ=ÆKÆ,KÈ<K	Ê	J*Ê)J*Ê-	J:Ê9J:c                 ó   — t        | ||¬«      S )a=  Create node positions using Pydot and Graphviz.

    Returns a dictionary of positions keyed by node.

    Parameters
    ----------
    G : NetworkX Graph
        The graph for which the layout is computed.
    prog : string (default: 'neato')
        The name of the GraphViz program to use for layout.
        Options depend on GraphViz version but may include:
        'dot', 'twopi', 'fdp', 'sfdp', 'circo'
    root : Node from G or None (default: None)
        The node of G from which to start some layout algorithms.

    Returns
    -------
      Dictionary of (x, y) positions keyed by node.

    Examples
    --------
    >>> G = nx.complete_graph(4)
    >>> pos = nx.nx_pydot.graphviz_layout(G)
    >>> pos = nx.nx_pydot.graphviz_layout(G, prog="dot")

    Notes
    -----
    This is a wrapper for pydot_layout.
    ©r   ÚprogÚroot)r   rh   s      r   r   r   ñ   s   € ô< ˜! $¨TÔ2Ð2r   c                 óÊ  — ddl }t        | «      }|�|j                  dt        |«      «       |j	                  |¬«      }t        |t        «       ¬«      }|dk(  rJt        d|› d�«       t        «        t        d	«       t        d
«       t        d«       t        d|› d�«       y|j                  |«      }t        |«      dk(  sJ ‚|d   }i }	| j                  «       D ]…  }
t        |
«      }|j                  |j                  |«      «      }t        |t        «      r|d   }|j                  «       dd }|€ŒY|j                  d«      \  }}t!        |«      t!        |«      f|	|
<   Œ‡ |	S )aô  Create node positions using :mod:`pydot` and Graphviz.

    Parameters
    ----------
    G : Graph
        NetworkX graph to be laid out.
    prog : string  (default: 'neato')
        Name of the GraphViz command to use for layout.
        Options depend on GraphViz version but may include:
        'dot', 'twopi', 'fdp', 'sfdp', 'circo'
    root : Node from G or None (default: None)
        The node of G from which to start some layout algorithms.

    Returns
    -------
    dict
        Dictionary of positions keyed by node.

    Examples
    --------
    >>> G = nx.complete_graph(4)
    >>> pos = nx.nx_pydot.pydot_layout(G)
    >>> pos = nx.nx_pydot.pydot_layout(G, prog="dot")

    Notes
    -----
    If you use complex node objects, they may have the same string
    representation and GraphViz could treat them as the same node.
    The layout may assign both nodes a single location. See Issue #1568
    If this occurs in your case, consider relabeling the nodes just
    for the layout computation using something similar to::

        H = nx.convert_node_labels_to_integers(G, label_attribute="node_label")
        H_layout = nx.nx_pydot.pydot_layout(H, prog="dot")
        G_layout = {H.nodes[n]["node_label"]: p for n, p in H_layout.items()}

    r   Nrj   )ri   )Úencodingr$   zGraphviz layout with z failedzTo debug what happened try:zP = nx.nx_pydot.to_pydot(G)zP.write_dot("file.dot")zAnd then run z on file.dotr   éÿÿÿÿú,)r   r	   Úsetr8   Ú
create_dotr   Úprintr   Úlenr'   Úget_nodeÚquote_id_if_necessaryr7   ÚlistÚget_posÚsplitÚfloat)r   ri   rj   r   r   ÚD_bytesÚDÚQ_listÚQÚnode_posrB   Ústr_nr%   ÚposÚxxÚyys                   r   r   r     s]  € óL ä�‹€AØÐØ	�‰ˆf”c˜$“iÔ ð �l‰l ˆlÓ%€Gô 	ˆGÔ2Ó4Ô5€AàˆB‚wÜÐ% d V¨7Ð3Ô4ÜŒÜÐ+Ô,ÜÐ+Ô,ÜÐ'Ô(Ü�˜d˜V <Ð0Ô1Øð ×&Ñ& qÓ)€FÜˆv‹;˜!ÒÐÐð 	ˆq‰	€Aà€HØ�W‰W‹Yò 	1ˆÜ�A“ˆØ�z‰z˜%×5Ñ5°eÓ<Ó=ˆä�dœDÔ!Ø˜‘7ˆDØ�l‰l‹n˜Q˜rÐ"ˆØ‰?Ø—Y‘Y˜s“^‰FˆB�Ü  ›9¤e¨B£iÐ0ˆH�QŠKð	1ð €Or   )ÚneatoN)Ú__doc__Úlocaler   Únetworkxr*   Únetworkx.utilsr   Ú__all__r   Ú_dispatchabler   r
   r	   r   r   rT   r   r   ú<module>r‰      s¦   ðñõ, (ã Ý $ò€ñ ˆ1�3Ôñó ðñ ˆ1�3ÔØ€×ÑÐ'°ÀDÔIñ!ó Jó ð!ðB €×Ñ˜¨TÔ2ñXó 3ðXòv>óB3ôBNr   