Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/Cython/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/Cython/__pycache__/Coverage.cpython-37.pyc

B

Z��ZM0�@s�dZddlmZddlZddlZddlZddlmZddl	m
Z
mZmZddl
mZddlmZmZmZdd	lmZd
d�Zdd
�ZGdd�de
�ZGdd�de�ZGdd�de�Zdd�ZdS)zv
A Cython plugin for coverage.py

Requires the coverage package at least in version 4.0 (which added the plugin API).
�)�absolute_importN)�defaultdict)�CoveragePlugin�
FileTracer�FileReporter)�canonical_filename�)�find_root_package_dir�is_package_dir�open_source_file)�__version__cCs<tj�|d�r|d}ntj�|d�r4|d}nd}|S)Nz.cz.cpp)�os�path�exists)�	base_path�c_file�r�B/opt/alt/python37/lib64/python3.7/site-packages/Cython/Coverage.py�_find_c_sources

rcCs�tj�|�}|�d�rPtj�|�sPtj�tj�|�|�}tj�|�rPtj�|�}tj�|�s�x8tjD].}tj�tj�||��}tj�|�rdt	|�SqdWt	|�S)Nz.pxi)
r
r�abspath�endswithr�join�dirname�sys�realpathr)Z	main_file�	file_path�abs_pathZ
pxi_file_path�sys_pathZ	test_pathrrr�_find_dep_file_path!src@sHeZdZdZdZdZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�PluginNcCs
dtfgS)NzCython version)r)�selfrrr�sys_info9szPlugin.sys_infocCs�|�d�s|�d�rdSd}}ttj�|��}|jrN||jkrN|j|d}|dkrx|�|�\}}|sldS|�||�|jdkr�i|_t	||||j|j�S)zR
        Try to find a C source file for a file path found by the tracer.
        �<zmemory:Nr)
�
startswithrr
rr�_c_files_map�_find_source_files�_parse_lines�_file_path_map�CythonModuleTracer)r �filenamer�py_filerrr�file_tracer<s
zPlugin.file_tracercCsrttj�|��}|jr2||jkr2|j|\}}}n2|�|�\}}|sHdS|�||�\}}|dkrddSt||||�S)N)rr
rrr$r%r&�CythonModuleReporter)r r)r�
rel_file_path�code�_rrr�
file_reporterXszPlugin.file_reporterc	Cs�tj�|�\}}|��}|dkr"n�|dkrPt�d|tj�}|r�|d|���}nl|dkr~t�d|tj�}|r�|d|���}n>|dkr�|�tj�	|�|�||j
kr�|j
|ddfSndS|d	kr�|nt|�}|dk�r.t�
|�}tj�||��tjj�}t|�d
k�r.tj�tj�	|�d�|��}t|�}d}	|�r�tj�|�dd}	tj�|	��s^d}	y.t|d
��}
d|
�d�k�r�dSWdQRXWnttfk
�r�d}YnX||	fS)N)z.pyz.pyxz.pxdz.cz.cppz.pydz[.]cp[0-9]+-win[_a-z0-9]*$z.soz&[.](?:cpython|pypy)-[0-9]+[-_a-z0-9]*$z.pxir)NN)z.cz.cppr�.z.py�rbs/* Generated by Cython �)r
r�splitext�lower�re�search�I�start�_find_c_source_filesrr$rr	Zuncached�relpath�split�sep�lenrr�open�read�IOError�OSError)r r)�basename�extZplatform_suffixrZpackage_rootZpackage_pathZ
test_basepathZpy_source_file�frrrr%ksH



zPlugin._find_source_filescCs�tj�|�sdStjj}xNt�|�D]@}||�d��}|dkr$|�tj�||�|�||jkr$dSq$Wt	|�r�|�
tj�|�|�dS)z�
        Desperately parse all C files in the directory or its package parents
        (not re-descending) to find the (included) source file in one of them.
        Nr)z.cz.cpp)r
r�isdirr4�listdirr5r&rr$r
r:r)r Zdir_path�source_filer4r)rDrrrr:�s
zPlugin._find_c_source_filesc	Csv|jdkri|_||jkr&|j|}n�t�d�j}t�d�j}t�d�j}t�d�j}tt�}t�}t|���}	t|	�}	x�|	D]|}
||
�}|s�q||�	�\}}
|�
|�t|
�}
xJ|	D]B}||�}|r�|�d��
�}||�r�P||||
<Pq�||�r�Pq�Wq|WWdQRX||j|<|jdk�r"i|_x0|��D]$\}}t||�}|||f|j|<�q,W||jk�rddS|j|dd�S)z�
        Parse a Cython generated C/C++ source file and find the executable lines.
        Each executable line starts with a comment header that states source file
        and line number, as well as the surrounding range of source code lines.
        Nz */[*] +"(.*)":([0-9]+)$z *[*] (.*) # <<<<<<+$z *[*]/$zX\s*c(?:type)?def\s+(?:(?:public|external)\s+)?(?:struct|union|enum|class)(\s+[^:]+|)\s*:r)NN)�_parsed_c_filesr6�compile�matchr�dict�setr?�iter�groups�add�int�group�rstripr$�itemsr)r rZ
