o
    ·›îYf  ã                   @   sÖ   d Z ddlZddlZddlZddlmZmZ ddlm	Z	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 eeƒZe	d	d
�dd„ ƒZe	dd
�dd„ ƒZe	dd
�dd„ ƒZdd„ ZG dd„ deƒZdS )z'Python source expertise for coverage.pyé    N)ÚenvÚfiles)ÚcontractÚ	expensiveÚisolate_moduleÚ
join_regex)ÚCoverageExceptionÚNoSource)ÚPythonParser)Úsource_token_linesÚsource_encoding)ÚFileReporterÚbytes©Úreturnsc                 C   sT   t | dƒ�}| ¡ }W d  ƒ n1 sw   Y  tjr t|ƒ}| dd¡ dd¡S )zFRead the Python source text from `filename`.

    Returns bytes.

    ÚrbNs   
ó   
ó   )ÚopenÚreadr   Ú
IRONPYTHONr   Úreplace)ÚfilenameÚfÚsource© r   úA/var/www/html/env/lib/python3.10/site-packages/coverage/python.pyÚread_python_source   s   
ÿr   Úunicodec                 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d| f }|d7 }t|ƒ‚| 	dd¡}| 
t|ƒd¡}|r]|d	 d
kr]|d
7 }|S )z#Return the source code, as unicode.ú.pyz.pywNzNo source for code: '%s'.
z*Aborting report output, consider using -i.ó   ó    r   éÿÿÿÿÚ
)ÚosÚpathÚsplitextr   ÚWINDOWSÚexistsr   Úget_zip_bytesr	   r   Údecoder   )r   ÚbaseÚextÚextsÚtry_filenamer   Úexc_msgr   r   r   Úget_python_source%   s*   
ÿ
r0   z
bytes|Nonec              	   C   sœ   dt j dt j dt j g}|D ];}|| v rK|  |¡}zt |d |dd…  ¡}W n
 tjy4   Y qw z| |d ¡}W |  S  tyJ   Y qw qdS )zûGet 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.

    z.zipz.eggz.pexr   Nr"   é   )r$   ÚsepÚsplitÚ	zipimportÚzipimporterÚZipImportErrorÚget_dataÚIOError)r   ÚmarkersÚmarkerÚpartsÚziÚdatar   r   r   r)   J   s"   	
ÿþÿør)   c                 C   st   |   d¡r| S |   d¡r+| dd… }tj |¡r|S tjr)|d }tj |¡r)|S |S |   d¡r8| dd… d S | S )z•Return the source file 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"   Úwz	$py.classi÷ÿÿÿ)Úendswithr$   r%   r(   r   r'   )r   Úpy_filenameÚpyw_filenamer   r   r   Úsource_for_filec   s   


rB   c                       s¸   e Zd ZdZd#‡ fdd„	Zdd„ Zedd�d	d
„ ƒZedd„ ƒZ	dd„ Z
dd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZd#dd„Zedd�dd„ ƒZdd „ Zd!d"„ Z‡  ZS )$ÚPythonFileReporterz!Report support for a Python file.Nc                    sÔ   || _ t|dƒr|j}nt|tjƒrtd |¡ƒ‚|}tt	 
|¡ƒ}tt| ƒ t	 |¡¡ t|dƒrT|j dtj¡}tj |¡ d¡rJ|tjd 7 }|d7 }t	 
|¡}nt	 |¡}|| _d | _d | _d | _d | _d S )NÚ__file__zModule {0} has no fileÚ__name__Ú.z	__init__.Ú__init__r   )ÚcoverageÚhasattrrD   Ú
isinstanceÚtypesÚ
ModuleTyper   ÚformatrB   r   Úunicode_filenameÚsuperrC   rG   Úcanonical_filenamerE   r   r$   r2   r%   ÚbasenameÚ
startswithÚrelative_filenameÚrelnameÚ_sourceÚ_parserÚ_statementsÚ	_excluded)ÚselfÚmorfrH   r   Úname©Ú	__class__r   r   rG   ‡   s(   



zPythonFileReporter.__init__c                 C   s   d  | j¡S )Nz<PythonFileReporter {0!r}>)rM   r   ©rY   r   r   r   Ú__repr__¦   ó   zPythonFileReporter.__repr__r   r   c                 C   s   | j S ©N)rT   r^   r   r   r   rS   ©   s   z$PythonFileReporter.relative_filenamec                 C   s2   | j du rt| j| j d¡d�| _ | j  ¡  | j S )z&Lazily create a :class:`PythonParser`.NÚexclude)r   rb   )rV   r
   r   rH   Ú_exclude_regexÚparse_sourcer^   r   r   r   Úparser­   s   

þ
zPythonFileReporter.parserc                 C   ó   | j jS ©z2Return the line numbers of statements in the file.)re   Ú
statementsr^   r   r   r   Úlines¸   ó   zPythonFileReporter.linesc                 C   rf   rg   )re   Úexcludedr^   r   r   r   Úexcluded_lines¼   rj   z!PythonFileReporter.excluded_linesc                 C   ó   | j  |¡S ra   )re   Útranslate_lines)rY   ri   r   r   r   rn   À   r`   z"PythonFileReporter.translate_linesc                 C   rm   ra   )re   Útranslate_arcs)rY   Úarcsr   r   r   ro   Ã   r`   z!PythonFileReporter.translate_arcsc                 C   s&   | j  t| jjjƒt| jjjƒ¡}|S ra   )re   Úlines_matchingr   rH   ÚconfigÚpartial_listÚpartial_always_list)rY   Ú	no_branchr   r   r   Úno_branch_linesÆ   s
   þz"PythonFileReporter.no_branch_linesc                 C   ó
   | j  ¡ S ra   )re   rp   r^   r   r   r   rp   Î   ó   
zPythonFileReporter.arcsc                 C   rw   ra   )re   Úexit_countsr^   r   r   r   ry   Ò   rx   zPythonFileReporter.exit_countsc                 C   s   | j  |||¡S ra   )re   Úmissing_arc_description)rY   ÚstartÚendÚexecuted_arcsr   r   r   rz   Ö   s   z*PythonFileReporter.missing_arc_descriptionc                 C   s   | j d u rt| jƒ| _ | j S ra   )rU   r0   r   r^   r   r   r   r   Ù   s   
zPythonFileReporter.sourcec                 C   s,   t j | j¡\}}| d¡rdS |sdS dS )zäDoes 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   rR   )rY   Ú_r,   r   r   r   Úshould_be_pythonß   s   	
z#PythonFileReporter.should_be_pythonc                 C   s   t |  ¡ ƒS ra   )r   r   r^   r   r   r   r   ó   r`   z%PythonFileReporter.source_token_linesra   )rE   Ú
__module__Ú__qualname__Ú__doc__rG   r_   r   rS   Úpropertyre   ri   rl   rn   ro   r   rv   rp   ry   rz   r   r   r   Ú__classcell__r   r   r\   r   rC   „   s.    







rC   )r‚   Úos.pathr$   rK   r4   rH   r   r   Úcoverage.miscr   r   r   r   r   r	   Úcoverage.parserr
   Úcoverage.phystokensr   r   Úcoverage.pluginr   r   r0   r)   rB   rC   r   r   r   r   Ú<module>   s&   

$
!