Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/Cython/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/Cython/__pycache__/Coverage.cpython-35.opt-1.pyc



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__cCsPtjj|d�r#|d}n)tjj|d�rF|d}nd}|S)Nz.cz.cpp)�os�path�exists)�	base_path�c_file�r�B/opt/alt/python35/lib64/python3.5/site-packages/Cython/Coverage.py�_find_c_sources

rcCs�tjj|�}|jd�rytjj|�rytjjtjj|�|�}tjj|�rytjj|�}tjj|�s�xNtjD]C}tjjtjj||��}tjj|�r�t	|�Sq�Wt	|�S)Nz.pxi)
r
r�abspath�endswithr�join�dirname�sys�realpathr)Z	main_fileZ	file_path�abs_pathZ
pxi_file_pathZsys_pathZ	test_pathrrr�_find_dep_file_path!s"!!rc@sjeZdZdZdZdZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�PluginNcCs
dtfgS)NzCython version)r)�selfrrr�sys_info9szPlugin.sys_infocCs�|jd�s|jd�r"dSd}}ttjj|��}|jrm||jkrm|j|d}|dkr�|j|�\}}|s�dS|j||�|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_tracercCs�ttjj|��}|jrI||jkrI|j|\}}}nG|j|�\}}|shdS|j||�\}}|dkr�dSt||||�S)N)rr
rrr"r#r$�CythonModuleReporter)rr'r�
rel_file_path�code�_rrr�
file_reporterXszPlugin.file_reportercCsPtjj|�\}}|j�}|dkr3n�|dkrvtjd|tj�}|r|d|j��}n�|dkr�tjd	|tj�}|r|d|j��}nS|d
kr|jtjj	|�|�||j
kr|j
|ddfSndS|dkr|n	t|�}|dkr�tj
|�}tjj||�jtjj�}t|�dkr�tjjtjj	|�d
j|��}t|�}d}	|rFtjj|�dd}	tjj|	�s�d}	y6t|d�� }
d|
jd�krdSWdQRXWnttfk
rEd}YnX||	fS)N�.py�.pyx�.pxd�.c�.cppz.pydz[.]cp[0-9]+-win[_a-z0-9]*$z.soz&[.](?:cpython|pypy)-[0-9]+[-_a-z0-9]*$z.pxirr�.�rbs/* Generated by Cython �)r/r0r1r2r3)NN)r2r3)NN)r
r�splitext�lower�re�search�I�start�_find_c_source_filesrr"rr	Zuncached�relpath�split�sep�lenrr�open�read�IOError�OSError)rr'�basename�extZplatform_suffixrZpackage_rootZpackage_pathZ
test_basepathZpy_source_file�frrrr#ksH$*zPlugin._find_source_filescCs�tjj|�sdStjj}xktj|�D]Z}||�dj�}|dkr2|jtjj||�|�||jkr2dSq2Wt	|�r�|j
tjj|�|�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�.c�.cpp)rIrJ)r
r�isdirr7�listdirr8r$rr"r
r=r)rZdir_path�source_filer7r'rGrrrr=�szPlugin._find_c_source_filescCs�|jdkri|_||jkr7|j|}nAtjd�j}tjd�j}tjd�j}tjd�j}tt�}t�}t|���}	t|	�}	x�|	D]�}
||
�}|s�q�|j	�\}}
|j
|�t|
�}
xa|	D]Y}||�}|rO|jd�j
�}||�r=P||||
<Pq||�rPqWq�WWdQRX||j|<|jdkr�i|_x?|j�D]1\}}t||�}|||f|j|<q�W||jkr�d	S|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�)N)NN)�_parsed_c_filesr9�compile�matchr�dict�setrB�iter�groups�add�int�group�rstripr"�itemsr)rrZ
sourcefileZ
code_linesZmatch_source_path_lineZmatch_current_code_lineZmatch_comment_endZnot_executable�	filenames�lines�linerQr'�linenoZcomment_line�	code_liner,rrrrr$�sN		



	zPlugin._parse_lines)�__name__�
__module__�__qualname__r%r"rOrr)r.r#r=r$rrrrr1s2rcs@eZdZdZ�fdd�Zdd�Zdd�Z�S)r&zA
    Find the Python/Cython source file for a Cython module.
    csDtt|�j�||_||_||_||_||_dS)N)�superr&�__init__�module_filer(rr"r%)rrer(rZc_files_mapZ
file_path_map)�	__class__rrrd�s				zCythonModuleTracer.__init__cCsdS)NTr)rrrr�has_dynamic_source_filename�sz.CythonModuleTracer.has_dynamic_source_filenamecCs�|jj}y|j|SWntk
r/YnXt||�}|jr{|dd�j�dkr{|j|j|<|jS||jkr�|j|df|j|<||j|<|S)zR
        Determine source file path.  Called by the function call tracer.
        �Nz.py���)	�f_code�co_filenamer%�KeyErrorrr(r8r"r)rr'�framerMrrrr�dynamic_source_filename�s
%
z*CythonModuleTracer.dynamic_source_filename)r`rarb�__doc__rdrgrnrr)rfrr&�sr&csXeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�S)r*zP
    Provide detailed trace information for one source file to coverage.py.
    cs5tt|�j|�||_||_||_dS)N)rcr*rd�namer�_code)rrrMr+r,)rfrrrds		zCythonModuleReporter.__init__cCs
t|j�S)zJ
        Return set of line numbers that are possibly executable.
        )rSrq)rrrrr\szCythonModuleReporter.linesccsjd}x]t|jj��D]F\}}x||krIgV|d7}q+Wd|fgV|d7}qWdS)Nr�txt)�sortedrqrZ)rZcurrent_lineZline_nor_rrr�_iter_source_tokenss"z(CythonModuleReporter._iter_source_tokensc	Cs_tjj|j�r;t|j��}|j�SWdQRXn djdd�|j�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'rrCrrt)rrHrrr�source(s	zCythonModuleReporter.sourceccs�tjj|j�rYt|j��/}x%|D]}d|jd�fgVq.WWdQRXn%x"|j�D]}d|fgVqfWdS)z6
        Iterate over the source code tokens.
        rrruN)r
rrr'rrYrt)rrHr]rrr�source_token_lines4s
%z'CythonModuleReporter.source_token_lines)	r`rarbrordr\rtrzr{rr)rfrr*s	r*cCs|jt��dS)N)Zadd_file_tracerr)Zreg�optionsrrr�
coverage_initAsr})roZ
__future__rr9Zos.pathr
r�collectionsrZcoverage.pluginrrrZcoverage.filesrZUtilsr	r
rrvrrrrr&r*r}rrrr�<module>s
�&2