§
    bŠtj'  ã                   ó  — 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dS )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                 ór   — t          | ¦  «        }|                     |                     ¦   «         ¦  «         dS )z÷Write NetworkX graph G to Graphviz dot format on path.

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

    path : string or file
       Filename or file handle for data output.
       Filenames ending in .gz or .bz2 will be compressed.
    N)r	   ÚwriteÚ	to_string)ÚGÚpathÚPs      úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/drawing/nx_pydot.pyr   r   &   s.   € õ 	�‰Œ€AØ‡J‚Jˆq�{Š{‰}Œ}ÑÔÐØ
€Fó    ÚrÚpydot_read_dotT)ÚnameÚgraphsÚreturns_graphc                 ó†   — ddl }|                      ¦   «         }|                     |¦  «        }t          |d         ¦  «        S )a•  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 to read.
        Filenames ending in .gz or .bz2 will be decompressed.

    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   7   sC   € ð2 €L€L€Là�9Š9‰;Œ;€Dð ×&Ò& tÑ,Ô,€Fõ �f˜Q”iÑ Ô Ð r   )r   r   c                 óZ  — 	 |                       ¦   «         }n%# t          $ r |                       d¦  «        }Y nw xY w| }|                      ¦   «         dk    r*|rt          j        ¦   «         }n=t          j        ¦   «         }n)|rt          j        ¦   «         }nt          j        ¦   «         }|                      ¦   «          	                    d¦  «        }|dk    r||_
        |                      ¦   «         D ]N}|                     ¦   «          	                    d¦  «        }|dv rŒ. |j        |fi |                     ¦   «         ¤Ž ŒO|                      ¦   «         D �]>}|                     ¦   «         }|                     ¦   «         }	|                     ¦   «         }
g }g }t#          |t$          ¦  «        r)|                     | 	                    d¦  «        ¦  «         n3|d         D ]*}|                     | 	                    d¦  «        ¦  «         Œ+t#          |	t$          ¦  «        r)|                     |	 	                    d¦  «        ¦  «         n3|	d         D ]*}|                     | 	                    d¦  «        ¦  «         Œ+|D ]}|D ]} |j        ||fi |
¤Ž ŒŒ�Œ@|                      ¦   «         }|r
||j        d<   	 |                      ¦   «         d         |j        d<   n# t.          t          f$ r Y nw xY w	 |                      ¦   «         d         |j        d	<   n# t.          t          f$ r Y nw xY w|S )
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))

    NÚgraphú"Ú )Únoder"   ÚedgeÚnodesr   r%   r&   )Ú
