
    c                     .   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZmZmZ ddlZddlmZ ddlmZ e	rEddlmZmZ eej        geee         eeef         df         f         Zeee         ee         f         ZdZd-dZd.dZ ej        d          Z ej        d          Z ej        d          Zd/dZ d0dZ!d0dZ"dZ#dZ$dZ%de#e$z   e%z   e#e$e%z   dZ&e#e$e%ddZ' G d d          Z( G d  d!          Z)d1d$Z*d2d'Z+d3d)Z,d.d*Z-d4d,Z.dS )5z8Generic classes/functions for pyreverse core/extensions.    )annotationsN)TYPE_CHECKINGAnyCallableOptionalTupleUnion)nodes)InferenceResult)ClassDiagramPackageDiagramz.pyreversercreturn	list[str]c                 Z   g } t           j                            dd          }|rt           j                            |t
                    }	 t          |d          5 }|                                                                } ddd           n# 1 swxY w Y   n# t          $ r Y nw xY w| S )z,Read config file and return list of options.HOME utf-8)encodingN)
osenvirongetpathjoinRCFILEopenreadsplitOSError)optionshomercfilefile_handles       6lib/python3.11/site-packages/pylint/pyreverse/utils.pyget_default_optionsr$   !   s    G:>>&"%%D dF++	fw/// 5;%**,,22445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 	 	 	D	Ns6   B 'BB BB BB 
B('B(Nonec                     t                      } |                                  | D ]"}t          j                            d|           #dS )z#Insert default options to sys.argv.   N)r$   reversesysargvinsert)r   args     r#   insert_default_optionsr-   /   sO    !##GOO    3       z^__([^\W_]_*)+__$z^__(_*[^\W_])+_?$z^_\w*$namestrc                    t                               |           rd}n<t                              |           rd}nt                              |           rd}nd}|S )zIReturn the visibility from a name: public, protected, private or special.specialprivate	protectedpublic)SPECIALmatchPRIVATE	PROTECTED)r/   
visibilitys     r#   get_visibilityr;   =   s`    }}T 

	t		 

			  

 
r.   nodenodes.ClassDefboolc                    | j         dk    S )N	interfacetyper<   s    r#   is_interfacerD   K       9##r.   c                    | j         dk    S )N	exceptionrA   rC   s    r#   is_exceptionrH   P   rE   r.            )ALLPUB_ONLYr6   OTHER)r2   r4   r3   r5   c                  "    e Zd ZdZddZdd
ZdS )FilterMixInz7Filter nodes according to a mode and nodes' visibility.moder0   r   r%   c                    d}|                     d          D ]H}	 |t          |         z  }# t          $ r(}t          d| t          j                   Y d}~Ad}~ww xY w|| _        dS )zInit filter modes.r   +zUnknown filter mode )fileN)r   MODESKeyErrorprintr)   stderr_FilterMixIn__mode)selfrQ   rY   nummodexs        r#   __init__zFilterMixIn.__init__k   s    jjoo 	D 	DFD%-' D D D1R11
CCCCCCCCCDs   ,
AAAr<   nodes.NodeNG | strr>   c                j    t          t          |d|                    }| j        t          |         z   S )z*Return true if the node should be treated.r/   )r;   getattrrY   VIS_MOD)rZ   r<   r:   s      r#   	show_attrzFilterMixIn.show_attru   s0    #GD&$$?$?@@
;!4444r.   N)rQ   r0   r   r%   )r<   r^   r   r>   )__name__
__module____qualname____doc__r]   rb    r.   r#   rP   rP   h   sB        AA   5 5 5 5 5 5r.   rP   c                  *    e Zd ZdZddZddZdd
ZdS )LocalsVisitora  Visit a project by traversing the locals dictionary.

    * visit_<class name> on entering a node, where class name is the class of
    the node in lower case

    * leave_<class name> on leaving a node, where class name is the class of
    the node in lower case
    r   r%   c                :    i | _         t                      | _        d S )N)_cacheset_visited)rZ   s    r#   r]   zLocalsVisitor.__init__   s    AC+.55r.   r<   nodes.NodeNG_CallbackTupleTc           	     2   |j         }| j                            |          }|l|j                                        }t          | d| t          | dd                    }t          | d| t          | dd                    }||f| j        |<   n|\  }}||fS )z0Get callbacks from handler for the visited node.Nvisit_visit_defaultleave_leave_default)	__class__rk   r   rc   lowerr`   )rZ   r<   klassmethodskide_methodl_methods          r#   get_callbackszLocalsVisitor.get_callbacks   s    +//%(( 
	).&&((CnsnngdOT&J&J H nsnngdOT&J&J H #+H!5DK!(Hh!!r.   r   c                V   || j         v rdS | j                             |           |                     |          }|d          |d         |           t          |d          r,|                                D ]}|                     |           |d          |d         |          S dS )z.Launch the visit starting from the given node.Nr   localsr'   )rm   addr|   hasattrvaluesvisit)rZ   r<   rx   
local_nodes       r#   r   zLocalsVisitor.visit   s    4=  	4$$$T**1: 	GAJt4"" 	'"kkmm ' '


:&&&&1: 	$71:d###tr.   Nr   r%   )r<   rn   r   ro   )r<   rn   r   r   )rc   rd   re   rf   r]   r|   r   rg   r.   r#   ri   ri   {   sZ         1 1 1 1" " " ""     r.   ri   annnodes.Name | nodes.NodeNGc                    t          | t          j                  r| j        | j        S t          | t          j                  r|                                 S dS )Nr   )
isinstancer
   Namer/   NodeNG	as_string)r   s    r#   get_annotation_labelr      sM    #uz"" sx x#u|$$ }}2r.   #nodes.AssignAttr | nodes.AssignName#nodes.Name | nodes.Subscript | Nonec                Z   d}t          | j        t          j                  r| j        j        }nt          | t          j                  ri| j        j        }	 t          t          |j        |j	        j
                            } |j        | j        j        j                  }n# t          $ r Y nw xY w|S 	 |                                 ^}}n# t           j        $ r d}Y nw xY wt%          |          }|r.t'          |dd          |                    d          sd| dn|}|r||_        |S )z!Return the annotation for `node`.Nr   valuer   z	Optional[])r   parentr
   	AnnAssign
