o
    bVJ                     @   s(  d 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 e	dZ
e	dZejZe	dZe Zejd	kr@d
ZdZndZdZed dhZh dZdd ZG dd dZd%ddZdd ZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZdS )&zXThis module contains base classes and functions for the nodes and some
inference utils.
    Ncontext)
exceptions)utilzinterpreter.objectmodelhelpersmanager)   r   builtins__bool____builtin____nonzero__z	.propertyzabc.abstractproperty>
   lazyreifyLazyPropertylazypropertylazy_propertylazyattributecache_readonlycachedpropertylazy_attributecached_propertyc                    s   t |  r	dS dd |  D  t fddtD rdS | js$dS | jjp)dD ]:}t|}|d u s:|t	j
u r;q*|jjdkrd|jD ]}|jjd	krMqD||j\}}|jtkrc|jd
krc  dS qDq*dS )NTc                 S   s$   h | ]}|t jur|d d qS ).)r   Uninferablesplit.0name r   L/var/www/secure340b-portal/env/lib/python3.10/site-packages/astroid/bases.py	<setcomp>D   s    z_is_property.<locals>.<setcomp>c                 3   s    | ]}| v V  qd S Nr   r   strippedr   r   	<genexpr>I   s    z_is_property.<locals>.<genexpr>Fr   ClassDefNameproperty)
PROPERTIESintersectionZdecoratornamesanyPOSSIBLE_PROPERTIES
decoratorsnodesr   Z
safe_inferr   r   	__class____name__baseslookupr   BUILTINS)meth	decoratorinferredZ
base_classmodule_r   r"   r   _is_propertyA   s,   

r8   c                   @   s0   e Zd ZdZdZd	ddZdd Zd	ddZdS )
Proxyza simple proxy object

    Note:

    Subclasses of this object will need a custom __getattr__
    if new instance attributes are created. See the Const class
    Nc                 C   s   |d ur	|| _ d S d S r!   )_proxied)selfZproxiedr   r   r   __init__i   s   
zProxy.__init__c                 C   s4   |dkr
t | jdS || jv r| j| S t | j|S )Nr:   )getattrr.   __dict__r:   )r;   r   r   r   r   __getattr__m   s
   

zProxy.__getattr__c                 c   s    | V  d S r!   r   )r;   r   r   r   r   infert   s   
zProxy.inferr!   )r/   
__module____qualname____doc__r:   r<   r?   r@   r   r   r   r   r9   ^   s    
r9   c              	   c   s    d}|dur|j }| }nd}t }| D ]=}|tju r$|V  d}q||||_ z|j|dD ]}|V  d}q2W q tj	yE   Y q tj
yT   tjV  d}Y qw |s`tj
d| ||ddS )zGReturn an iterator on statements inferred by each statement in *stmts*.FNTr   z.Inference failed for all members of {stmts!r}.)stmtsframer   )Z
lookupnameclone
contextmodInferenceContextr   r   Z_infer_namer@   r   ZNameInferenceErrorInferenceError)rD   r   rE   r5   r   stmtr   r   r   _infer_stmtsx   s@   

rK   c                 C   s   t | j||dd }|rKt|drK| stjS z&|j| |dD ]}|tju r,|  W S t |j|d}|   W S W tjS  t	j
yJ   Y tjS w tjS )Nr   infer_call_result)nextigetattrhasattrcallabler   r   rL   r@   
bool_valuer   rI   )instancemethod_namer   r3   valuer5   r   r   r   _infer_method_result_truth   s"   

rU   c                   @   sD   e Zd ZdZdZdd ZdddZddd	Zdd
dZdddZ	dS )BaseInstancezNAn instance base class, which provides lookup methods for potential instances.Nc                 C      dS NzInstance ofr   r;   r   r   r   display_type      zBaseInstance.display_typeTc              
   C   s   z	| j ||}W n< tjyE } z/| jr'|| jv r'| j|gW  Y d }~S |r8| j j||ddW  Y d }~S tj| ||d|d }~ww |r`z|| j j||dd W S  tjy_   Y |S w |S )NFZclass_context)target	attributer   )r:   Zinstance_attrr   AttributeInferenceErrorspecial_attributesr1   r=   )r;   r   r   lookupclassvaluesexcr   r   r   r=      s0   
