o
    ooi                     @   sp  d Z ddlZddlZddlZddlZddlmZ ddlmZ g dZe	dej
Ze	dZh d	Zh d
Ze	dZej	dejdZeejdZejddejejeejefdedefddZdedefddZejdd		d$deje defddZejdd		d$deje defddZG dd dZdedefddZG d d! d!eZ dedefd"d#Z!dS )%KQuote strings to be valid DOT identifiers, assemble quoted attribute lists.    N   )_tools)
exceptions)quote
quote_edgea_list	attr_listescapenohtmlz<.*>$z8([a-zA-Z_][a-zA-Z0-9_]*|-?(\.[0-9]+|[0-9]+(\.[0-9]*)?))$>   edgenodegraphstrictdigraphsubgraph>
   _censwnenwseswz(?<!\\)(?:\\{2})*\\$a  
                                            (?P<escaped_backslashes>(?:\\{2})*)
                                            \\?  # treat \" same as "
                                            (?P<literal_quote>")
                                            )flagsz*\g<escaped_backslashes>\\\g<literal_quote>)supported_number
identifierreturnc                 C   s^   || rt | ts	 | S || r|  |v r-|| r%tjd| tjd d||  dS | S )a  Return DOT identifier from string, quote if needed.

    >>> quote('')  # doctest: +NO_EXE
    '""'

    >>> quote('spam')
    'spam'

    >>> quote('spam spam')
    '"spam spam"'

    >>> quote('-4.2')
    '-4.2'

    >>> quote('.42')
    '.42'

    >>> quote('<<b>spam</b>>')
    '<<b>spam</b>>'

    >>> quote(nohtml('<>'))
    '"<>"'

    >>> print(quote('"'))
    "\""

    >>> print(quote('\\"'))
    "\""

    >>> print(quote('\\\\"'))
    "\\\""

    >>> print(quote('\\\\\\"'))
    "\\\""
    z4expect syntax error scanning invalid quoted string: )category")
isinstanceNoHtmllowerwarningswarnr   DotSyntaxWarning)r   is_html_stringis_valid_iddot_keywords"endswith_odd_number_of_backslashesescape_unescaped_quotes r-   D/home/ubuntu/.local/lib/python3.10/site-packages/graphviz/quoting.pyr   (   s   *r   c                 C   sT   |  d\}}}t|g}|r%| d\}}}|t| |r%|| d|S )zReturn DOT edge statement node_id from string, quote if needed.

    >>> quote_edge('spam')  # doctest: +NO_EXE
    'spam'

    >>> quote_edge('spam spam:eggs eggs')
    '"spam spam":"eggs eggs"'

    >>> quote_edge('spam:eggs:s')
    'spam:eggs:s'
    :)	partitionr   appendjoin)r   r   r   restpartsportcompassr-   r-   r.   r   ]   s   


r   labelc                 C   sl   | durdt |  gng }|r|dd t|D 7 }|r1t|dr(t|}|dd |D 7 }d|S )zReturn assembled DOT a_list string.

    >>> a_list('spam', kwargs={'spam': None, 'ham': 'ham ham', 'eggs': ''})  # doctest: +NO_EXE
    'label=spam eggs="" ham="ham ham"'
    Nzlabel=c                 S   .   g | ]\}}|d urt | dt | qS N=r   .0kvr-   r-   r.   
<listcomp>}       za_list.<locals>.<listcomp>itemsc                 S   r8   r9   r;   r<   r-   r-   r.   r@      rA    )r   r   mapping_itemshasattrr2   )r7   kwargs
attributesresultr-   r-   r.   r   s   s   


r   c                 C   s"   t | ||d}|sdS d| dS )a  Return assembled DOT attribute list string.

    Sorts ``kwargs`` and ``attributes`` if they are plain dicts
    (to avoid unpredictable order from hash randomization in Python < 3.7).

    >>> attr_list()  # doctest: +NO_EXE
    ''

    >>> attr_list('spam spam', kwargs={'eggs': 'eggs', 'ham': 'ham ham'})
    ' [label="spam spam" eggs=eggs ham="ham ham"]'

    >>> attr_list(kwargs={'spam': None, 'eggs': ''})
    ' [eggs=""]'
    )rF   rG    z [])r   )r7   rF   rG   contentr-   r-   r.   r	      s   r	   c                   @   s0   e Zd ZdZeeZeeZee	Z
eeZdS )Quoter   N)__name__
__module____qualname____doc__staticmethodr   _quoter   _quote_edger   _a_listr	   
_attr_listr-   r-   r-   r.   rL      s    rL   r   c                 C   s   t | ddS )a  Return string disabling special meaning of backslashes and ``'<...>'``.

    Args:
        s: String in which backslashes and ``'<...>'``
            should be treated as literal.

    Returns:
        Escaped string subclass instance.

    Raises:
        TypeError: If ``s`` is not a ``str``.

    Example:
        >>> import graphviz  # doctest: +NO_EXE
        >>> print(graphviz.escape(r'\l'))
        \\l

    See also:
        Upstream documentation:
        https://www.graphviz.org/doc/info/attrs.html#k:escString
    \z\\)r   replacer   r-   r-   r.   r
      s   r
   c                   @   s   e Zd ZdZdZdS )r#   zCString subclass that does not treat ``'<...>'`` as DOT HTML string.r-   N)rM   rN   rO   rP   	__slots__r-   r-   r-   r.   r#      s    r#   c                 C   s   t | S )a&  Return string not treating ``'<...>'`` as DOT HTML string in quoting.

    Args:
        s: String in which leading ``'<'`` and trailing ``'>'``
            should be treated as literal.

    Returns:
        String subclass instance.

    Raises:
        TypeError: If ``s`` is not a ``str``.

    Example:
        >>> import graphviz  # doctest: +NO_EXE
        >>> g = graphviz.Graph()
        >>> g.node(graphviz.nohtml('<>-*-<>'))
        >>> print(g.source)  # doctest: +NORMALIZE_WHITESPACE
        graph {
            "<>-*-<>"
        }
    )r#   rX   r-   r-   r.   r      s   r   )NNN)"rP   	functoolsretypingr%   rI   r   r   __all__compileDOTALLHTML_STRINGIDKEYWORDSCOMPASSFINAL_ODD_BACKSLASHESVERBOSEQUOTE_WITH_OPTIONAL_BACKSLASHESpartialsubESCAPE_UNESCAPED_QUOTESdeprecate_positional_argsmatchsearchstrr   r   Optionalr   r	   rL   r
   r#   r   r-   r-   r-   r.   <module>   sZ    


4


