
    c                       U d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZmZ ddlmZ  G d	 d
e          Z ed          Zded<   ej        dej        dej        diZded<   ej        dddej        ddddej        dddddej        dddddej         dddiZ!ded<    G d  d!e          Z"dS )"zNClass to generate files in dot format and image formats supported by Graphviz.    )annotationsN)Enum)Path)nodes)EdgeTypeLayoutNodePropertiesNodeTypePrinter)get_annotation_labelc                      e Zd ZdZdS )
HTMLLabelsz<br ALIGN="LEFT"/>N)__name__
__module____qualname__LINEBREAK_LEFT     <lib/python3.11/site-packages/pylint/pyreverse/dot_printer.pyr   r      s        )NNNr   r   )utf-8z
iso-8859-1latin1zfrozenset[str]ALLOWED_CHARSETSboxrecordzdict[NodeType, str]SHAPESnoneempty)	arrowtail	arrowheadnodedashed)r   r   stylegreendiamondsolid)	fontcolorr   r   r"   odiamondopenzdict[EdgeType, dict[str, str]]ARROWSc                  b     e Zd ZdZ	 	 dd fd	Zd dZ	 d!d"dZd#dZ	 d!d$dZd%dZ	d dZ
 xZS )&
DotPrinterblackNtitlestrlayoutLayout | Noneuse_automatic_namespacebool | Nonec                x    |pt           j        }d| _        t                                          |||           d S )Nr   )r   BOTTOM_TO_TOPcharsetsuper__init__)selfr-   r/   r1   	__class__s       r   r7   zDotPrinter.__init__6   s<     /6/(?@@@@@r   returnNonec                F   |                      d| j         d           | j        r"|                      d| j        j                    | j        rR| j                                        t          v sJ d| j                     |                      d| j         d           dS dS )zEmit the header lines.z	digraph "z" {zrankdir=zunsupported charset z	charset=""N)emitr-   r/   valuer5   lowerr   r8   s    r   _open_graphzDotPrinter._open_graph@   s    		.dj...///; 	6II4!244555< 	3""$$(885 54dl445 5 5 II1$,11122222		3 	3r   nametype_r
   
propertiesNodeProperties | Nonec                @   |t          |          }t          |         }|j        |j        n| j        }|| j        k    rdnd}|                     |          }|rd| dnd}|j        rd|j         d	nd}	|                     d	| d
| d	|	 | d| d| d           dS )zVCreate a new node.

        Nodes can be classes, packages, participants etc.
        N)labelfilledr%   z	, label=<> z, fontcolor="r=   z
" [color="z	, shape="z
", style="z"];)r	   r   colorDEFAULT_COLOR_build_label_for_noder&   r>   )
r8   rC   rD   rE   shaperL   r"   rH   
label_partfontcolor_parts
             r   	emit_nodezDotPrinter.emit_nodeK   s      	4'd333Ju$.$4X
  dFX!T%77DW**:66-2:)))))
7A7KS3J03333QS 	 			hhhhhh
hhUhh^chhh	
 	
 	
 	
 	
r   r	   c                0   |j         sdS |j         }|j        	|j        |S |j        pg }t          j        j                             d |D                       }d| d| t          j        j         d}|j        pg }|D ]}|                     |          }|                                rd|j	         dn|j	         }|| dd                    |           d	z  }|j
        r|d
t          |j
                  z   z  }|t          j        j         z  }|dz  }|S )NrK   c              3  B   K   | ]}|                     d d          V  dS )|z\|N)replace).0attrs     r   	<genexpr>z3DotPrinter._build_label_for_node.<locals>.<genexpr>n   sI       B
 B
)-DLLe$$B
 B
 B
 B
 B
 B
r   {rU   z<I>z</I>(, )z: })rH   attrsmethodsr   r   r?   join_get_method_argumentsis_abstractrC   returnsr   )	r8   rE   rH   r_   attrs_stringr`   funcargsmethod_names	            r   rN   z DotPrinter._build_label_for_nodec   sx    	2% 	
(: 	L &+1r%4:<AA B
 B
16B
 B
 B
 
 
 OeNNlNJ,E,KNNN ,6+=+C 	; 	;D--d33D)-)9)9););O%di%%%%DI  99tyy9999E| C 4T\ B BBB28::EEr   	from_nodeto_noder   rH   
str | Nonec                   t           |         }d |                                D             }|r|                    d| d           |                     d| d| dd                    t          |                     d           dS )	zACreate an edge from one node to another to display relationships.c                $    g | ]\  }}| d | dS )z="r=   r   )rW   propr?   s      r   
<listcomp>z(DotPrinter.emit_edge.<locals>.<listcomp>   s-    KKKuD$$E$$$KKKr   zlabel="r=   z" -> "z" [r\   z];N)r)   itemsappendr>   ra   sorted)r8   ri   rj   rD   rH   
arrowstyler_   s          r   	emit_edgezDotPrinter.emit_edge   s     E]
KK
8H8H8J8JKKK 	-LL+5+++,,,		OiOOwOO499VE]]3K3KOOOPPPPPr   
outputfilec                   |                                   d}| j        }|[d}t          j        d|          \  }}t          j        d|          \  }}t	          j        |           t	          j        |           nft          |          j                            d          }|s
d}|dz   |z   }||vr-t          j        d|          \  }}t	          j        |           n|}t          |dd          5 }|
                    | j                   d d d            n# 1 swxY w Y   ||vr2t          j        d	d
||d|gd           t	          j        |           d S d S )N)dotgvpngz.gvz.png.wutf8)encodingrw   z-Tz-oT)check)_close_graphr-   tempfilemkstemposcloser   suffixlstripr(   
writelineslines
subprocessrununlink)	r8   ru   graphviz_extensionsrC   targetpdotdot_sourcepathppngoutfiles	            r   generatezDotPrinter.generate   s   +z 	,F#+#3E4#@#@ D.'/==D*HTNNNHTNNNN*%%,33C88F 7'#-6
00 ,'/'7t'D'D$n!+.#777 	+7tz***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+,, 	&NfndJGt    In%%%%%		& 	&s   3DD!Dc                0    |                      d           dS )z2Emit the lines needed to properly close the graph.z}
N)r>   rA   s    r   r   zDotPrinter._close_graph   s    		%r   )NN)r-   r.   r/   r0   r1   r2   )r:   r;   )N)rC   r.   rD   r
   rE   rF   r:   r;   )rE   r	   r:   r.   )
ri   r.   rj   r.   rD   r   rH   rk   r:   r;   )ru   r.   r:   r;   )r   r   r   rM   r7   rB   rR   rN   rt   r   r   __classcell__)r9   s   @r   r+   r+   3   s        M
 !%/3	A A A A A A A	3 	3 	3 	3 -1	
 
 
 
 
0   F !Q Q Q Q Q& & & &8       r   r+   )#__doc__
__future__r   r   r   r   enumr   pathlibr   astroidr   pylint.pyreverse.printerr   r   r	   r
   r   pylint.pyreverse.utilsr   r   	frozensetr   __annotations__PACKAGE	INTERFACECLASSr   INHERITS
IMPLEMENTSASSOCIATIONAGGREGATIONUSESr)   r+   r   r   r   <module>r      s  
 U T T " " " " " " 				                        X X X X X X X X X X X X X X 7 7 7 7 7 7* * * * * * * * $-9-N#O#O  O O O OeNH     V'BBvGhWW	  	  Mf==*    &z z z z z z z z z zr   