zBaseInstance.getattrc                 c   s    |st  }z$|| j|frW dS | j||dd}t| |||| dE dH  W dS  tjy~ } zFz&| jj	j
dkrGtjdi t||| jj||dd}| ||E dH  W n tjyr } ztjdi t||d}~ww W Y d}~dS d}~ww )zinferred getattrNF)ra   )rE   r%   r\   r   )rG   rH   pushr:   r=   rK   
_wrap_attrr   r_   r.   r/   rI   varsrN   )r;   r   r   Zget_attrerrorattrsr   r   r   rN      s.   zBaseInstance.igetattrc                 c   s    |D ]J}t |trt|r|| |E dH  qt|| V  qt|drJ|jdkrJ|  | j	krF|j
j
rF|j
j
d jdkrFt|| V  q|V  q|V  qdS )z7wrap bound methods of attrs in a InstanceMethod proxiesNr   z<lambda>r   r;   )
isinstanceUnboundMethodr8   rL   BoundMethodrO   r   Z	statementscoper:   args)r;   rh   r   attrr   r   r   re      s   
zBaseInstance._wrap_attrc                 c   sn    t || }d}| jd|D ]}|tju s| sq|||D ]}d}|V  q"q|s5tj	| ||ddS )z4infer what a class instance is returning when calledF__call__T)nodecallerr   N)
rG   bind_context_to_noder:   rN   r   r   rP   rL   r   rI   )r;   rq   r   r5   rp   resr   r   r   rL      s   zBaseInstance.infer_call_resultNTr!   )
r/   rA   rB   rC   r`   rZ   r=   rN   re   rL   r   r   r   r   rV      s    


rV   c                   @   sX   e Zd ZdZedd Zdd Zdd Zdd	 Z	d
d Z
dd Zdd ZdddZdS )Instancez-A special node representing a class instance.c                   C      t  S r!   )objectmodelZInstanceModelr   r   r   r   <lambda>      zInstance.<lambda>c                 C   s   d| j  j| j jt| f S )Nz<Instance of %s.%s at 0x%s>)r:   rootr   idrY   r   r   r   __repr__  s
   
zInstance.__repr__c                 C   s   d| j  j| j jf S )NzInstance of %s.%s)r:   rz   r   rY   r   r   r   __str__  s   zInstance.__str__c                 C   s.   z| j jddd W dS  tjy   Y dS w )Nro   Fr\   T)r:   r=   r   r_   rY   r   r   r   rP     s   zInstance.callablec                 C   s
   | j  S r!   )r:   qnamerY   r   r   r   pytype$     
zInstance.pytypec                 C   rW   rX   r   rY   r   r   r   rZ   '  r[   zInstance.display_typec                 C   sz   t  }t jg d|_| |_z	t| t|}W |S  tjtj	fy<   z
t| d|}W Y |S  tj	tjfy;   Y Y dS w w )aV  Infer the truth value for an Instance

        The truth value of an instance is determined by these conditions:

           * if it implements __bool__ on Python 3 or __nonzero__
             on Python 2, then its bool value will be determined by
             calling this special method and checking its result.
           * when this method is not defined, __len__() is called, if it
             is defined, and the object is considered true if its result is
             nonzero. If a class defines neither __len__() nor __bool__(),
             all its instances are considered true.
        )rm   __len__T)
rG   rH   ZCallContextZcallcontextZ	boundnoderU   BOOL_SPECIAL_METHODr   rI   r_   )r;   r   resultr   r   r   rQ   *  s   zInstance.bool_valueNc                 C   s   d S r!   r   )r;   indexr   r   r   r   getitemF  r[   zInstance.getitemr!   )r/   rA   rB   rC   r   lazy_descriptorr`   r|   r}   rP   r   rZ   rQ   r   r   r   r   r   ru     s    ru   c                   @   sZ   e Zd ZdZedd Zdd Zdd Zdd	 Z	dddZ
dddZdd Zdd Zd
S )rj   z=a special node representing a method not bound to an instancec                   C   rv   r!   )rw   ZUnboundMethodModelr   r   r   r   rx   N  ry   zUnboundMethod.<lambda>c                 C   s,   | j j }d| jj| j j| t| f S )Nz<%s %s of %s at 0x%s)r:   parentrE   r.   r/   r   r~   r{   )r;   rE   r   r   r   r|   P  s   zUnboundMethod.__repr__c                 C   rW   )Nr   r   rY   r   r   r   implicit_parametersY  r[   z!UnboundMethod.implicit_parametersc                 C   rW   NFr   rY   r   r   r   is_bound\  r[   zUnboundMethod.is_boundNc                 C   s&   || j v r| j |gS | j||S r!   )r`   r1   r:   r=   r;   r   r   r   r   r   r=   _  s   
zUnboundMethod.getattrc                 C   s*   || j v rt| j |fS | j||S r!   )r`   iterr1   r:   rN   r   r   r   r   rN   d  s   
zUnboundMethod.igetattrc                 C   sp   | j jdkr1| j j  dt kr1|jr(|j|jd }|jd j	|d}ng }dd |D S | j 
||S )a  
        The boundnode of the regular context with a function called
        on ``object.__new__`` will be of type ``object``,
        which is incorrect for the argument in general.
        If no context is given the ``object.__new__`` call argument will
        correctly inferred except when inside a call that requires
        the additional context (such as a classmethod) of the boundnode
        to determine which class the method was called from
        __new__z	%s.objectr   r   c                 s   s&    | ]}|t jurt|n|V  qd S r!   )r   r   ru   )r   xr   r   r   r$     s   $ z2UnboundMethod.infer_call_result.<locals>.<genexpr>)r:   r   r   rE   r~   r2   rm   Zextra_contextgetr@   rL   )r;   rq   r   Znode_contextr@   r   r   r   rL   i  s   
