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

    Returns bytes.

    rbNs   
   
   )openreadreplace)r   fsource r$   U/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/coverage/python.pyread_python_source!   s   
r&   c                 C  s   t j| \}}|dkrtjrddg}n|g}|D ]}|| }t j|r+t|} nt|}|dur5 nqtd|  ddd|	dd	}|
t|d
}|rZ|d dkrZ|d7 }|S )z#Return the source code, as unicode..pyz.pywNzNo source for code: 'z'.z	no-source)slug       r!   
)ospathsplitextr   WINDOWSexistsr&   get_zip_bytesr   r!   decoder   )r   baseextextstry_filenamesource_bytesr#   r$   r$   r%   get_python_source-   s&   
r9   bytes | Nonec                 C  sh   t | }|dur2|\}}zt|}W n tjy   Y dS w z||}W |S  ty1   Y dS w 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datar$   r$   r%   r2   P   s   r2   c                 C  sZ   |  dr| S |  dr+| dd }tj|r|S tjr)|d }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.   r1   r   r0   )r   py_filenamepyw_filenamer$   r$   r%   source_for_fileg   s   

rI   morfr   c                 C  sD   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)hasattrrK   
isinstancetypes
ModuleTyper   rI   )rJ   r   r$   r$   r%   source_for_morf   s   rP   c                      s   e Zd ZdZdBdC fd	d
ZdDddZdDddZedEddZdFddZ	dGddZ
dFddZdHddZdId"d#ZdFd$d%ZdJd&d'ZdKd)d*Z	dBdLd0d1ZdMd2d3ZdDd4d5ZdNd7d8ZdOd:d;ZdPd=d>ZdQd@dAZ  ZS )RPythonFileReporterz!Report support for a Python file.NrJ   r   coverageCoverage | Noner   Nonec                   s   || _ t|}|}d}| j d ur| j jjrd}|rt|}t | t|drE|j	dt
j}t
j|dr@|t
jd 7 }|d7 }nt|}|| _d | _d | _d | _d S )NTF__name__.z	__init__.__init__r'   )rR   rP   configrelative_filesr   superrW   rL   rU   r!   r-   sepr.   basename
startswithr	   relname_source_parser	_excluded)selfrJ   rR   r   fnamecanonicalizename	__class__r$   r%   rW      s(   




zPythonFileReporter.__init__r   c                 C  s   d| j dS )Nz<PythonFileReporter >)r   rb   r$   r$   r%   __repr__      zPythonFileReporter.__repr__c                 C  s   | j S N)r^   ri   r$   r$   r%   r	      s   z$PythonFileReporter.relative_filenamer   c                 C  s@   | j dusJ | jdu rt| j| j dd| _| j  | jS )z&Lazily create a :class:`PythonParser`.Nexclude)r   rm   )rR   r`   r   r   _exclude_regexparse_sourceri   r$   r$   r%   parser   s   


zPythonFileReporter.parserset[TLineNo]c                 C     | j jS z2Return the line numbers of statements in the file.)rp   
statementsri   r$   r$   r%   lines      zPythonFileReporter.linesdict[TLineNo, TLineNo]c                 C  rr   )z>A map of line numbers to first-line in a multi-line statement.)rp   multiline_mapri   r$   r$   r%   rx      rv   z PythonFileReporter.multiline_mapc                 C  rr   rs   )rp   excludedri   r$   r$   r%   excluded_lines   rv   z!PythonFileReporter.excluded_linesru   Iterable[TLineNo]c                 C     | j |S rl   )rp   translate_lines)rb   ru   r$   r$   r%   r}         z"PythonFileReporter.translate_linesarcsIterable[TArc]	set[TArc]c                 C  r|   rl   )rp   translate_arcs)rb   r   r$   r$   r%   r      r~   z!PythonFileReporter.translate_arcsc                 C  s2   | j d usJ | jt| j jj| j jj }|S rl   )rR   rp   lines_matchingr   rX   partial_listpartial_always_list)rb   	no_branchr$   r$   r%   no_branch_lines   s
   z"PythonFileReporter.no_branch_linesc                 C  
   | j  S rl   )rp   r   ri   r$   r$   r%   r         
zPythonFileReporter.arcsdict[TLineNo, int]c                 C  r   rl   )rp   exit_countsri   r$   r$   r%   r      r   zPythonFileReporter.exit_countsstartr   endexecuted_arcsIterable[TArc] | Nonec                 C     | j ||S rl   )rp   missing_arc_description)rb   r   r   r   r$   r$   r%   r      s   z*PythonFileReporter.missing_arc_descriptionc                 C  r   rl   )rp   arc_description)rb   r   r   r$   r$   r%   r      rk   z"PythonFileReporter.arc_descriptionc                 C  s   | j d u rt| j| _ | j S rl   )r_   r9   r   ri   r$   r$   r%   r#      s   
zPythonFileReporter.sourceboolc                 C  s,   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.   r/   r   r]   )rb   _r5   r$   r$   r%   should_be_python   s   	
z#PythonFileReporter.should_be_pythonr   c                 C     t |  S rl   )r   r#   ri   r$   r$   r%   r     r~   z%PythonFileReporter.source_token_linesIterable[CodeRegion]c                 C  r   rl   )r   r#   ri   r$   r$   r%   r   	  r~   zPythonFileReporter.code_regionsIterable[tuple[str, str]]c                 C  s   ddgS )N)function	functions)classclassesr$   ri   r$   r$   r%   code_region_kinds  s   z$PythonFileReporter.code_region_kindsrl   )rJ   r   rR   rS   r   rT   )r   r   )r   r   )r   rq   )r   rw   )ru   r{   r   rq   )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   )rU   
__module____qualname____doc__rW   rj   r	   propertyrp   ru   rx   rz   r}   r   r   r   r   r   r   r#   r   r   r   r   __classcell__r$   r$   rf   r%   rQ      s.    














rQ   )r   r   r   r   )r   r   r   r   )r   r   r   r:   )rJ   r   r   r   ).r   
__future__r   os.pathr-   rN   r;   collections.abcr   typingr   rR   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&   r9   r2   rI   rP   rQ   r$   r$   r$   r%   <module>   s4   


#

