o
    ooi54                     @   s  d Z ddlZddlZddlmZ ddlmZ ddlmZ g dZded	efd
dZ	ded	efddZ
ded	efddZdededed	efddZdededed	efddZG dd dZG dd dZded	efddZded	efddZd ed!ed	efd"d#ZG d$d% d%ejejZdS )&z"Create DOT code with method-calls.    N   )_tools)base)quoting)GraphSyntaxDigraphSyntaxDotlinereturnc                 C      d|  dS )zReturn comment header line.z// 
 )r	   r   r   @/home/ubuntu/.local/lib/python3.10/site-packages/graphviz/dot.pycomment      r   namec                 C   r   )zReturn DOT graph head line.zgraph {
r   r   r   r   r   
graph_head   r   r   c                 C   r   )zReturn DOT digraph head line.zdigraph r   r   r   r   r   r   digraph_head   r   r   tailheadattrc                 C      d|  d| | dS )z%Return DOT graph edge statement line.	z -- r   r   r   r   r   r   r   r   
graph_edge      r   c                 C   r   )z'Return DOT digraph edge statement line.r   z -> r   r   r   r   r   r   digraph_edge!   r   r   c                   @       e Zd ZdZeeZeeZdS )r   zDOT graph head and edge syntax.N)	__name__
__module____qualname____doc__staticmethodr   _headr   _edger   r   r   r   r   &       r   c                   @   r   )r   z!DOT digraph head and edge syntax.N)	r    r!   r"   r#   r$   r   r%   r   r&   r   r   r   r   r   .   r'   r   c                 C   r   )zReturn DOT subgraph head line.z	subgraph r   r   r   r   r   r   subgraph6   r   r(   c                 C   s
   |  dS )z$Return plain DOT subgraph head line.r   r   r   r   r   r   subgraph_plain;   s   
r)   leftrightc                 C   s   d|  | dS )zReturn DOT node statement line.r   r   r   )r*   r+   r   r   r   node@   s   r,   c                
       s*  e Zd ZU dZeed< eeZede	de	fddZ
ede	de	fddZd	ZeeZeeZee ZZed
e	de	fddZede	de	de	de	fddZede	de	de	fddZdddddddddeje	 deje	 deddf fddZ fddZejdddd8d eddfd!d"Zejdddd8d#edeje	 fd$d%Z ejd&de!d'		d9de	d(eje	 ddfd)d*Zejd+de!d'		d9d,e	d-e	d(eje	 ddfd.d/Z"d:d0d1Z#ejd2de!d'		d9d3eje	 ddfd4d5Z$ejd2dd					d;deje	 deje	 fd6d7Z  Z%S )<r   zAssemble DOT source code.directedr   r
   c                 C      t d)zReturn DOT head line.*must be implemented by concrete subclassesNotImplementedErrorr   r   r   r   r%   L      z	Dot._headc                 C   s   d|  | S )zReturn DOT strict head line.zstrict )r%   )clsr   r   r   r   _head_strictQ      zDot._head_strictz}
r*   c                 C   s   |  |dS )N )_attr)r3   r*   r   r   r   _attr_plain^   r   zDot._attr_plainr   r   r   c                 C   r.   )zReturn DOT edge statement line.r/   r0   r   r   r   r   r&   b   r2   z	Dot._edgec                C   s   | j ||ddS )z%Return plain DOT edge statement line.r6   r   )r&   )r3   r   r   r   r   r   _edge_plaing   r5   zDot._edge_plainNFr   r   
graph_attr	node_attr	edge_attrbodystrictr   r?   c          	         s   t  jdi | || _	 || _	 |d urt|ni | _	 |d ur%t|ni | _	 |d ur1t|ni | _	 |d ur=t|ng | _		 || _
d S )Nr   )super__init__r   r   dictr;   r<   r=   listr>   r?   )	selfr   r   r;   r<   r=   r>   r?   kwargs	__class__r   r   rA   l   s   zDot.__init__c              	      s8   t  j| j| jt| jt| jt| jt| j	| j
dS )z3Return the kwargs to create a copy of the instance.r:   )r@   _copy_kwargsr   r   rB   r;   r<   r=   rC   r>   r?   )rD   rE   rF   r   r   rH      s   
zDot._copy_kwargsr   rD   )supported_number
ignore_arg
keep_attrsc                 C   s0   |s| j | j| jfD ]}|  q
| j  dS )zReset content to an empty body, clear graph/node/egde_attr mappings.

        Args:
            keep_attrs (bool): preserve graph/node/egde_attr mappings
        N)r;   r<   r=   clearr>   )rD   rK   ar   r   r   rL      s   
z	Dot.clearr(   c                 c   s    | j r| | j V  |r| jrtd| jr| jn| j}n	| jr$| jn| j}|| jr3| 	| jd ndV  dD ]}t
| | d}|rQ| || jd|dV  q9| jE dH  | jV  dS )zYield the DOT source code line by line (as graph or subgraph).

        Yields: Line ending with a newline (``'\n'``).
        zsubgraphs cannot be strict r6   graphr,   edger7   N)rE   )r   _commentr?   
ValueErrorr   	_subgraph_subgraph_plainr4   r%   _quotegetattrr7   
_attr_listr>   _tail)rD   r(   r   kwattrsr   r   r   __iter__   s     zDot.__iter__   )rI   rJ   categorylabelc                 K   s6   |  |}| j|||d}| ||}| j| dS )a  Create a node.

        Args:
            name: Unique identifier for the node inside the source.
            label: Caption to be displayed (defaults to the node ``name``).
            attrs: Any additional node attributes (must be strings).

        Attention:
            When rendering ``label``, backslash-escapes
            and strings of the form ``<...>`` have a special meaning.
            See the sections :ref:`backslash-escapes` and
            :ref:`quoting-and-html-like-labels` in the user guide for details.
        rE   