annotation
AssignAttrdictzipr~   argsr   r   r   r/   AttributeErrorinferastroidInferenceErrorr   r`   
startswith)r<   r   init_methodr   default_labels          r#   get_annotationr      sd    C$+u// 
k$	D%*	+	+ k(	s;#5{7G7STTUUK!+/$+"3"899CC 	 	 	D	 
jjll!!!    !%%E
 
 w11$$Z00!!!!! 	 	  Js%   AB" "
B/.B/5C C C set[InferenceResult]c                ~   t          |           }	 |rct          |t          j                  s%t          |t          j                  r|j        dk    r|hS t          |                                          S t          |                                           S # t          j	        $ r |r|hnt                      cY S w xY w)zReturn a set containing the node annotation if it exists
    otherwise return a set of the inferred types using the NodeNG.infer method.
    |)
r   r   r
   	SubscriptBinOpoprl   r   r   r   )r<   r   s     r#   
infer_noder      s    
 

C	' 	$#u// 3,,143 usyy{{###4::<<   ! ' ' '&uu&&&'s   AB  B 6 B "B<;B<c                 x    t          j        d          %t          d           t          j        d           dS dS )zCheck if the ``dot`` command is available on the machine.

    This is needed if image output is desired and ``dot`` is used to convert
    from *.dot or *.gv into the final output format.
    dotNz?'Graphviz' needs to be installed for your chosen output format.    )shutilwhichrW   r)   exitrg   r.   r#   check_graphviz_availabilityr      s@     |E OPPP r.   output_formatc                f   t          j        ddgddd          }t          j        d|j                                                  }|st          d	           d
S |                    d          }| |                                vr+t          d|  d|            t          j
        d           d
S d
S )zCheck if the ``dot`` command supports the requested output format.

    This is needed if image output is desired and ``dot`` is used to convert
    from *.gv into the final output format.
    r   z-T?TFr   )capture_outputcheckr   z$.*Use one of: (?P<formats>(\S*\s?)+))patternstringzUnable to determine Graphviz supported output formats. Pyreverse will continue, but subsequent error messages regarding the output format may come from Graphviz directly.NformatszFormat z, is not supported by Graphviz. It supports: r   )
subprocessrunrer7   rX   striprW   groupr   r)   r   )r   
dot_outputr7   supported_formatss       r#   !check_if_graphviz_supports_formatr      s     	t57  J H7 &&((  E  K	
 	
 	

 	I..-33555 dmddQbdd	
 	
 	
 		 r.   )r   r   r   )r/   r0   r   r0   )r<   r=   r   r>   )r   r   r   r0   )r<   r   r   r   )r<   r   r   r   )r   r0   r   r%   )/rf   
__future__r   r   r   r   r   r)   typingr   r   r   r   r   r	   r   r
   astroid.typingr   pylint.pyreverse.diagramsr   r   r   
_CallbackTro   r   r$   r-   compiler6   r8   r9   r;   rD   rH   _SPECIAL
_PROTECTED_PRIVATErU   ra   rP   ri   r   r   r   r   r   rg   r.   r#   <module>r      s  
 ? > " " " " " " 				 				      



 G G G G G G G G G G G G G G G G        * * * * * * HFFFFFFFF	eL!5)E#FLM	OJ HZ0(:2FFGO 
           "*)
*
*
"*)
*
*BJy!!	   $ $ $ $
$ $ $ $ 
:%0("		 	 	 5 5 5 5 5 5 5 5&- - - - - - - -`          F' ' ' '$        r.   