
    yIf4                       d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
mZ ddlZddlmZ ddlmZ ddlmZ e
e
egej        f         eegeej                 f         Z	 d*d+dZ G d d          Z G d d          Z G d deej                  Z G d de          Z G d de          Z G d de          Z G d d e          Zed!ej        d	fd,d)Z dS )-z|Visitor doing some post-processing on the astroid tree.

Try to resolve definitions (namespace) dictionary, relationship...
    )annotationsN)ABCabstractmethod)CallableOptional)nodes)	constants)utilsFfuncCallable[[str], nodes.Module]modnamestrverboseboolreturnnodes.Module | Nonec                    |rt          d| d           	  | |          S # t          j        j        $ r}t          |           Y d }~n&d }~wt          $ r t          j                     Y nw xY wd S )Nzparsing z...)printastroid
exceptionsAstroidBuildingError	Exception	traceback	print_exc)r   r   r   excs       N/var/www/piapp/venv/lib/python3.11/site-packages/pylint/pyreverse/inspector.py_astroid_wrapperr      s    
  '%%%%&&&tG}}2   c







   4s   
" A-A

 A-,A-c                  .    e Zd ZdZdddZdddZdd	Zd
S )IdGeneratorMixInz1Mixin adding the ability to generate integer uid.r   start_valueintr   Nonec                    || _         d S Nid_countselfr    s     r   __init__zIdGeneratorMixIn.__init__0   s    #    c                    || _         dS )zInit the id counter.Nr%   r'   s     r   init_counterzIdGeneratorMixIn.init_counter3   s    #r*   c                0    | xj         dz  c_         | j         S )zGenerate a new identifier.   r%   r(   s    r   generate_idzIdGeneratorMixIn.generate_id7   s    }r*   N)r   )r    r!   r   r"   )r   r!   )__name__
__module____qualname____doc__r)   r,   r0    r*   r   r   r   -   s`        ;;$ $ $ $ $$ $ $ $ $     r*   r   c                  <    e Zd ZdZdddZdd
ZddZddZddZdS )Projectz-A project handle a set of modules / packages. namer   c                    || _         d | _        d| _        g | _        i | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j        | _        | j        j	        | _	        d S )Nr8   )
r9   uidpathmoduleslocals__getitem____iter__valueskeysitemsr(   r9   s     r   r)   zProject.__init__@   sf    	#	+-/1;2,k(K$	[&


r*   nodenodes.Moduler   r"   c                X    || j         |j        <   | j                            |           d S r$   )r>   r9   r=   appendr(   rE   s     r   
add_modulezProject.add_moduleL   s,    !%DID!!!!!r*   c                    | j         |         S r$   )r>   rD   s     r   
get_modulezProject.get_moduleP   s    {4  r*   list[nodes.Module]c                    | j         S r$   )r=   r/   s    r   get_childrenzProject.get_childrenS   s
    |r*   c                b    d| j         dt          |            dt          | j                   dS )Nz	<Project z at z (z
 modules)>)r9   idlenr=   r/   s    r   __repr__zProject.__repr__V   s5    U49UUBtHHUUDL8I8IUUUUr*   N)r8   )r9   r   rE   rF   r   r"   )r9   r   r   rF   )r   rM   )r   r   )	r1   r2   r3   r4   r)   rJ   rL   rO   rS   r5   r*   r   r7   r7   =   s        77
' 
' 
' 
' 
'" " " "! ! ! !   V V V V V Vr*   r7   c                  |    e Zd ZdZd#d$d	Zd%dZd&dZd'dZd(dZd)dZ	e
d*d            Zd+dZd,dZd-dZd.d!Zd"S )/Linkera_  Walk on the project tree and resolve relationships.

    According to options the following attributes may be
    added to visited nodes:

    * uid,
      a unique identifier for the node (on astroid.Project, astroid.Module,
      astroid.Class and astroid.locals_type). Only if the linker
      has been instantiated with tag=True parameter (False by default).

    * Function
      a mapping from locals names to their bounded value, which may be a
      constant like a string or an integer, or an astroid node
      (on astroid.Module, astroid.Class and astroid.Function).

    * instance_attrs_type
      as locals_type but for klass member attributes (only on astroid.Class)

    * associations_type
      as instance_attrs_type but for association relationships

    * aggregations_type
      as instance_attrs_type but for aggregations relationships
    Fprojectr7   tagr   r   r"   c                   t                               |            t          j                            |            || _        || _        t                      | _        | j                            t                                 d S r$   )
r   r)   r
   LocalsVisitorrX   rW   AggregationsHandlerassociations_handlerset_nextOtherAssociationsHandler)r(   rW   rX   s      r   r)   zLinker.__init__t   sm    !!$'''$$T***$7$9$9!!**+C+E+EFFFFFr*   rE   c                    | j         r|                                 |_        |j        D ]}|                     |           dS )zbVisit a pyreverse.utils.Project node.

        * optionally tag the node with a unique id
        N)rX   r0   r;   r=   visit)r(   rE   modules      r   visit_projectzLinker.visit_project~   sQ    
 8 	*''))DHl 	 	FJJv	 	r*   rF   c                    t          |d          rdS t          j        t                    |_        g |_        g |_        | j        r|                                 |_	        dS dS )zVisit an astroid.Module node.

        * set the locals_type mapping
        * set the depends mapping
        * optionally tag the node with a unique id
        locals_typeN)
hasattrcollectionsdefaultdictlistrd   dependstype_dependsrX   r0   r;   rI   s     r   visit_modulezLinker.visit_module   sh     4'' 	F&24888 	*''))DHHH	* 	*r*   nodes.ClassDefc                   t          |d          rdS t          j        t                    |_        | j        r|                                 |_        |                    d          D ]/}t          |dg           }|
                    |           ||_        0t          j        t                    |_        t          j        t                    |_        t          j        t                    |_        t          |j                                                  D ]R}|D ]M}t%          |t&          j                  s1| j                            ||           |                     ||           NSdS )zVisit an astroid.Class node.

        * set the locals_type and instance_attrs_type mappings
        * optionally tag the node with a unique id
        rd   NF)recursspecializations)re   rf   rg   rh   rd   rX   r0   r;   	ancestorsgetattrrH   ro   instance_attrs_typeaggregations_typeassociations_typetupleinstance_attrsrA   
isinstancer   Unknownr\   handlehandle_assignattr_type)r(   rE   baseobjro   assignattrs
assignattrs         r   visit_classdefzLinker.visit_classdef   sb    4'' 	F&24888 	*''))DH~~U~33 	6 	6G%g/@"EEO""4(((&5G###.#:4#@#@ !,!8!>!>!,!8!>!> !4!;!;!=!=>> 	B 	BK) B B
!*em<< B-44ZFFF//
DAAAB	B 	Br*   nodes.FunctionDefc                    t          |d          rdS t          j        t                    |_        | j        r|                                 |_        dS dS )zVisit an astroid.Function node.

        * set the locals_type mapping
        * optionally tag the node with a unique id
        rd   N)re   rf   rg   rh   rd   rX   r0   r;   rI   s     r   visit_functiondefzLinker.visit_functiondef   sY     4'' 	F&24888 	*''))DHHH	* 	*r*   nodes.AssignNamec                j   t          |d          rdS d|_        |j        |                                v r|                                }n|                                }t          |d          sut          |t          j                  r|                     |           nEt          |t          j	                  r| 
                    |           n|                     |           |j        |j                 }t          t          |          t          j        |          z            |j        |j        <   dS )zFVisit an astroid.AssignName node.

        handle locals_type
        _handledNTrd   )re   r   r9   framerootrw   r   ClassDefr~   FunctionDefr   rk   rd   rh   setr
   
infer_node)r(   rE   r   currents       r   visit_assignnamezLinker.visit_assignname   s    4$$ 	F9

$$JJLLEE IIKKEum,, 		) %00 )##E****E5#455 )&&u----!!%(((#DI.'+CLL5;KD;Q;Q,Q'R'R$)$$$r*   nodes.AssignAttrparentc                    t          |j        | j                           }t          |t	          j        |           z            |j        | j        <   dS )zOHandle an astroid.assignattr node.

        handle instance_attrs_type
        N)r   rr   attrnamerh   r
   r   )rE   r   r   s      r   rz   zLinker.handle_assignattr_type   sM     f0?@@48e&t,,,5
 5
"4=111r*   nodes.Importc                    |                                 j        }|j        D ]E}t          j                            |d         |          }|                     ||d         |           FdS )zKVisit an astroid.Import node.

        resolve module dependencies
        r   N)r   filenamesr   modutilsis_relative_imported_module)r(   rE   context_filer9   relatives        r   visit_importzLinker.visit_import   sj    
 yy{{'J 	; 	;D'33DG\JJH!!$Q::::	; 	;r*   nodes.ImportFromc                   |j         }|                                j        }|!t          j                            ||          }nd}|j        D ]}|d         dk    r| d|d          }|                    d          dk    r2	 t          j                            ||          }n# t          $ r Y cw xY w||k    r| 
                    |||           dS )zOVisit an astroid.ImportFrom node.

        resolve module dependencies
        NFr   *.)r   r   r   r   r   r   r   findget_module_partImportErrorr   )r(   rE   basenamer   r   r9   fullnames          r   visit_importfromzLinker.visit_importfrom   s    
 <yy{{'#'33HlKKHHHJ 	@ 	@DAw#~~"..T!W..H}}S!!B&&&/??,WWHH"   H8##%%dHh???	@ 	@s    B$$
B10B1context_namer   mod_pathc                    t           j                            | j        j                  }||k    rdS t          j                            ||f          S )z,Should the module be added to dependencies ?F)osr<   dirnamerW   r   r   module_in_path)r(   r   r   package_dirs       r   compute_modulezLinker.compute_module  sG    goodl&7888##5 ..x+HHHr*   nodes.Import | nodes.ImportFromr   c                L   |                                 }|j        }|r5d                    |                    d          dd                    d| }|                     ||          r9t          |d          sg |_        |j        }||vr|                    |           dS dS dS )z8Notify an imported module, used to analyze dependencies.r   Nr   ri   )r   r9   joinsplitr   re   ri   rH   )r(   rE   r   r   ra   r   	mod_pathss          r   r   zLinker._imported_module  s     { 	N((<#5#5c#:#:3B3#?@@MM8MMH|X66 	+69-- $!#Iy((  *****	+ 	+
 )(r*   NF)rW   r7   rX   r   r   r"   )rE   r7   r   r"   rT   )rE   rl   r   r"   )rE   r   r   r"   )rE   r   r   r"   rE   r   r   rl   r   r"   )rE   r   r   r"   )rE   r   r   r"   )r   r   r   r   r   r   )rE   r   r   r   r   r   r   r"   )r1   r2   r3   r4   r)   rb   rk   r~   r   r   staticmethodrz   r   r   r   r   r5   r*   r   rV   rV   Z   s         2G G G G G   * * * *B B B B4
* 
* 
* 
*S S S S< 
 
 
 \
; ; ; ;@ @ @ @0I I I I+ + + + + +r*   rV   c                  >    e Zd Zedd            Zedd	            Zd
S )AssociationHandlerInterfacehandlerr   c                    d S r$   r5   r(   r   s     r   r]   z$AssociationHandlerInterface.set_next#  s	     	r*   rE   r   r   rl   r"   c                    d S r$   r5   r(   rE   r   s      r   ry   z"AssociationHandlerInterface.handle)  s    r*   Nr   r   r   r   r   )r1   r2   r3   r   r]   ry   r5   r*   r   r   r   "  sR           ^
    ^  r*   r   c                  >    e Zd ZU dZded<   ddZedd            ZdS )AbstractAssociationHandlera  
    Chain of Responsibility for handling types of association, useful
    to expand in the future if we want to add more distinct associations.

    Every link of the chain checks if it's a certain type of association.
    If no association is found it's set as a generic association in `associations_type`.

    The default chaining behavior is implemented inside the base handler
    class.
    r   _next_handlerr   r   c                    || _         |S r$   )r   r   s     r   r]   z#AbstractAssociationHandler.set_next<  s     %r*   rE   r   r   rl   r"   c                N    | j         r| j                             ||           d S d S r$   )r   ry   r   s      r   ry   z!AbstractAssociationHandler.handleB  s6     	4%%dF33333	4 	4r*   Nr   r   )r1   r2   r3   r4   __annotations__r]   r   ry   r5   r*   r   r   r   .  sb         	 	 /...    4 4 4 ^4 4 4r*   r   c                        e Zd Zd fdZ xZS )	r[   rE   r   r   rl   r   r"   c                   t          |j        t          j        t          j        f          r{t          |j        j        t          j        j                  rRt          |j
        |j                           }t          |t          j        |          z            |j
        |j        <   d S t                                          ||           d S r$   )rw   r   r   	AnnAssignAssignvaluer   node_classesNamer   rs   r   rh   r
   r   superry   )r(   rE   r   r   	__class__s       r   ry   zAggregationsHandler.handleI  s    dkEOU\#BCC 	)
Kw38I
 I
 	) &24=ABBG6:%*40007 7F$T]333 GGNN4(((((r*   r   )r1   r2   r3   ry   __classcell__)r   s   @r   r[   r[   H  s=        	) 	) 	) 	) 	) 	) 	) 	) 	) 	)r*   r[   c                      e Zd Zd	dZdS )
r^   rE   r   r   rl   r   r"   c                    t          |j        |j                           }t          |t	          j        |          z            |j        |j        <   d S r$   )r   rt   r   rh   r
   r   )r(   rE   r   r   s       r   ry   zOtherAssociationsHandler.handleV  sG    f.t}=>>26wAQRVAWAW7W2X2X ///r*   Nr   )r1   r2   r3   ry   r5   r*   r   r^   r^   U  s.        Y Y Y Y Y Yr*   r^   zno namefiles	list[str]func_wrapper_WrapperFuncTproject_name
black_listtuple[str, ...]c                .   t           j        }t          |          }| D ]u}t          j                            |          s3t           j                            |                    d                    }nBt          j        	                    |          r!t          j        
                    |d          }n|} ||j        ||          }	|	|j        p|	j        |_        |                    |	           |	j        }
|	j        r|                    d          dk    rzt           j                            t          j                            |	j                  |          D ]7} ||j        ||          }	|	|	j        |
k    r"|                    |	           8w|S )z1Return a Project from a list of files or modules.r   z__init__.pyNr)   r   )r   MANAGERr7   r   r<   existsr   file_from_modpathr   isdirr   ast_from_filer   rJ   r9   packager   get_module_filesr   )r   r   r   r   r   astroid_managerrW   	somethingfpathast	base_names              r   project_from_filesr   [  s|    oOl##G ( (	w~~i(( 	$66ys7K7KLLEEW]]9%% 	GLLM::EEEl?8%II;|/sx3H	; 	(9>>*55;; )::)):  ( ( #l?#@%QQ;#(i"7"7""3''''Nr*   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r7   )!r4   
__future__r   rf   r   r   abcr   r   typingr   r   r   r   pylintr	   pylint.pyreverser
   r   Moduler   r   r   r   r7   rZ   rV   r   r   r[   r^   DEFAULT_IGNORE_LISTr   r5   r*   r   <module>r      sw  
 
 # " " " " "     				     # # # # # # # # % % % % % % % %              " " " " " "seU\!"C.0FF              V V V V V V V V:E+ E+ E+ E+ E+u2 E+ E+ E+P	 	 	 	 	# 	 	 	4 4 4 4 4!< 4 4 44
) 
) 
) 
) 
)4 
) 
) 
)Y Y Y Y Y9 Y Y Y #3!"+"?" " " " " " "r*   