
    ci54                     @   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
Z	ded	efdZ
ded	efdZdededed	efdZdededed	efdZ G d d      Z G d d      Zded	efdZded	efdZdeded	efdZ G d dej&                  ej(                        Zy)z"Create DOT code with method-calls.    N   )_tools)base)quoting)GraphSyntaxDigraphSyntaxDotlinereturnc                     d|  dS )zReturn comment header line.z// 
 )r
   s    3/tmp/pip-target-z3e9_cxr/lib/python/graphviz/dot.pycommentr      s    b>    namec                     d|  dS )zReturn DOT graph head line.zgraph {
r   r   s    r   
graph_headr      s    D6r   c                     d|  dS )zReturn DOT digraph head line.zdigraph r   r   r   s    r   digraph_headr      s    dV4  r   tailheadattrc                     d|  d| | dS )z%Return DOT graph edge statement line.	z -- r   r   r   r   r   s      r   
graph_edger          vT$vR((r   c                     d|  d| | dS )z'Return DOT digraph edge statement line.r   z -> r   r   r   s      r   digraph_edger"   !   r    r   c                   0    e Zd ZdZ ee      Z ee      Zy)r   zDOT graph head and edge syntax.N)	__name__
__module____qualname____doc__staticmethodr   _headr   _edger   r   r   r   r   &   s    )$E$Er   r   c                   0    e Zd ZdZ ee      Z ee      Zy)r   z!DOT digraph head and edge syntax.N)	r$   r%   r&   r'   r(   r   r)   r"   r*   r   r   r   r   r   .   s    +&E&Er   r   c                     d|  dS )zReturn DOT subgraph head line.z	subgraph r   r   r   s    r   subgraphr-   6   s    tfD!!r   c                     |  dS )z$Return plain DOT subgraph head line.r   r   r   s    r   subgraph_plainr/   ;   s    V4=r   leftrightc                     d|  | dS )zReturn DOT node statement line.r   r   r   )r0   r1   s     r   noder3   @   s    veWBr   c            
           e Zd ZU dZeed<    ee      Zede	de	fd       Z
ede	de	fd       ZdZ ee      Z ee      Z ee      xZZede	de	fd	       Zed
e	de	de	de	fd       Zed
e	de	de	fd       Zdddddddddej2                  e	   dej2                  e	   deddf fdZ fdZ ej:                  dd      d*deddfd       Z ej:                  dd      d*dedej>                  e	   fd       Z  ej:                  dde!      	 	 d+de	dej2                  e	   ddfd        Z ej:                  d!de!      	 	 d+d"e	d#e	dej2                  e	   ddfd$       Z"d,d%Z# ej:                  d&de!      	 	 d+d'ej2                  e	   ddfd(       Z$ ej:                  d&d      	 	 	 	 	 d-dej2                  e	   dej2                  e	   fd)       Z xZ%S ).r	   zAssemble DOT source code.directedr   r   c                     t        d      )zReturn DOT head line.*must be implemented by concrete subclassesNotImplementedErrorr   s    r   r)   z	Dot._headL        ""NOOr   c                 *    d| j                  |       S )zReturn DOT strict head line.zstrict )r)   )clsr   s     r   _head_strictzDot._head_strictQ   s     4)**r   z}
r0   c                 &    | j                  |d      S )N )_attr)r<   r0   s     r   _attr_plainzDot._attr_plain^   s    yyr""r   r   r   r   c                     t        d      )zReturn DOT edge statement line.r7   r8   r   s      r   r*   z	Dot._edgeb   r:   r   c                *    | j                  ||d      S )z%Return plain DOT edge statement line.r?   r   )r*   )r<   r   r   s      r   _edge_plainzDot._edge_plaing   s     yydBy77r   NFr   r   
graph_attr	node_attr	edge_attrbodystrictr   rJ   c                    t        	|   di | || _        	 || _        	 |t	        |      ni | _        	 |t	        |      ni | _        	 |t	        |      ni | _        	 |t        |      ng | _	        	 || _
        y )Nr   )super__init__r   r   dictrF   rG   rH   listrI   rJ   )
selfr   r   rF   rG   rH   rI   rJ   kwargs	__class__s
            r   rM   zDot.__init__l   s    
 	"6"	T@.8.D$z*"R,5,AirR,5,AirR"&"2DJ	S7r   c           
         t         |   | j                  | j                  t	        | j
                        t	        | j                        t	        | j                        t        | j                        | j                        S )z3Return the kwargs to create a copy of the instance.rE   )rL   _copy_kwargsr   r   rN   rF   rG   rH   rO   rI   rJ   )rP   rQ   rR   s     r   rT   zDot._copy_kwargs   s]    w#,0LL/3DOO/D.24>>.B.24>>.B)-dii+/;; $ 8 	8r   r   rP   )supported_number