get_strictÚ	TypeErrorÚ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Úget_edge_defaults)r   ÚstrictÚ
multiedgesÚNr   ÚpÚnÚeÚuÚvÚattrÚsÚdÚunodesÚvnodesÚsource_nodeÚdestination_nodeÚpattrs                     r   r
   r
   [   sj  € ð4$Ø—’‘”ˆˆøÝð $ð $ð $Ø—’˜dÑ#Ô#ˆˆˆð$øøøà�€Jà‡z‚z�|„|�wÒÐØð 	Ý”‘”ˆAˆAå”‘
”
ˆAˆAàð 	Ý”Ñ!Ô!ˆAˆAå”
‘”ˆAð �:Š:‰<Œ<×Ò˜cÑ"Ô"€DØˆr‚z€zØˆŒð �_Š_ÑÔð ,ð ,ˆØ�JŠJ‰LŒL×Ò˜sÑ#Ô#ˆØÐ)Ð)Ð)ØØˆŒ
�1Ð+Ð+˜×(Ò(Ñ*Ô*Ð+Ð+Ð+Ð+ð �_Š_ÑÔð Bñ BˆØ�LŠL‰NŒNˆØ×ÒÑÔˆØ×ÒÑ!Ô!ˆØˆØˆå�a�ÑÔð 	,Ø�HŠH�Q—W’W˜S‘\”\Ñ"Ô"Ð"Ð"à˜Gœ*ð ,ð ,�Ø—’˜Ÿš cÑ*Ô*Ñ+Ô+Ð+Ð+å�a�ÑÔð 	,Ø�HŠH�Q—W’W˜S‘\”\Ñ"Ô"Ð"Ð"à˜Gœ*ð ,ð ,�Ø—’˜Ÿš cÑ*Ô*Ñ+Ô+Ð+Ð+àð 	Bð 	BˆKØ$%ð Bð BÐ Ø�”
˜;Ð(8ÐAÐA¸DÐAÐAÐAÐAðBñ	Bð
 ×ÒÑÔ€EØð !Ø ˆŒ�ÑðØ×-Ò-Ñ/Ô/°Ô2ˆŒ�‰ˆøÝ�	Ð"ð ð ð ØˆðøøøðØ×-Ò-Ñ/Ô/°Ô2ˆŒ�‰ˆøÝ�	Ð"ð ð ð Øˆðøøøà€Hs0   ‚ —9¸9Ê6"K ËK-Ë,K-Ë1"L ÌL(Ì'L(c                 óö  — ddl }|                      ¦   «         rd}nd}t          j        | ¦  «        dk    o|                      ¦   «          }| j        }| j                             di ¦  «        }|dk    r |j        d||dœ|¤Ž}n |j        d|› d�f||dœ|¤Ž}	  |j	        di | j        d         ¤Ž n# t          $ r Y nw xY w	  |j        di | j        d	         ¤Ž n# t          $ r Y nw xY w|                      d
¬¦  «        D ]U\  }}d„ |                     ¦   «         D ¦   «         }	t          |¦  «        } |j        |fi |	¤Ž}
|                     |
¦  «         ŒV|                      ¦   «         r�|                      d
d
¬¦  «        D ]v\  }}}}d„ |                     ¦   «         D ¦   «         }t          |¦  «        t          |¦  «        }} |j        ||fdt          |¦  «        i|¤Ž}|                     |¦  «         Œwn}|                      d
¬¦  «        D ]f\  }}}d„ |                     ¦   «         D ¦   «         }t          |¦  «        t          |¦  «        }} |j        ||fi |¤Ž}|                     |¦  «         Œg|S )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_typer?   r#   r%   r&   T)r   c                 óN   — i | ]"\  }}t          |¦  «        t          |¦  «        “Œ#S © ©r9   ©Ú.0ÚkrF   s      r   ú
<dictcomp>zto_pydot.<locals>.<dictcomp>å   s*   € ÐDÐDÐD©4¨1¨a�˜A™œ¥ A¡¤ÐDÐDÐDr   )r   Úkeysc                 óZ   — i | ](\  }}|d k    ¯t          |¦  «        t          |¦  «        “Œ)S )ÚkeyrT   rU   s      r   rX   zto_pydot.<locals>.<dictcomp>ì   s0   € ÐVÐVÐV©t¨q°!È1ÐPUÊ:È:�C ™FœF¥C¨¡F¤FÈ:È:È:r   r[   c                 óN   — i | ]"\  }}t          |¦  «        t          |¦  «        “Œ#S rS   rT   rU   s      r   rX   zto_pydot.<locals>.<dictcomp>ó   s*   € ÐHÐHÐH©t¨q°!�C ™FœF¥C¨¡F¤FÐHÐHÐHr   )r$   rS   )r   Úis_directedr+   Únumber_of_selfloopsÚis_multigraphr   r"   ÚgetÚDotÚset_node_defaultsÚKeyErrorÚset_edge_defaultsr'   Úitemsr9   ÚNoder3   ÚedgesÚEdger;   )rA   r   rQ   r?   r   Úgraph_defaultsr   rC   ÚnodedataÚstr_nodedatarB   rE   rF   r[   ÚedgedataÚstr_edgedatar&   s                    r   r	   r	   ¹   s  € ð" €L€L€Lð 	‡}‚}�„ð Øˆ
ˆ
àˆ
ÝÔ# AÑ&Ô&¨!Ò+ÐE°A·O²OÑ4EÔ4EÐ0E€FàŒ6€DØ”W—[’[ ¨"Ñ-Ô-€NØˆr‚z€zØˆEŒIÐQ Z¸ÐQÐQÀ.ÐQÐQˆˆàˆEŒIØ�ˆKˆKˆKð
Ø$.°vð
ð 
ØAOð
ð 
ˆðØˆÔÐ.Ð.˜aœg fœoÐ.Ð.Ð.Ð.øÝð ð ð ØˆðøøøðØˆÔÐ.Ð.˜aœg fœoÐ.Ð.Ð.Ð.øÝð ð ð Øˆðøøøð —w’w D�wÑ)Ô)ð ð ‰ˆˆ8ØDÐD°8·>²>Ñ3CÔ3CÐDÑDÔDˆÝ�‰FŒFˆØˆEŒJ�qÐ)Ð)˜LÐ)Ð)ˆØ	�
Š
�1‰Œˆˆà‡‚ÑÔð Ø#$§7¢7°¸4 7Ñ#@Ô#@ð 	ð 	ÑˆAˆq�#�xØVÐV°x·~²~Ñ7GÔ7GÐVÑVÔVˆLÝ�q‘6”6�3˜q™6œ6ˆqˆAØ�5”:˜a ÐAÐA­¨C©¬ÐA°LÐAÐAˆDØ�JŠJ�tÑÔÐÐð		ð  Ÿgšg¨4˜gÑ0Ô0ð 	ð 	‰NˆAˆq�(ØHÐH°x·~²~Ñ7GÔ7GÐHÑHÔHˆLÝ�q‘6”6�3˜q™6œ6ˆqˆAØ�5”:˜a Ð3Ð3 lÐ3Ð3ˆDØ�JŠJ�tÑÔÐÐØ€Hs$   ÂB3 Â3
C Â?C ÃC Ã
C*Ã)C*Úneatoc                 ó&   — 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   rp   s      r   r   r   ú   s   € õ< ˜! $¨TÐ2Ñ2Ô2Ð2r   c                 óš  — ddl }t          | ¦  «        }|�#|                     dt          |¦  «        ¦  «         |                     |¬¦  «        }t          |t          ¦   «         ¬¦  «        }|dk    rct          d|› d�¦  «         t          ¦   «          t          d	¦  «         t          d
¦  «         t          d¦  «         t          d|› d�¦  «         dS |                     |¦  «        }t          |¦  «        dk    sJ ‚|d         }i }	|  	                    ¦   «         D ]­}
t          |
¦  «        }| 
                    |                     |¦  «        ¦  «        }t          |t          ¦  «        r|d         }|                     ¦   «         dd…         }|�9|                     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   Nrr   )rq   )Ú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	   Úsetr9   Ú
