Your IP : 216.73.216.213


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



E�W�9�@s#dZddlZddlZddlmZddlmZddlmZddl	m
Z
mZddlm
Z
ee�ZyddlmZmZWnJek
r�ejd	�d
kr�ejjd�ejd�dZYnXGd
d�de�Zdd�ZGdd�de�ZdS)z#Raw data collector for coverage.py.�N)�env)�iitems)�abs_file)�CoverageException�isolate_module)�PyTracer)�CTracer�CFileDispositionZCOVERAGE_TEST_TRACER�cz:*** COVERAGE_TEST_TRACER is 'c' but can't import CTracer!
�c@seZdZdZdS)�FileDispositionz9A simple value type for recording what to do with a file.N)�__name__�
__module__�__qualname__�__doc__�rr�E/opt/alt/python35/lib64/python3.5/site-packages/coverage/collector.pyr#srcCs#|jj}|jd�r|SdS)zKWho-Tests-What hack: Determine whether this frame begins a new who-context.�testN)�f_code�co_name�
startswith)�frameZfn_namerrr�should_start_context(src@s�eZdZdZgZeddddg�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�	CollectoraCollects trace data.

    Creates a Tracer object for each thread, since they track stack
    information.  Each Tracer points to the same shared data, contributing
    traced data points.

    When the Collector is started, it creates a Tracer for the current thread,
    and installs a function to create Tracers for each new thread started.
    When the Collector is stopped, all active Tracers are stopped.

    Threads started while the Collector is stopped will never have Tracers
    associated with them.

    �greenlet�eventlet�gevent�threadcCs�||_||_||_||_d|_d|_|jj|�}t|�dkrjt	d|��|r||j
�nd|_y�|jdkr�ddl}|j
|_n�|jdkr�ddl}	|	jj
|_nk|jdkr	ddl}
|
j
|_nA|jd	ks"|jr:ddl}||_nt	d
|��Wn(tk
rut	d|jf��YnXttjdd��|_|j�|r�t|_ntp�t|_|jtkr�t|_d
|_nt|_d|_dS)a�Create a collector.

        `should_trace` is a function, taking a file name, and returning a
        `coverage.FileDisposition object`.

        `check_include` is a function taking a file name and a frame. It returns
        a boolean: True if the file should be traced, False if not.

        If `timid` is true, then a slower simpler trace function will be
        used.  This is important for some environments where manipulation of
        tracing functions make the faster more sophisticated trace function not
        operate properly.

        If `branch` is true, then branches will be measured.  This involves
        collecting data on which statements followed each other (arcs).  Use
        `get_arc_data` to get the arc data.

        `warn` is a warning function, taking a single string message argument,
        to be used if a warning needs to be issued.

        `concurrency` is a list of strings indicating the concurrency libraries
        in use.  Valid values are "greenlet", "eventlet", "gevent", or "thread"
        (the default).  Of these four values, only one can be supplied.  Other
        values are ignored.

        Nrz$Conflicting concurrency settings: %s�rrrrrzDon't understand concurrency=%sz?Couldn't trace with concurrency=%s, the module isn't installed.ZCOVERAGE_WTWTF)�should_trace�
check_include�warn�branch�	threading�concur_id_func�SUPPORTED_CONCURRENCIES�intersection�lenr�pop�concurrencyrZ
getcurrentZeventlet.greenthreadZgreenthreadr�ImportError�int�os�getenv�wtw�resetr�_trace_classrr	Zfile_disposition_classZsupports_pluginsr)�selfrr Ztimidr"r!r)Zthese_concurrenciesrrrr#rrr�__init__GsL						

		zCollector.__init__cCsdt|�|j�fS)Nz<Collector at 0x%x: %s>)�id�tracer_name)r1rrr�__repr__�szCollector.__repr__cCs
