
    -hc                       d dl mZ d dlZd dlmZ d dlmZmZ d dlm	Z	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZ d dlmZ d dlmZmZmZ d dl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 erd dl4m5Z5 d dl6m7Z7 d dlm8Z8 ddddZ9	 dhdhddhddhdhdhdZ:	 ddhZ;	 dddddddd5d2Z< G d3 d4          Z=dS )6    )annotationsN)suppress)TYPE_CHECKINGAny)get_instance_names	get_names)ast_childrenast_kindast_next)get_docstring)safe_get__all__)relative_to_absolute)get_parameters)LinesCollectionModulesCollection)Kind)AliasResolutionErrorCyclicAliasErrorLastNodeError)ExprExprNamesafe_get_annotationsafe_get_base_classsafe_get_conditionsafe_get_expression)
Extensionsload_extensions)	Alias	AttributeClass	Decorator	DocstringFunctionModule	Parameter
Parameters)Path)DocstringStyle)Parserpropertystaticmethodclassmethod)r*   r+   r,   abstractmethodcached	dataclass)zabc.abstractmethodzfunctools.cachezfunctools.cached_propertyzcached_property.cached_propertyzfunctools.lru_cachezdataclasses.dataclassztyping.overloadztyping_extensions.overload)
extensionsparentdocstring_parserdocstring_optionslines_collectionmodules_collectionmodule_namestrfilepathr'   coder0   Extensions | Noner1   Module | Noner2   DocstringStyle | Parser | Noner3   dict[str, Any] | Noner4   LinesCollection | Noner5   ModulesCollection | Nonereturnr$   c               r    t          | |||pt                      |||||	  	                                        S )a  Parse and visit a module file.

    We provide this function for static analysis. It uses a [`NodeVisitor`][ast.NodeVisitor]-like class,
    the [`Visitor`][griffe.Visitor], to compile and parse code (using [`compile`][])
    then visit the resulting AST (Abstract Syntax Tree).

    Important:
        This function is generally not used directly.
        In most cases, users can rely on the [`GriffeLoader`][griffe.GriffeLoader]
        and its accompanying [`load`][griffe.load] shortcut and their respective options
        to load modules using static analysis.

    Parameters:
        module_name: The module name (as when importing [from] it).
        filepath: The module file path.
        code: The module contents.
        extensions: The extensions to use when visiting the AST.
        parent: The optional parent of this module.
        docstring_parser: The docstring parser to use. By default, no parsing is done.
        docstring_options: Additional docstring parsing options.
        lines_collection: A collection of source code lines.
        modules_collection: A collection of modules.

    Returns:
        The module, with its members populated.
    )r2   r3   r4   r5   )Visitorr   
get_module)	r6   r8   r9   r0   r1   r2   r3   r4   r5   s	            S/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/_griffe/agents/visitor.pyvisitrE   A   sM    L 'o'')+)-
 
 
 jll
    c                       e Zd ZdZ	 	 	 	 	 dGdH fdZdddIdZdJd ZdKd!ZdKd"ZdLd$Z	dMd&Z
dNd*ZdOd.ZdPdQd2ZdRd4ZdSd6ZdTd8ZdUd:Z	 dPdVd>ZdWd@ZdXdBZdYdDZdZdFZ xZS )[rB   zoThis class is used to instantiate a visitor.

    Visitors iterate on AST nodes to extract data from them.
    Nr6   r7   r8   r'   r9   r0   r   r1   r;   r2   r<   r3   r=   r4   r>   r5   r?   r@   Nonec
                2   t                                                       || _        	 || _        	 || _        	 || _        	 || _        	 d| _        	 || _        	 |pi | _	        	 |pt                      | _        	 |	pt                      | _        	 d| _        dS )a(  Initialize the visitor.

        Parameters:
            module_name: The module name.
            filepath: The module filepath.
            code: The module source code.
            extensions: The extensions to use when visiting.
            parent: An optional parent for the final module object.
            docstring_parser: The docstring parser to use.
            docstring_options: The docstring parsing options.
            lines_collection: A collection of source code lines.
            modules_collection: A collection of modules.
        NF)super__init__r6   r8   r9   r0   r1   currentr2   r3   r   r4   r   r5   type_guarded)selfr6   r8   r9   r0   r1   r2   r3   r4   r5   	__class__s             rD   rK   zVisitor.__init__z   s    2 	 +&"	%&0:%+='+/@P*1B1Hb,1A1V_EVEV05G5^K\K^K^&"'>>rF   Fstrictnodeast.ASTrQ   boolDocstring | Nonec               p    t          ||          \  }}}|d S t          |||| j        | j                  S )NrP   )lineno	endlinenoparserparser_options)r   r"   r2   r3   )rN   rR   rQ   valuerW   rX   s         rD   _get_docstringzVisitor._get_docstring   sQ    #0f#E#E#E vy=4(1
 
 
 	