ignore_arg
keep_attrsc                     |s8| j                   | j                  | j                  fD ]  }|j                           | j                  j                          y)zReset content to an empty body, clear graph/node/egde_attr mappings.

        Args:
            keep_attrs (bool): preserve graph/node/egde_attr mappings
        N)rF   rG   rH   clearrI   )rP   rW   as      r   rY   z	Dot.clear   s@     oot~~t~~F 			r   r-   c              #   N  K   | j                   r| j                  | j                          |r<| j                  rt        d      | j                  r| j
                  n| j                  }n$| j                  r| j                  n| j                  } || j                  r| j                  | j                        dz   nd       dD ]9  }t        | | d      }|s| j                  || j                  d|             ; | j                  E d{    | j                   y7 w)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 r?   graphr3   edger@   N)rQ   )r   _commentrJ   
ValueErrorr   	_subgraph_subgraph_plainr=   r)   _quotegetattrr@   
_attr_listrI   _tail)rP   r-   r   kwattrss        r   __iter__zDot.__iter__   s      <<----{{ !=>>%)YY4>>D4H4HD(,4$$D4994;;tyy)C/"EE+ 	JBDRD,/EjjT__T%_%HII	J
 99jj 	s   CD%6D%D#D%   )rU   rV   categorylabelc                     | j                  |      }| j                  |||      }| j                  ||      }| j                  j	                  |       y)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.
        rQ   
attributesN)rd   rf   _noderI   append)rP   r   rm   _attributesri   	attr_listr
   s          r   r3   zDot.node   sH    $ {{4 OOE%KOP	zz$	*		r      	tail_name	head_namec                     | j                  |      }| j                  |      }| j                  |||      }| j                  |||      }| j                  j	                  |       y)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.
        ro   r   N)_quote_edgerf   r*   rI   rr   )rP   rv   rw   rm   rs   ri   rt   r
   s           r   r_   zDot.edge   s^    6 $$Y/	$$Y/	OOE%KOP	zzyyyzI		r   c                     | j                   }| j                  }| xj                  |D cg c]  \  }} | ||       ||             c}}z  c_        yc c}}w )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>`.
        )r   r   N)rD   ry   rI   )rP   tail_head_iterr_   quoteths         r   edgesz	Dot.edges   sV       		"02!Q auQx8 2 	2	 2s    A
r   rh   c                 $   | |j                         dvrt        d|      |s|rj|&| j                  d||      }| j                  |      }n&| j	                  d||      }| j                  ||      }| j                  j                  |       yy)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>`.
        Nr]   z1attr statement must target graph, node, or edge: ro   )lowerra   _a_listrA   rf   r@   rI   rr   )rP   rh   rs   ri   a_listr
   rt   s          r   r   zDot.attr  s     >bhhj0II !!#( ) )Kzd5[Q''/ OOD;OW	zz"i0IIT"  r   c           	         |m| j                         }|j                  dd       |j                  ||||||d        | j                  di |t        j
                  fd       }	 |	|       S ||||||g}
t        d |
D              st        d      |j                  | j                  k7  rt        | d|      | xj                  |j                  d	
      D cg c]  }d| 	 c}z  c_	        yc c}w )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filenamerE   c              3   8   K    | j                         yw)z*Return subgraph and add to parent on exit.Nr-   )parentr-   s    r   subgraph_contextmanagerz-Dot.subgraph.<locals>.subgraph_contextmanagerK  s      )s   )r   c              3   $   K   | ]  }|d u  
 y w)Nr   ).0rZ   s     r   	<genexpr>zDot.subgraph.<locals>.<genexpr>T  s     +19+s   z)graph must be sole argument of subgraph()z( cannot add subgraph of different kind: Tr   r   r   )rT   popupdaterR   
contextlibcontextmanagerallra   r5   rI   rj   )rP   r^   r   r   rF   rG   rH   rI   rQ   r   argsr
   r-   s               @r   r-   zDot.subgraph  s   N =&&(FJJz4(MMtW%/9PY#D  2 &t~~//H&&* '*
 +$77gz9iF+d++HII>>T]]*x (!!&	+ , , 			enndn.KLd4&kLL	Ls   C6)F)NN)r   N)NNNNNNN)&r$   r%   r&   r'   bool__annotations__r(   r   r`   strr)   classmethodr=   rg   r-   rb   r/   rc   r3   rq   r@   rA   r*   rD   typingOptionalrM   rT   r   deprecate_positional_argsrY   Iteratorrj   DeprecationWarningr_   r   r   __classcell__)rR   s   @r   r	   r	   E   s   #NG$HPC PC P P + + + + EX&I">2O &&EE#s #s # # Ps P# PS PS P P 8# 8S 8S 8 8
 /315 DDt %	8s+8 //#.8 	8 59	888 &V%%qVL	 	 	 M	 &V%%qVL &//#2F  M2 &V%%qV/AC ,0 OOC(+/C* &V%%qV/AC ,0c c OOC(+/C>2& &V%%qV/AC.2#vs+ #+/#C#. &V%%qVL!.215<@	>Ms+>M //#.>M M>Mr   r	   )r'   r   r   r?   r   r   r   __all__r   r   r   r   r   r"   r   r   r-   r/   r3   QuoteBaser	   r   r   r   <module>r      s   (     
1# # 
S S 
!s !s !
) )3 )c )c )
)# )S ) ) )
% %' '"3 "3 "
  
 s  3  3  
VM'-- VMr   