zUnboundMethod.infer_call_resultc                 C   rW   rt   r   rY   r   r   r   rQ     r[   zUnboundMethod.bool_valuer!   )r/   rA   rB   rC   r   r   r`   r|   r   r   r=   rN   rL   rQ   r   r   r   r   rj   J  s    	

rj   c                       sX   e Zd ZdZedd Zdd Zdd Zdd	 Z	d
d Z
d fdd	Zdd Z  ZS )rk   z9a special node representing a method bound to an instancec                   C   rv   r!   )rw   ZBoundMethodModelr   r   r   r   rx     ry   zBoundMethod.<lambda>c                 C   s   t | | || _d S r!   )rj   r<   bound)r;   proxyr   r   r   r   r<     s   
zBoundMethod.__init__c                 C   rW   )N   r   rY   r   r   r   r     r[   zBoundMethod.implicit_parametersc                 C   rW   rt   r   rY   r   r   r   r     r[   zBoundMethod.is_boundc                    s  ddl m} t|jd j d}|jjdkrdS |dt s"dS t|jd j d}|jjdkr5dS t	|j
ts=dS t|jd	 j d}|jjd
krPdS  fdd|jD }tdd |D redS t|jd j d}|jjdkrxdS tt}	|jD ](\}
}t|
j d}
t|j d}|
jjdkrt	|
j
tr|	|
j
 | q|j|j
|j|j|d}| }|j|j|gg d|g d |	|_|S )zTry to infer what type.__new__(mcs, name, bases, attrs) returns.

        In order for such call to be valid, the metaclass needs to be
        a subtype of ``type``, the name needs to be a string, the bases
        needs to be a tuple of classes
        r   )node_classesr   r%   Nz%s.typer   ZConst   Tuplec                    s   g | ]
}t |j d qS )r   )rM   r@   )r   eltr   r   r   
<listcomp>  s    z4BoundMethod._infer_type_new_call.<locals>.<listcomp>c                 s   s    | ]	}|j jd kV  qdS )r%   N)r.   r/   )r   baser   r   r   r$     s    z3BoundMethod._infer_type_new_call.<locals>.<genexpr>r   Dict)r   lineno
col_offsetr   T)r0   bodyr,   Znewstyle	metaclasskeywords)astroidr   rM   rm   r@   r.   r/   Zis_subtype_ofr2   ri   rT   streltsr*   collectionsdefaultdictlistitemsappendr   r   PassZpostinitlocals)r;   rq   r   r   mcsr   r0   Zinferred_basesrh   Z
cls_localskeyrT   clsemptyr   r   r   _infer_type_new_call  sX   
z BoundMethod._infer_type_new_callNc                    sl   t || j}| jjjdkr-| jjdkr-| jdkr-t|jdkr-| ||}|r-t	|fS t
t| ||S )Nr%   typer      )rG   rr   r   r.   r/   r   lenrm   r   r   superrk   rL   )r;   rq   r   Znew_clsr.   r   r   rL     s   

zBoundMethod.infer_call_resultc                 C   rW   rt   r   rY   r   r   r   rQ     r[   zBoundMethod.bool_valuer!   )r/   rA   rB   rC   r   r   r`   r<   r   r   r   rL   rQ   __classcell__r   r   r   r   rk     s    Erk   c                   @   sX   e Zd ZdZedd ZdddZdd Zd	d
 Z	dd Z