rF   r$   c                    t          | j        dt          | j                  t          j        d          }|                     |           | j        j        S )zBuild and return the object representing the module attached to this visitor.

        This method triggers a complete visit of the module nodes.

        Returns:
            A module instance.
        exec   )modefilenameflagsoptimize)	compiler9   r7   r8   astPyCF_ONLY_ASTrE   rL   module)rN   top_nodes     rD   rC   zVisitor.get_module   sJ     496C<N<NVYVgrsttt

8|""rF   c                d     t          | dt          |           | j                  |           dS )ziExtend the base visit with extensions.

        Parameters:
            node: The node to visit.
        visit_N)getattrr
   generic_visitrN   rR   s     rD   rE   zVisitor.visit   s9     	E/x~~//1CDDTJJJJJrF   c                T    t          |          D ]}|                     |           dS )zqExtend the base generic visit with extensions.

        Parameters:
            node: The node to visit.
        N)r	   rE   )rN   rR   childs      rD   rl   zVisitor.generic_visit   s:     "$'' 	 	EJJu	 	rF   
ast.Modulec                $   | j                             d||            | j                             d||            t          | j        | j        | j        |                     |          | j        | j                  x| _	        }| j                             d|||            | j                             d|||            | 
                    |           | j                             d	|||            | j                             d
|||            dS )zWVisit a module node.

        Parameters:
            node: The node to visit.
        on_noderR   agenton_module_node)namer8   r1   	docstringr4   r5   on_instancerR   objrt   on_module_instance)rR   modrt   
on_memberson_module_membersN)r0   callr$   r6   r8   r1   r\   r4   r5   rL   rl   )rN   rR   rg   s      rD   visit_modulezVisitor.visit_module   s$    	YT>>>-DEEE &!];))$//!2#6!
 !
 !
 	
v 	]6NNN1&PTUUU4   \&MMM0ttTTTTTrF   ast.ClassDefc           	     v     j                             d|             j                             d|            g }|j        r9|j        d         j        }|                     fd|j        D                        n|j        } fd|j        D             }t          |j        ||j         	                    |          || j
                   }|xj                             |          z  c_         j                            |j        |           | _         j                             d|| 	            j                             d
||                                 |            j                             d|| 	            j                             d||             j        j         _        dS )zaVisit a class definition node.

        Parameters:
            node: The node to visit.
        rr   rs   on_class_noder   c              3  z   K   | ]5}t          t          |j        d           |j        |j                  V  6dS )Fr1   parse_stringsrW   rX   N)r!   r   rL   rW   