create_dotr   Úprintr   Úlenr'   Úget_nodeÚquote_id_if_necessaryr8   ÚlistÚget_posÚsplitÚfloat)r   rq   rr   r   r   ÚD_bytesÚDÚQ_listÚQÚnode_posrC   Ústr_nr%   ÚposÚxxÚyys                   r   r   r     sÇ  € ðL €L€L€Lå�‰Œ€AØÐØ	�Šˆf•c˜$‘i”iÑ Ô Ð ð �lŠl ˆlÑ%Ô%€Gõ 	ˆGÕ2Ñ4Ô4Ð5Ñ5Ô5€AàˆB‚w€wÝÐ3 dÐ3Ð3Ð3Ñ4Ô4Ð4Ý‰ŒˆÝÐ+Ñ,Ô,Ð,ÝÐ+Ñ,Ô,Ð,ÝÐ'Ñ(Ô(Ð(ÝÐ0˜dÐ0Ð0Ð0Ñ1Ô1Ð1Øˆð ×&Ò& qÑ)Ô)€FÝˆv‰;Œ;˜!ÒÐÐÐð 	ˆqŒ	€Aà€HØ�WŠW‰YŒYð 	1ð 	1ˆÝ�A‘”ˆØ�zŠz˜%×5Ò5°eÑ<Ô<Ñ=Ô=ˆå�d�DÑ!Ô!ð 	Ø˜”7ˆDØ�lŠl‰nŒn˜Q˜r˜TÔ"ˆØˆ?Ø—Y’Y˜s‘^”^‰FˆB�Ý  ™9œ9¥e¨B¡i¤iÐ0ˆH�Q‰KøØ€Or   )rn   N)Ú__doc__Úlocaler   Únetworkxr+   Únetworkx.utilsr   Ú__all__r   Ú_dispatchabler   r
   r	   r   r   rS   r   r   ú<module>r�      sE  ððð ð, (Ð 'Ð 'Ð 'Ð 'Ð 'à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $ðð ð €ð €ˆ1�3ÐÑÔðð ñ Ôðð  €ˆ1�3ÐÑÔØ€ÔÐ'°ÀDÐIÑIÔIð!ð !ñ JÔIñ Ôð!ðD €Ô˜¨TÐ2Ñ2Ô2ðZð Zñ 3Ô2ðZðz>ð >ð >ðB3ð 3ð 3ð 3ðBNð Nð Nð Nð Nð Nr   