dd Zdd Zdd ZdS )	Generatorzea special node representing a generator.

    Proxied class is set once for all in raw_building.
    c                   C   rv   r!   )rw   ZGeneratorModelr   r   r   r   rx     ry   zGenerator.<lambda>Nc                 C   s
   || _ d S r!   )r   )r;   r   r   r   r   r<     r   zGenerator.__init__c                 C   rW   r   r   rY   r   r   r   rP     r[   zGenerator.callablec                 C      dt  S )Nz%s.generatorr2   rY   r   r   r   r        zGenerator.pytypec                 C   rW   )Nr   r   rY   r   r   r   rZ     r[   zGenerator.display_typec                 C   rW   rt   r   rY   r   r   r   rQ     r[   zGenerator.bool_valuec                 C      d| j j| jt| f S )Nz<Generator(%s) l.%s at 0x%s>r:   r   r   r{   rY   r   r   r   r|     
   zGenerator.__repr__c                 C      d| j j S )NzGenerator(%s)r:   r   rY   r   r   r   r}        zGenerator.__str__r!   )r/   rA   rB   rC   r   r   r`   r<   rP   r   rZ   rQ   r|   r}   r   r   r   r   r     s    
r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )AsyncGeneratorz,Special node representing an async generatorc                 C   r   )Nz%s.async_generatorr   rY   r   r   r   r     r   zAsyncGenerator.pytypec                 C   rW   )Nr   r   rY   r   r   r   rZ     r[   zAsyncGenerator.display_typec                 C   r   )Nz!<AsyncGenerator(%s) l.%s at 0x%s>r   rY   r   r   r   r|     r   zAsyncGenerator.__repr__c                 C   r   )NzAsyncGenerator(%s)r   rY   r   r   r   r}   "  r   zAsyncGenerator.__str__N)r/   rA   rB   rC   r   rZ   r|   r}   r   r   r   r   r     s    r   r!   )rC   r	   r   sysr   r   rG   r   r   Zlazy_importrw   r   r/   r2   r   ZAstroidManagerZMANAGERversion_infor   r(   r+   r8   r9   rK   rU   rV   ru   rj   rk   r   r   r   r   r   r   <module>   s:   



	
"`=<h$