
    L-Ph!                    @   d Z ddlm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 ddlmZmZ ddlmZmZmZ dd	lmZm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  ddl!m"Z"m#Z#m$Z$m%Z% erddlm&Z&  ee          ZddZ'ddZ(d dZ)ddZ*d!dZ+ G d de          Z,dS )"z'Python source expertise for coverage.py    )annotationsN)TYPE_CHECKING)Iterable)env)CoverageExceptionNoSource)canonical_filenamerelative_filenamezip_location)isolate_module
join_regex)PythonParser)source_token_linessource_encoding)
CodeRegionFileReporter)code_regions)TArcTLineNoTMorfTSourceTokenLines)Coveragefilenamestrreturnbytesc                    t          | d          5 }|                                }ddd           n# 1 swxY w Y   |                    dd                              dd          S )zFRead the Python source text from `filename`.

    Returns bytes.

    rbNs   
   
   )openreadreplace)r   fsources      O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/python.pyread_python_sourcer'      s     
h		                >>'5))11%???s   266c                   t           j                            |           \  }}|dk    rt          j        rddg}n|g}|D ]J}||z   }t           j                            |          rt          |          } n't          |          }| nKt          d|  d          |	                    dd          }|
                    t          |          d          }|r|d	         d
k    r|d
z  }|S )z#Return the source code, as unicode..pyz.pywNzNo source for code: 'z'.       r#   
)ospathsplitextr   WINDOWSexistsr'   get_zip_bytesr   r#   decoder   )r   baseextextstry_filenamesource_bytesr%   s          r&   get_python_sourcer:   +   s     **ID#
e|||vu  = =cz7>>,'' 	-l;;LE %\22#E $ ;x;;;<<<  ''t44L  !>!>	JJF  &*$$$M    bytes | Nonec                    t          |           }|[|\  }}	 t          j        |          }n# t          j        $ r Y dS w xY w	 |                    |          }n# t
          $ r Y dS w xY w|S dS )zGet data from `filename` if it is a zip file path.

    Returns the bytestring data read from the zip file, or None if no zip file
    could be found or `filename` isn't in it.  The data returned will be
    an empty string if the file is empty.

    N)r   	zipimportzipimporterZipImportErrorget_dataOSError)r   zipfile_innerzipfileinnerzidatas         r&   r3   r3   N   s     !**M &	&w//BB' 	 	 	44		;;u%%DD 	 	 	44	4s    - A A A 
A('A(c                   |                      d          r| S |                      d          r_| dd         }t          j                            |          r|S t          j        r&|dz   }t          j                            |          r|S |S | S )zReturn the source filename for `filename`.

    Given a file name being traced, return the best guess as to the source
    file to attribute it to.

    r)   )z.pycz.pyoNr,   w)endswithr.   r/   r2   r   r1   )r   py_filenamepyw_filenames      r&   source_for_filerM   e   s      			+	,	, ssm7>>+&& 	; 	$&,Lw~~l++ $## Or;   morfr   c                    t          | d          r| j        r| j        }n/t          | t          j                  rt          d|  d          | }t          |          }|S )z6Get the source filename for the module-or-file `morf`.__file__zModule z has no file)hasattrrP   