|jjS)z0Return the class name of the tracer we're using.)r0r
)r1rrrr4�szCollector.tracer_namecCski|_i|_|j|jd<i|_tjrUddl}|jd�|_n	i|_g|_dS)z2Clear collected data, and prepare to collect more.Nr�module)	�data�contexts�file_tracersrZPYPY�__pypy__Znewdict�should_trace_cache�tracers)r1r:rrrr/�s			
		zCollector.resetcCs;|j�}|j|_|j|_|j|_|j|_|j|_t|d�rf|j|_n(|jr�t	d|j
|j�f��t|d�r�|j|_t|d�r�|j
|_
t|d�r�|j|_|jrt|d�rt|_t|d�r|j|_|j�}|jj|�|S)z8Start a new Tracer object, and store it in self.tracers.r$z@Can't support concurrency=%s with %s, only threads are supportedr9r#r r�switch_context)r0r7r"Z
trace_arcsrr;r!�hasattrr$rr)r4r9r#r r.rr=�startr<�append)r1�tracer�fnrrr�
_start_tracer�s4			zCollector._start_tracercCs5tjd�|j�}|r1||||�}|S)z0Called on new threads, installs the real tracer.N)�sys�settracerC)r1r�event�argrBrrr�_installation_trace�s

zCollector._installation_tracec
Cs%|jr|jdj�g}tj�}|r\t|dd�}|r\t|dg�}y|j�}Wn%|jr�|jdj��YnX|jj|�x^|D]V}|\\}}}}	y||||d|	�Wq�tk
rt	d��Yq�Xq�W|j
r!|j
j|j�dS)	z#Start collecting trace information.r�__self__NZtraces�linenoz3fullcoverage must be run with the C trace function.���rK)
�_collectors�pauserD�gettrace�getattrrC�resumer@�	TypeError�	Exceptionr#rErH)
r1Ztraces0Zfn0Ztracer0rB�argsrrFrGrJrrrr?	s.		

	zCollector.startcCs}|jst�|jd|ks?td||jdf��|j�g|_|jj�|jry|jdj�dS)z"Stop collecting trace information.rz0Expected current collector to be %r, but it's %rNrKrKrK)rL�AssertionErrorrMr<r(rP)r1rrr�stop0s
	
	zCollector.stopcCs�xl|jD]a}|j�|j�}|r
td�x2t|j��D]}td|||f�qIWq
W|jr�|jjd�dS)z+Pause tracing, but be prepared to `resume`.z
Coverage.py tracer stats:z%20s: %sN)r<rUZ	get_stats�print�sorted�keysr#rE)r1rAZstats�krrrrM@s

 	zCollector.pausecCsKx|jD]}|j�q
W|jr=|jj|j�n
|j�dS)zResume tracing after a `pause`.N)r<r?r#rErHrC)r1rArrrrPLs
	zCollector.resumecCs6|jj|i�}x|jD]}||_qWdS)z1Who-Tests-What hack: switch to a new who-context.N)r8�
setdefaultr<r7)r1Znew_contextr7rArrrr=UszCollector.switch_contextc
Cs�dd�}|jr.|j||j��n|j||j��|j||j��|jr�ddl}djt	j
��}t|d��}|j|j|�WdQRX|j
�dS)zZSave the collected data to a `CoverageData`.

        Also resets the collector.

        cSstdd�t|�D��S)z;Return a dict like d, but with keys modified by `abs_file`.css'|]\}}t|�|fVqdS)N)r)�.0rY�vrrr�	<genexpr>esz=Collector.save_data.<locals>.abs_file_dict.<locals>.<genexpr>)�dictr)�drrr�
abs_file_dictcsz*Collector.save_data.<locals>.abs_file_dictrNzcoverage_wtw_{:06}.py�w)r"Zadd_arcsr7Z	add_linesZadd_file_tracersr9r.�pprint�formatr,�getpid�openr8r/)r1Zcovdatar`rb�out_fileZwtw_outrrr�	save_data]s		zCollector.save_dataN)r
rrrrL�setr%r2r5r4r/rCrHr?rUrMrPr=rgrrrrr/sW.)
'	r)rr,rD�coveragerZcoverage.backwardrZcoverage.filesrZ
coverage.miscrrZcoverage.pytracerrZcoverage.tracerrr	r*r-�stderr�write�exit�objectrrrrrrr�<module>s$