attributesN)rV   rX   _noder>   append)rD   r   r_   _attributesr[   	attr_listr	   r   r   r   r,      s   
zDot.node   	tail_name	head_namec                 K   sD   |  |}|  |}| j|||d}| j|||d}| j| dS )a  Create an edge between two nodes.

        Args:
            tail_name: Start node identifier
                (format: ``node[:port[:compass]]``).
            head_name: End node identifier
                (format: ``node[:port[:compass]]``).
            label: Caption to be displayed near the edge.
            attrs: Any additional edge attributes (must be strings).

        Note:
            The ``tail_name`` and ``head_name`` strings are separated
            by (optional) colon(s) into ``node`` name, ``port`` name,
            and ``compass`` (e.g. ``sw``).
            See :ref:`details in the User Guide <node-ports-compass>`.

        Attention:
            When rendering ``label``, backslash-escapes
            and strings of the form ``<...>`` have a special meaning.
            See the sections :ref:`backslash-escapes` and
            :ref:`quoting-and-html-like-labels` in the user guide for details.
        r`   r   N)_quote_edgerX   r&   r>   rc   )rD   rg   rh   r_   rd   r[   re   r	   r   r   r   rQ      s
   

zDot.edgec                    s.   | j  | j|  j fdd|D 7  _dS )a  Create a bunch of edges.

        Args:
            tail_head_iter: Iterable of ``(tail_name, head_name)`` pairs
                (format:``node[:port[:compass]]``).


        Note:
            The ``tail_name`` and ``head_name`` strings are separated
            by (optional) colon(s) into ``node`` name, ``port`` name,
            and ``compass`` (e.g. ``sw``).
            See :ref:`details in the User Guide <node-ports-compass>`.
        c                    s$   g | ]\}} ||d qS ))r   r   r   ).0thrQ   quoter   r   
<listcomp>   s    zDot.edges.<locals>.<listcomp>N)r9   ri   r>   )rD   tail_head_iterr   rm   r   edges   s
   z	Dot.edgesr   rZ   c                 K   s~   |dur|  dvrtd||s|r=|du r'| jd||d}| |}n| jd||d}| ||}| j| dS dS )aB  Add a general or graph/node/edge attribute statement.

        Args:
            kw: Attributes target
                (``None`` or ``'graph'``, ``'node'``, ``'edge'``).
            attrs: Attributes to be set (must be strings, may be empty).

        See the :ref:`usage examples in the User Guide <attributes>`.
        NrO   z1attr statement must target graph, node, or edge: r`   )lowerrS   _a_listr8   rX   r7   r>   rc   )rD   rZ   rd   r[   a_listr	   re   r   r   r   r     s   zDot.attrc              	      s   |du r0|   }|dd |j||||||dd | jdi | tj fdd}	|	| dS ||||||g}
tdd |
D sEtd	|j| jkrTt| d
||  j	dd |j
ddD 7  _	dS )a  Add the current content of the given sole ``graph`` argument
            as subgraph or return a context manager
            returning a new graph instance
            created with the given (``name``, ``comment``, etc.) arguments
            whose content is added as subgraph
            when leaving the context manager's ``with``-block.

        Args:
            graph: An instance of the same kind
                (:class:`.Graph`, :class:`.Digraph`) as the current graph
                (sole argument in non-with-block use).
            name: Subgraph name (``with``-block use).
            comment: Subgraph comment (``with``-block use).
            graph_attr: Subgraph-level attribute-value mapping
                (``with``-block use).
            node_attr: Node-level attribute-value mapping
                (``with``-block use).
            edge_attr: Edge-level attribute-value mapping
                (``with``-block use).
            body: Verbatim lines to add to the subgraph ``body``
                (``with``-block use).

        See the :ref:`usage examples in the User Guide <subgraphs-clusters>`.

        When used as a context manager, the returned new graph instance
        uses ``strict=None`` and the parent graph's values
        for ``directory``, ``format``, ``engine``, and ``encoding`` by default.

        Note:
            If the ``name`` of the subgraph begins with
            ``'cluster'`` (all lowercase)
            the layout engine will treat it as a special cluster subgraph.
        Nfilenamer:   c                 3   s     V  |    dS )z*Return subgraph and add to parent on exit.Nr(   parentrv   r   r   subgraph_contextmanagerK  s   z-Dot.subgraph.<locals>.subgraph_contextmanagerrw   c                 s   s    | ]}|d u V  qd S )Nr   )rj   rM   r   r   r   	<genexpr>T  s    zDot.subgraph.<locals>.<genexpr>z)graph must be sole argument of subgraph()z( cannot add subgraph of different kind: c                 S   s   g | ]}d | qS )r   r   )rj   r	   r   r   r   ro   [  s    z Dot.subgraph.<locals>.<listcomp>Trv   r   )rH   popupdaterG   
contextlibcontextmanagerallrS   r-   r>   r\   )rD   rP   r   r   r;   r<   r=   r>   rE   ry   argsr   rv   r   r(     s&   '
$zDot.subgraph)F)NN)r
   N)NNNNNNN)&r    r!   r"   r#   bool__annotations__r$   r   rR   strr%   classmethodr4   rY   r(   rT   r)   rU   r,   rb   r7   r8   r&   r9   typingOptionalrA   rH   r   deprecate_positional_argsrL   Iteratorr\   DeprecationWarningrQ   rq   r   __classcell__r   r   rF   r   r   E   s   
 

r   )r#   r}   r   r6   r   r   r   __all__r   r   r   r   r   r   r   r   r(   r)   r,   QuoteBaser   r   r   r   r   <module>   s$    