sourcefileZ
code_linesZmatch_source_path_lineZmatch_current_code_lineZmatch_comment_endZnot_executable�	filenames�lines�linerKr)�linenoZcomment_line�	code_liner.rrrrr&�sN







zPlugin._parse_lines)�__name__�
__module__�__qualname__r'r$rIr!r+r0r%r:r&rrrrr1s2rcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)r(zA
    Find the Python/Cython source file for a Cython module.
    cs0tt|���||_||_||_||_||_dS)N)�superr(�__init__�module_filer*rr$r')r r_r*rZc_files_mapZ
file_path_map)�	__class__rrr^�szCythonModuleTracer.__init__cCsdS)NTr)r rrr�has_dynamic_source_filename�sz.CythonModuleTracer.has_dynamic_source_filenamecCs�|jj}y
|j|Stk
r&YnXt||�}|jr^|dd���dkr^|j|j|<|jS|jdk	slt�||jkr�|j	|df|j|<||j|<|S)zR
        Determine source file path.  Called by the function call tracer.
        ���Nz.py)
�f_code�co_filenamer'�KeyErrorrr*r5r$�AssertionErrorr)r r)�framerHrrrr�dynamic_source_filename�s



z*CythonModuleTracer.dynamic_source_filename)rZr[r\�__doc__r^rarh�
__classcell__rr)r`rr(�sr(cs@eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�Z	S)r,zP
    Provide detailed trace information for one source file to coverage.py.
    cs&tt|��|�||_||_||_dS)N)r]r,r^�namer�_code)r rrHr-r.)r`rrr^szCythonModuleReporter.__init__cCs
t|j�S)zJ
        Return set of line numbers that are possibly executable.
        )rMrl)r rrrrVszCythonModuleReporter.linesccsTd}xJt|j���D]8\}}x||kr6gV|d7}qWd|fgV|d7}qWdS)Nr�txt)�sortedrlrT)r �current_lineZline_norYrrr�_iter_source_tokenss
z(CythonModuleReporter._iter_source_tokensc	CsFtj�|j�r*t|j��
}|��SQRXnd�dd�|��D��SdS)zA
        Return the source code of the file as a string.
        N�
css"|]}|r|ddndVqdS)rr�Nr)�.0�tokensrrr�	<genexpr>1sz.CythonModuleReporter.source.<locals>.<genexpr>)r
rrr)rr@rrp)r rErrr�source(szCythonModuleReporter.sourcec	cshtj�|j�rFt|j��&}x|D]}d|�d�fgVq WWdQRXnx|��D]}d|fgVqPWdS)z6
        Iterate over the source code tokens.
        rmrqN)r
rrr)rrSrp)r rErWrrr�source_token_lines4s
"z'CythonModuleReporter.source_token_lines)
rZr[r\rir^rVrprvrwrjrr)r`rr,s	r,cCs|�t��dS)N)Zadd_file_tracerr)Zreg�optionsrrr�
coverage_initAsry)ri�
__future__rr6�os.pathr
r�collectionsrZcoverage.pluginrrrZcoverage.filesrZUtilsr	r
rrrrrrrr(r,ryrrrr�<module>s 
9&2