end_lineno).0decorator_noderN   s     rD   	<genexpr>z)Visitor.visit_classdef.<locals>.<genexpr>  si         # 't|[`aaa)0,7       rF   c                <    g | ]}t          |j                   S r1   )r   rL   )r   baserN   s     rD   
<listcomp>z*Visitor.visit_classdef.<locals>.<listcomp>  s)    WWWD$T$,???WWWrF   )rv   rW   rX   rw   
decoratorsbasesruntimerx   ry   on_class_instance)rR   clsrt   r}   on_class_membersN)r0   r   decorator_listrW   extendr   r    rv   r   r\   rM   labelsdecorators_to_labelsrL   
set_memberrl   r1   )rN   rR   r   rW   r   class_s   `     rD   visit_classdefzVisitor.visit_classdef   s    	YT>>>_4tDDD ')
 	!(+2F     '+&9       [F XWWWDJWWWo))$//!))
 
 
 	22:>>>	6222]6NNN0ttTTT4   \&MMM/ddSSS|*rF   r   list[Decorator]set[str]c                    t                      }|D ]L}|j        }|t          v r!|                    t          |                    3|t          v r|t          |         z  }M|S )zBuild and return a set of labels based on decorators.

        Parameters:
            decorators: The decorators to check.

        Returns:
            A set of labels.
        )setcallable_pathbuiltin_decoratorsaddstdlib_decorators)rN   r   r   	decoratorr   s        rD   r   zVisitor.decorators_to_labels%  sm     # 	; 	;I%3M 222

-m<===="333+M::rF   functionr#   
str | Nonec                    |D ]y}	 |j                             dd          \  }}n# t          $ r Y .w xY w|dv o<||j        k    o1| j                            |j                                      d          }|r|c S zdS )a<  Check decorators to return the base property in case of setters and deleters.

        Parameters:
            decorators: The decorators to check.

        Returns:
            base_property: The property for which the setter/deleted is set.
            property_function: Either `"setter"` or `"deleter"`.
        .r_   >   setterdeleterr*   N)r   rsplit
ValueErrorpathrL   
get_memberrv   
has_labels)rN   r   r   r   r   prop_functionproperty_setter_or_deleters          rD   get_base_propertyzVisitor.get_base_property7  s     $ 	% 	%I&/&=&D&DS!&L&L#mm    !66 RHM)RL++HM::EEjQQ '
 * %$$$$%ts   %
22&ast.AsyncFunctionDef | ast.FunctionDefr   
set | Nonec                     j                             d|             j                             d|            |pt                      }g }d}|j        ry|j        d         j        }|j        D ]^}t          | j        d          }|t          ||j        |j                  }|	                    |           ||j
        t          v z  }_n|j        }|                     |          z  }d	|v rt          |j        dt          |j         j        
          |j        |j                             |           j                   }	|	xj        |z  c_         j                            |j        |	            j                             d||	             j                             d||	            dS t+           fdt-          |j                  D              }
t1          |j        ||j        |
t          |j         j        
          |                     |           j          j        	  	        }                     ||          }|r+ j        j        |j                 	                    |           n|rg j        j        |j                 }|dk    r"||_        |j                            d           n|dk    r!||_        |j                            d           n j                            |j        |            j        j        t@          j!        t@          j"        hv rE j        j        |j                 r. j        j        |j                 |_         j        j        |j        = |xj        |z  c_         j                             d||             j                             d||             j        j        t@          j"        u r:|j        dk    r1| _         #                    |            j        j$         _        dS dS dS )zHandle a function definition node.

        Parameters:
            node: The node to visit.
            labels: Labels to add to the data object.
        rr   rs   on_function_nodeFr   r   Nr   r*   r   rv   r[   
annotationrW   rX   rw   r   rx   ry   on_attribute_instancerR   attrrt   c                    g | ]Z\  }}}}t          ||t          |j                   t          |t                    r|nt          |j        d                    [S )r   Fr   )kindr   default)r%   r   rL   
isinstancer7   r   )r   rv   r   r   r   rN   s        rD   r   z+Visitor.handle_function.<locals>.<listcomp>  s     
 
 
 4D*dG 2:dlSSS!'3//`GG,WT\Y^___  
 
 
rF   )	rv   rW   rX   
parametersreturnsr   rw   r   r1   r   writabler   	deletableon_function_instance)rR   funcrt   rK   )%r0   r   r   r   rW   r   rL   r!   r   appendr   typing_overloadr   r   rv   r   r   r\   rM   r   r   r&   r   argsr#   r   	overloadsmembersr   r   r   r   r   MODULECLASSrl   r1   )rN   rR   r   r   overloadrW   r   decorator_valuer   	attributer   r   property_functionbase_propertys   `             rD   handle_functionzVisitor.handle_functionO  sP    	YT>>>/d$GGG355 
 	!(+2F"&"5 
G 
G"5nT\in"o"o"o"*%#)0,7  	
 !!),,,I3FF