isinstancetypes
ModuleTyper   rM   )rN   r   s     r&   source_for_morfrU      sn    tZ   T] =	D%*	+	+    <$ < < <===x((HOr;   c                       e Zd ZdZd-d. fd	Zd/dZd/dZed0d            Zd1dZ	d1dZ
d2dZd3dZd1dZd4dZd5dZ	 d-d6d"Zd7d#Zd/d$Zd8d&Zd9d(Zd:d*Zd;d,Z xZS )<PythonFileReporterz!Report support for a Python file.NrN   r   coverageCoverage | Noner   Nonec                (   || _         t          |          }|}d}| j         | j         j        j        rd}|rt	          |          }t                                          |           t          |d          ro|j        	                    dt          j                  }t          j                            |                              d          r|t          j        dz   z  }|dz  }nt          |          }|| _        d | _        d | _        d | _        d S )NTF__name__.z	__init__.__init__r)   )rX   rU   configrelative_filesr	   superr^   rQ   r\   r#   r.   sepr/   basename
startswithr
   relname_source_parser	_excluded)selfrN   rX   r   fnamecanonicalizename	__class__s          r&   r^   zPythonFileReporter.__init__   s    "4((=$}#2 %$ 	1&x00E4$$ 	/=((bf55Dw))44[AA ,++EMDD$X..D#',0r;   r   c                    d| j         dS )Nz<PythonFileReporter >)r   ri   s    r&   __repr__zPythonFileReporter.__repr__   s    8dm8888r;   c                    | j         S N)re   rp   s    r&   r
   z$PythonFileReporter.relative_filename   s
    |r;   r   c                    | j         J | j        Lt          | j        | j                             d                    | _        | j                                         | j        S )z&Lazily create a :class:`PythonParser`.Nexclude)r   ru   )rX   rg   r   r   _exclude_regexparse_sourcerp   s    r&   parserzPythonFileReporter.parser   sf     }(((<'44Y??  DL L%%'''|r;   set[TLineNo]c                    | j         j        S z2Return the line numbers of statements in the file.)rx   
statementsrp   s    r&   lineszPythonFileReporter.lines   s    {%%r;   c                    | j         j        S r{   )rx   excludedrp   s    r&   excluded_linesz!PythonFileReporter.excluded_lines   s    {##r;   r}   Iterable[TLineNo]c                6    | j                             |          S rs   )rx   translate_lines)ri   r}   s     r&   r   z"PythonFileReporter.translate_lines   s    {**5111r;   arcsIterable[TArc]	set[TArc]c                6    | j                             |          S rs   )rx   translate_arcs)ri   r   s     r&   r   z!PythonFileReporter.translate_arcs   s    {))$///r;   c                    | j         J | j                            t          | j         j        j        | j         j        j        z                       }|S rs   )rX   rx   lines_matchingr   r_   partial_listpartial_always_list)ri   	no_branchs     r&   no_branch_linesz"PythonFileReporter.no_branch_lines   sW    }(((K..$1-&:; 
 
	 r;   c                4    | j                                         S rs   )rx   r   rp   s    r&   r   zPythonFileReporter.arcs   s    {!!!r;   dict[TLineNo, int]c                4    | j                                         S rs   )rx   exit_countsrp   s    r&   r   zPythonFileReporter.exit_counts   s    {&&(((r;   startr   endexecuted_arcsIterable[TArc] | Nonec                8    | j                             ||          S rs   )rx   missing_arc_description)ri   r   r   r   s       r&   r   z*PythonFileReporter.missing_arc_description   s     {225#>>>r;   c                8    | j                             ||          S rs   )rx   arc_description)ri   r   r   s      r&   r   z"PythonFileReporter.arc_description   s    
 {**5#666r;   c                P    | j         t          | j                  | _         | j         S rs   )rf   r:   r   rp   s    r&   r%   zPythonFileReporter.source   s#    <,T];;DL|r;   boolc                    t           j                            | j                  \  }}|                    d          rdS |sdS dS )zDoes it seem like this file should contain Python?

        This is used to decide if a file reported as part of the execution of
        a program was really likely to have contained Python in the first
        place.

        r)   TF)r.   r/   r0   r   rd   )ri   _r6   s      r&   should_be_pythonz#PythonFileReporter.should_be_python   sL     !!$-003 >>%   	4 	4ur;   r   c                D    t          |                                           S rs   )r   r%   rp   s    r&   r   z%PythonFileReporter.source_token_lines  s    !$++--000r;   Iterable[CodeRegion]c                D    t          |                                           S rs   )r   r%   rp   s    r&   r   zPythonFileReporter.code_regions
  s    DKKMM***r;   Iterable[tuple[str, str]]c                
    ddgS )N)function	functions)classclasses rp   s    r&   code_region_kindsz$PythonFileReporter.code_region_kinds  s    % 
 	
r;   rs   )rN   r   rX   rY   r   rZ   )r   r   )r   r   )r   ry   )r}   r   r   ry   )r   r   r   r   )r   r   )r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   )r   r   )r   r   )r   r   )r\   
__module____qualname____doc__r^   rq   r
   propertyrx   r}   r   r   r   r   r   r   r   r   r%   r   r   r   r   __classcell__)rm   s   @r&   rW   rW      s       ++      69 9 9 9    	 	 	 X	& & & &$ $ $ $2 2 2 20 0 0 0   " " " ") ) ) ) 04	? ? ? ? ?7 7 7 7   
   (1 1 1 1+ + + +
 
 
 
 
 
 
 
r;   rW   )r   r   r   r   )r   r   r   r   )r   r   r   r<   )rN   r   r   r   )-r   
__future__r   os.pathr.   rS   r>   typingr   collections.abcr   rX   r   coverage.exceptionsr   r   coverage.filesr	   r
   r   coverage.miscr   r   coverage.parserr   coverage.phystokensr   r   coverage.pluginr   r   coverage.regionsr   coverage.typesr   r   r   r   r   r'   r:   r3   rM   rU   rW   r   r;   r&   <module>r      s	   . - " " " " " "                   $ $ $ $ $ $       ; ; ; ; ; ; ; ; N N N N N N N N N N 4 4 4 4 4 4 4 4 ( ( ( ( ( ( C C C C C C C C 4 4 4 4 4 4 4 4 ) ) ) ) ) ) B B B B B B B B B B B B "!!!!!!^B	@ 	@ 	@ 	@       F   .   :   @
 @
 @
 @
 @
 @
 @
 @
 @
 @
r;   