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.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_file�	file_path�abs_pathZ
pxi_file_path�sys_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)r r)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 �)r1r2r3r4r5)NN)r4r5)NN)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�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)rKrL)r
r�isdirr9�listdirr:r&rr$r
r?r)r Zdir_path�source_filer9r)rIrrrr?�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_filesr;�compile�matchr�dict�setrD�iter�groups�add�int�group�rstripr$�itemsr)r rZ
sourcefileZ
code_linesZmatch_source_path_lineZmatch_current_code_lineZmatch_comment_endZnot_executable�	filenames�lines�linerSr)�linenoZcomment_line�	code_liner.rrrrr&�sN		



	zPlugin._parse_lines)�__name__�
__module__�__qualname__r'r$rQr!r+r0r%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')r rgr*rZc_files_mapZ
file_path_map)�	__class__rrrf�s				zCythonModuleTracer.__init__cCsdS)NTr)r rrr�has_dynamic_source_filename�sz.CythonModuleTracer.has_dynamic_source_filenamecCs�|jj}y|j|SWntk
r/YnXt||�}|jr{|dd�j�dkr{|j|j|<|jS|jdk	s�t�||jkr�|j	|df|j|<||j|<|S)zR
        Determine source file path.  Called by the function call tracer.
        �Nz.py���)
�f_code�co_filenamer'�KeyErrorrr*r:r$�AssertionErrorr)r r)�framerOrrrr�dynamic_source_filename�s
%
z*CythonModuleTracer.dynamic_source_filename)rbrcrd�__doc__rfrirqrr)rhrr(�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)rer,rf�namer�_code)r rrOr-r.)rhrrrfs		zCythonModuleReporter.__init__cCs
t|j�S)zJ
        Return set of line numbers that are possibly executable.
        )rUrt)r rrrr^szCythonModuleReporter.linesccsjd}x]t|jj��D]F\}}x||krIgV|d7}q+Wd|fgV|d7}qWdS)Nr�txt)�sortedrtr\)r �current_lineZline_norarrr�_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)rrErrx)r rJrrr�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.
        ruryN)r
rrr)rr[rx)r rJr_rrr�source_token_lines4s
%z'CythonModuleReporter.source_token_lines)	rbrcrdrrrfr^rxr~rrr)rhrr,s	r,cCs|jt��dS)N)Zadd_file_tracerr)Zreg�optionsrrr�
coverage_initAsr�)rr�
__future__rr;�os.pathr
r�collectionsrZcoverage.pluginrrrZcoverage.filesrZUtilsr	r
rrzrrrrr(r,r�rrrr�<module>s
�&2