G [F$++J777!Y.t|DLQQQ{/--d33 --  I &L##DIy999O  TyPT UUUO  !8t)[_ ```F  
 
 
 
 8Fdi7P7P
 
 


 o!'T\JJJ!))$//))<

 

 

 !22:xHH 	:L"8=188BBBB 	:'+|';DI'FM H,,'/$$((4444"i//(0%$((555L##DIx888| T[$*$===$,BXYaYfBg=%)\%;HM%J"L*8=96!]84PPP3$XUYZZZ<
**x}
/J/J#DLt$$$<.DLLL +*/J/JrF   ast.FunctionDefc                0    |                      |           dS )zdVisit a function definition node.

        Parameters:
            node: The node to visit.
        Nr   rm   s     rD   visit_functiondefzVisitor.visit_functiondef  s     	T"""""rF   ast.AsyncFunctionDefc                6    |                      |dh           dS )zkVisit an async function definition node.

        Parameters:
            node: The node to visit.
        async)r   Nr   rm   s     rD   visit_asyncfunctiondefzVisitor.visit_asyncfunctiondef  s%     	T7)44444rF   
ast.Importc                   |j         D ]}|j        r|j        n |j                            dd          d         }|j        p|                    dd          d         }|| j        j        |<   t          |||j        |j        | j	                   }| j        
                    ||           | j                            d|||            dS )zXVisit an import node.

        Parameters:
            node: The node to visit.
        r   r_   r   rW   rX   r   on_aliasaliasrR   rt   N)namesasnamerv   splitrL   importsr   rW   r   rM   r   r0   r   rN   rR   rv   
alias_path
alias_namer   s         rD   visit_importzVisitor.visit_import  s     J 	Q 	QD&*kQtysA7N7Nq7QJC
(8(8a(@(@(CJ/9DL ,{/ --  E L##J666O  5t4 PPPP	Q 	QrF   ast.ImportFromc                8   |j         D ]}|j        s$|j        dk    r|j        s| j        j        j        r.t          ||| j        j                  }|j        dk    r-|                    dd          }|                    dd          }n|j        p|j        }|| j        j	        |<   || j        j
         d| k    r]t          |||j        |j        | j                   }| j                            ||           | j                            d||| 	           d
S )z_Visit an "import from" node.

        Parameters:
            node: The node to visit.
        r_   *r   /z.* r   r   r   N)r   rg   levelr   rL   is_init_moduler   rv   replacer   r   r   rW   r   rM   r   r0   r   r   s         rD   visit_importfromzVisitor.visit_importfrom  sA    J 	U 	UD; 4:??4;?4<K^Km?
 -dD$,:MNNJyC'//S99
'//b99

![5DI
3=$Z0  1@@J@@@@;"o $ 11   ''
E:::$$Zu4t$TTT7	U 	UrF   ast.Assign | ast.AnnAssignr   str | Expr | Nonec           
        | j                             d||            | j                             d||            | j        }t                      }|j        t
          j        u r9	 t          |          }n# t          $ r Y dS w xY w|	                    d           n|j        t
          j
        u r	 t          |          }n# t          $ r Y dS w xY wt          |t                    r$|j        r|j        }|	                    d           n|j        r+|	                    d           |	                    d           nt|	                    d           n^|j        t
          j        u rK|j        dk    rdS 	 t%          |          }n# t          $ r Y dS w xY w|j        }|	                    d           |sdS t)          |j        | j        d	
          }	 |                     t-          |          d          }n# t.          t0          f$ r d}Y nw xY w|D ]}d|v r||j        v rt          |j        t4          j        t4          j        f          r=|j        |         }	t;          t<          t>                    5  ||	j         z  }|	j!        r	|s|	j!        }t;          t0                    5  |	j"        r	|s|	j"        }ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   tG          ||||j$        |j%        || j&                   }
|
xj         |z  c_         |'                    ||
           |dk    rPt;          t0                    5  d tQ          || j                  D             |_)        ddd           n# 1 swxY w Y   | j                             d||
|            | j                             d||
|            dS )zHandle an attribute (assignment) node.

        Parameters:
            node: The node to visit.
            annotation: A potential annotation.
        rr   rs   on_attribute_nodeNzmodule-attributezclass-attributezinstance-attributerK   Fr   TrP   r   r   __all__c                r    g | ]4}t          |t                    r|nt          |j        |j                   5S r   r   r7   r   rv   r1   r   rv   s     rD   r   z,Visitor.handle_attribute.<locals>.<listcomp>]  sN     & & &  !+4 5 5b8DIVZVa;b;b;b& & &rF   rx   ry   r   r   )*r0   r   rL   r   r   r   r   r   KeyErrorr   r   r   r   is_classvarslicer[   FUNCTIONrv   r   r1   r   r\   r   r   AttributeErrorr   re   IfExceptHandlerr   r   r   r   rw   r   r   rW   r   rM   r   r   exports)rN   rR   r   r1   r   r   r[   rw   rv   existing_memberr   s              rD   handle_attributezVisitor.handle_attribute  s1    	YT>>>0t4HHH;$+%%!$   JJ)****[DJ&&!$    *d++ 
1
0F 
1'-


,---- 1

,---

/0000 

/0000[DM)){j((*400   ]FJJ+,,, 	F#DJt|SXYYY	++HTNN4+HHII~. 	 	 	III	  )	a )	aD d{{v~%% dkCFC4E+FGG "(."624DEE D Do44F&0 > >$3$=	!.11 D D*5 Dj D)8)CJD D D D D D D D D D D D D D DD D D D D D D D D D D D D D D "%{/# --  I &dI...y  n--  & &$3D$,$G$G& & &FN              
 O  TyPT UUUO  !8t)[_ ````S)	a )	as   $A4 4
BB0C   
CC3F 
FF$G6 6HH5/K$K5KKKK	KK	K		%M::M>	M>	
ast.Assignc                0    |                      |           dS )z\Visit an assignment node.

        Parameters:
            node: The node to visit.
        N)r  rm   s     rD   visit_assignzVisitor.visit_assignd  s     	d#####rF   ast.AnnAssignc                d    |                      |t          |j        | j                             dS )zfVisit an annotated assignment node.

        Parameters:
            node: The node to visit.
        r   N)r  r   r   rL   rm   s     rD   visit_annassignzVisitor.visit_annassignl  s4     	d$7PTP\$]$]$]^^^^^rF   ast.AugAssignc                R   t          t                    5  |j        j        dk    o*| j        j        ot          |j        t          j	                  }|r<| j        j
                            d t          || j                  D                        ddd           dS # 1 swxY w Y   dS )zfVisit an augmented assignment node.

        Parameters:
            node: The node to visit.
        r   c                r    g | ]4}t          |t                    r|nt          |j        |j                   5S r   r   r   s     rD   r   z+Visitor.visit_augassign.<locals>.<listcomp>  sN         !+4 5 5b8DIVZVa;b;b;b  rF   N)r   r   targetidrL   	is_moduler   opre   Addr  r   r   )rN   rR   all_augments      rD   visit_augassignzVisitor.visit_augassignt  s     n%% 	 	)+ 1L*1tw00 
  $++ $3D$,$G$G    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A:BB #B ast.Ifc                    t          |j        t          j        t          j        f          r4t          |j        | j        d          }t          |          dv rd| _	        | 
                    |           d| _	        dS )zVVisit an "if" node.

        Parameters:
            node: The node to visit.
        N)r1   	log_level>   typing.TYPE_CHECKINGr   TF)r   r1   re   r$   ClassDefr   testrL   r7   rM   rl   )rN   rR   	conditions      rD   visit_ifzVisitor.visit_if  sv     dkCJ#=>> 	)*49T\UYZZZI9~~!JJJ$(!4   !rF   )NNNNN)r6   r7   r8   r'   r9   r7   r0   r   r1   r;   r2   r<   r3   r=   r4   r>   r5   r?   r@   rH   )rR   rS   rQ   rT   r@   rU   )r@   r$   )rR   rS   r@   rH   )rR   rp   r@   rH   )rR   r   r@   rH   )r   r   r@   r   )r   r   r   r#   r@   r   )N)rR   r   r   r   r@   rH   )rR   r   r@   rH   )rR   r   r@   rH   )rR   r   r@   rH   )rR   r   r@   rH   )rR   r   r   r   r@   rH   )rR   r  r@   rH   )rR   r	  r@   rH   )rR   r  r@   rH   )rR   r  r@   rH   )__name__
__module____qualname____doc__rK   r\   rC   rE   rl   r   r   r   r   r   r   r   r   r   r  r  r  r  r  __classcell__)rO   s   @rD   rB   rB   t   s         !%;?37377;:? :? :? :? :? :? :?x ?D 

 

 

 

 

 

# # # #K K K K   U U U U,,+ ,+ ,+ ,+\   $   0e/ e/ e/ e/ e/N# # # #5 5 5 5Q Q Q Q(!U !U !U !UL )-ea ea ea ea eaN$ $ $ $_ _ _ _   *" " " " " " " "rF   rB   )r6   r7   r8   r'   r9   r7   r0   r:   r1   r;   r2   r<   r3   r=   r4   r>   r5   r?   r@   r$   )>
__future__r   re   
contextlibr   typingr   r    _griffe.agents.nodes.assignmentsr   r   _griffe.agents.nodes.astr	   r
   r   _griffe.agents.nodes.docstringsr   _griffe.agents.nodes.exportsr   _griffe.agents.nodes.importsr   _griffe.agents.nodes.parametersr   _griffe.collectionsr   r   _griffe.enumerationsr   _griffe.exceptionsr   r   r   _griffe.expressionsr   r   r   r   r   r   _griffe.extensions.baser   r   _griffe.modelsr   r   r    r!   r"   r#   r$   r%   r&   pathlibr'   _griffe.docstrings.parsersr(   r)   r   r   r   rE   rB    rF   rD   <module>r5     s   # " " " " " 



       % % % % % % % % J J J J J J J J         
 : 9 9 9 9 9 8 8 8 8 8 8 = = = = = = : : : : : : B B B B B B B B % % % % % % T T T T T T T T T T                @ ? ? ? ? ? ? ? q q q q q q q q q q q q q q q q q q q q q q ,999999++++++ "   
 / ,, z"*J!7(0*'=$:)]   8$&BC %) 7;/3/3370 0 0 0 0 0f`" `" `" `" `" `" `" `" `" `"rF   