o
    >hp                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	Z	ddl
mZmZmZmZ ddlmZ ddlmZ dd	lmZmZmZ d6ddZd6ddZd7ddZefd8ddZd9d d!Zeeefd:d*d+Zejd  ejdd ejee fd;d4d5Z!dS )<    )annotationsNwraps)CallableIterator   )	AutomatonInputOutputState)findMachines)MethodicalMachine)TypeMachineInputProtocolCoresstrreturnc                 C  s   d | ddS )Nz"{}""z\")formatreplacer    r   r/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/automat/_visualize.py_gvquote   s   r   c                 C  s
   d | S )Nz<{}>)r   r   r   r   r   _gvhtml   s   
r   namechildrenattrsc                 O  s6   d dd t| D }d |}dj| ||dS )z?
    Construct a string from the HTML element description.
     c                 s  s(    | ]\}}d  |tt|V  qdS )z{}={}N)r   r   r   ).0keyvaluer   r   r   	<genexpr>   s
    
zelementMaker.<locals>.<genexpr> z#<{name} {attrs}>{children}</{name}>)r   r   r   )joinsorteditemsr   )r   r   r   formattedAttrsformattedChildrenr   r   r   elementMaker   s   


r*   
inputLabeloutputLabels	list[str]port_ECallable[..., str]c                   s   i }|rt t||d<  d d| ddfd|d|}dd	i fd
d|D } d|g}|r>| dg|R    dg|R  S )z>
    Construct an HTML table to label a state transition.
    colspantdfontzmenlo-italic)facepurple)colorr.   z
point-size9c                   s(   g | ]} d  d|fi ddqS )r2   r3   pink)r6   r   )r    outputLabelr/   	pointSizer   r   
<listcomp><   s    ztableMaker.<locals>.<listcomp>trtable)r   lenappend)r+   r,   r.   r/   r1   inputLabelCelloutputLabelCellsrowsr   r:   r   
tableMaker&   s(   	rD   xCallable[[State], str]c                   s   t  d fdd}|S )Ntr   r   r   c                   s    |  dd ddS )N<z&lt;>z&gt;)r   )rG   rE   r   r   implJ   s   zescapify.<locals>.impl)rG   r   r   r   r   )rE   rK   r   rJ   r   escapifyI   s   rL   	automatonAutomaton[State, Input, Output]inputAsStringCallable[[Input], str]outputAsStringCallable[[Output], str]stateAsStringgraphviz.Digraphc                   s  t |}t   t |}tjdddddiddid}|  D ]}|| ju r+d}d}nd	}d}|j|||d
|dd qt|  D ]H\}}	|	\}
}}}d|}||}d}t	| fdd|D |d}|j|t
|ddd |j||
d||dd |d|||| qB|S )zA
    Produce a L{graphviz.Digraph} object from an automaton.
    true100)packdpifontnameMenlo)
graph_attr	node_attr	edge_attrboldz
Menlo-Boldr$   ellipseblue)fontameshapestyler6   zt{}	tableportc                   s   g | ]} |qS r   r   )r    outputSymbolrQ   r   r   r<   {   s    zmakeDigraph.<locals>.<listcomp>)r.   z0.2none)labelmarginrb   z{}:{}:w)	arrowheadz{}:{}:e)rL   graphvizDigraphstatesinitialStatenode	enumerateallTransitionsr   rD   r   edge)rM   rO   rQ   rS   digraphstate
stateShapefontNameneachTransitioninStateinputSymboloutStateoutputSymbolsthisTransitionr+   r.   r>   r   rf   r   makeDigraphQ   sN   



r~   	_progname_argv_syspath_findMachines[Callable[[str], Iterator[tuple[str, MethodicalMachine | TypeMachine[InputProtocol, Core]]]]_printCallable[..., None]Nonec                 C  sr  d}d}|d r| dd tj| ||d}|jddd |jd	d
dddd |jddddd |jddddd |jdddtjdd |jdddddd ||}|jo_|j p_|j|jk}	|j	rgdd  }||j
D ]J\}
}||
d! | }|	r|jd"|
|jd# ||
d$|j |jr|j p|	}|j|_|jd"|
|j|j|d% |rd&}nd'}||
||j qld(S ))z/
    Entry point for command line utility.
    zB
    Visualize automat.MethodicalMachines as graphviz graphs.
    zz
    You must have the graphviz tool suite installed.  Please visit
    http://www.graphviz.org for more information.
    r   r$   )progdescriptionepilogfqpnz@A Fully Qualified Path name representing where to find machines.)helpz--quietz-qzsuppress outputF
store_true)r   defaultactionz--dot-directoryz-dzWhere to write out .dot files.z.automat_visualize)r   r   z--image-directoryz-izWhere to write out image files.z--image-typez-tzThe image format.png)r   choicesr   z--viewz-vz.View rendered graphs with default image viewerc                  W  s   d S )Nr   )argsr   r   r   r      s   ztool.<locals>._printz...discoveredz{}.dot)filename	directoryz...wrote dot into)r   r   viewcleanupz...wrote image intoz...wrote image and dot intoN)insertargparseArgumentParseradd_argumentrk   FORMATS
parse_argsdot_directoryimage_directoryquietr   	asDigraphsaver   
image_typerenderr   )r   r   r   r   r   DESCRIPTIONEPILOGargumentParserr   explicitlySaveDotr   machiners   	deleteDotmsgr   r   r   tool   s   


r   )r   r   r   r   )r   r   r   r   r   r   r   r   )
r+   r   r,   r-   r.   r   r/   r0   r   r   )rE   rF   r   rF   )
rM   rN   rO   rP   rQ   rR   rS   rF   r   rT   )r   r   r   r-   r   r-   r   r   r   r   r   r   )"
__future__r   r   sys	functoolsr   typingr   r   rk   _corer   r	   r
   r   	_discoverr   _methodicalr   _typedr   r   r   r   r   r*   rD   rL   reprr~   argvpathprintr   r   r   r   r   <module>   s4    



#
;