
    yIf                     &   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 d/d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(d0d#Z)d1d&Z*d2d(Z+d-d)Z,d3d+Z-dS )4z8Generic 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       J/var/www/piapp/venv/lib/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	exception)type)r<   s    r#   is_exceptionrB   K   s    9##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)selfrK   rS   nummodexs        r#   __init__zFilterMixIn.__init__f   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;   getattrrS   VIS_MOD)rT   r<   r:   s      r#   	show_attrzFilterMixIn.show_attrp   s0    #GD&$$?$?@@
;!4444r.   N)rK   r0   r   r%   )r<   rX   r   r>   )__name__
__module____qualname____doc__rW   r\    r.   r#   rJ   rJ   c   sB        AA   5 5 5 5 5 5r.   rJ   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)rT   s    r#   rW   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__rf   r   r]   lowerrZ   )rT   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'   )rh   addrw   hasattrvaluesvisit)rT   r<   rs   
local_nodes       r#   r}   zLocalsVisitor.visit   s    4=  4$$$T**1:!GAJt4"" 	'"kkmm ' '


:&&&&1:!71:d###tr.   Nr   r%   )r<   ri   r   rj   )r<   ri   r   r   )r]   r^   r_   r`   rW   rw   r}   ra   r.   r#   rc   rc   v   sZ         1 1 1 1" " " ""     r.   rc   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      sK    #uz"" sx';x#u|$$ }}2r.   #nodes.AssignAttr | nodes.AssignName#nodes.Name | nodes.Subscript | Nonec                   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%          |          }|rqt'          |dd          `|                    d          sKt          |t          j                  r+t-          d |                                D                       sd| d}|r	|r||_        |S )z!Return the annotation for `node`.Nr   valuer   c              3  \   K   | ]'}t          |t          j                  o|j        d u V  (d S re   )r   r
   Constr   ).0childs     r#   	<genexpr>z!get_annotation.<locals>.<genexpr>   sN         5%+..F5;$3F     r.   z	Optional[])r   parentr
   	AnnAssign
annotation
AssignAttrdictzipry   argsr   r   r   r/   AttributeErrorinferastroidInferenceErrorr   rZ   
startswithBinOpanyget_children)r<   r   init_methodr   default_labels          r#   get_annotationr      s    C$+u// 
k$	D%*	+	+ k(	s;#5{7G7STTUUK!+/$+"3"899CC 	 	 	D	 
jjll!!!    !%%E 	&GWg..6  ,, 7 3,, 7    --//    	 7 &U%%%  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
   	Subscriptr   oprg   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whichrQ   r)   exitra   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   rR   striprQ   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5dmddQbdd	
 	
 	
 		 65r.   )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%   ).r`   
__future__r   r   r   r   r   r)   typingr   r   r   r   r   r	   r   r
   astroid.typingr   pylint.pyreverse.diagramsr   r   r   
_CallbackTrj   r   r$   r-   compiler6   r8   r9   r;   rB   _SPECIAL
_PROTECTED_PRIVATErO   r[   rJ   rc   r   r   r   r   r   ra   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&- - - - - - - -`   ( ( ( (V' ' ' '$        r.   