
    L-Ph                        d Z ddlmZ ddlZddlZddlmZ ddlmZ ej	         G d d                      Z
 G d d	          ZddZdS )z*Find functions and classes in Python code.    )annotationsN)cast)
CodeRegionc                  2    e Zd ZU dZded<   ded<   ded<   dS )Contextz0The nested named context of a function or class.strnamekindzset[int]linesN)__name__
__module____qualname____doc____annotations__     P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/regions.pyr   r      s1         ::IIIIIIOOOOOr   r   c                  J    e Zd ZdZddZddZddZddZddZddZ	ddZ
dS )RegionFinderzAn ast visitor that will find and track regions of code.

    Functions and classes are tracked by name. Results are in the .regions
    attribute.

    returnNonec                "    g | _         g | _        d S N)regionscontextselfs    r   __init__zRegionFinder.__init__   s    )+&(r   sourcer   c                T    |                      t          j        |                     dS )zCParse `source` and walk the ast to populate the .regions attribute.N)handle_nodeastparse)r   r   s     r   parse_sourcezRegionFinder.parse_source#   s&    6**+++++r   c                J    d                     d | j        D                       S )z6Get the current fully qualified name we're processing..c              3  $   K   | ]}|j         V  d S r   )r	   ).0cs     r   	<genexpr>z,RegionFinder.fq_node_name.<locals>.<genexpr>)   s$      551555555r   )joinr   r   s    r   fq_node_namezRegionFinder.fq_node_name'   s%    xx55555555r   nodeast.ASTc                   t          |t          j        t          j        f          r|                     |           dS t          |t          j                  r|                     |           dS |                     |           dS )zRecursively handle any node.N)
isinstancer"   FunctionDefAsyncFunctionDefhandle_FunctionDefClassDefhandle_ClassDefhandle_node_body)r   r-   s     r   r!   zRegionFinder.handle_node+   s    dS_c.BCDD 	(##D)))))cl++ 	(  &&&&&!!$'''''r   c                X    t          |dd          D ]}|                     |           dS )z9Recursively handle the nodes in this node's body, if any.bodyr   N)getattrr!   )r   r-   	body_nodes      r   r6   zRegionFinder.handle_node_body4   s>     vr22 	( 	(IY''''	( 	(r   &ast.FunctionDef | ast.AsyncFunctionDefc           
        t          t          |j        d         j        t	          t
          |j        d         j                  dz                       }| j        r1| j        d         j        dk    r| j        d         xj	        |z  c_	        t          | j                  D ]}|j        dk    r|xj	        |z  c_	         n | j                            t          |j        d|                     | j                            t          d|                                 |j        |                     |                     |           | j                                         dS )z Called for `def` or `async def`.r      classfunctionr
   r	   startr   N)setranger8   linenor   int
end_linenor   r
   r   reversedappendr   r	   r   r   r,   r6   popr   r-   r   ancestors       r   r3   zRegionFinder.handle_FunctionDef9   sP   E$)A,-tC29Q/R/RUV/VWWXX< 	,DL,1W<<L""e+"" .. 	 	H}
**%' + 	GDIz5AABBB&&((k	  	
 	
 	
 	d###r   ast.ClassDefc                   t                      }| j                            t          |j        d|                     | j                            t          d|                                 |j        |                     | 	                    |           | j        
                                 t          | j                  D ]}|j        dk    r|xj        |z  c_        dS )zCalled for `class`.r?   rA   N)rC   r   rI   r   r	   r   r   r,   rE   r6   rJ   rH   r
   r   rK   s       r   r5   zRegionFinder.handle_ClassDefP   s    
 %%GDIw>>???&&((k	  	
 	
 	
 	d### .. 	( 	(H}''%'	( 	(r   N)r   r   )r   r   r   r   )r   r   )r-   r.   r   r   )r-   r;   r   r   )r-   rM   r   r   )r   r   r   r   r   r$   r,   r!   r6   r3   r5   r   r   r   r   r      s         ) ) ) ), , , ,6 6 6 6( ( ( (( ( ( (
   .( ( ( ( ( (r   r   r   r   r   list[CodeRegion]c                V    t                      }|                    |            |j        S )a]  Find function and class regions in source code.

    Analyzes the code in `source`, and returns a list of :class:`CodeRegion`
    objects describing functions and classes as regions of the code::

        [
            CodeRegion(kind="function", name="func1", start=8, lines={10, 11, 12}),
            CodeRegion(kind="function", name="MyClass.method", start=30, lines={34, 35, 36}),
            CodeRegion(kind="class", name="MyClass", start=25, lines={34, 35, 36}),
        ]

    The line numbers will include comments and blank lines.  Later processing
    will need to ignore those lines as needed.

    Nested functions and classes are excluded from their enclosing region.  No
    line should be reported as being part of more than one function, or more
    than one class.  Lines in methods are reported as being in a function and
    in a class.

    )r   r$   r   )r   rfs     r   code_regionsrR   g   s'    * 
BOOF:r   )r   r   r   rO   )r   
__future__r   r"   dataclassestypingr   coverage.pluginr   	dataclassr   r   rR   r   r   r   <module>rX      s    1 0 " " " " " " 



           & & & & & &        L( L( L( L( L( L( L( L(^     r   