o
    gS                     @  sv  d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. e!eZzddl/m0Z0m1Z1 dZ2W n e3y   e4ddkrej56d e7d dZ2Y nw edZ8G dd dZ9dS )z#Raw data collector for coverage.py.    )annotationsN)	FrameType)
castAnyCallableDictListMappingOptionalSetTypeTypeVar)env)CoverageConfig)CoverageData)short_stack)FileDisposition)ConfigError)human_sorted_itemsisolate_module)CoveragePlugin)PyTracer)
SysMonitor)TArcTFileDisposition
TTraceDataTTraceFn
TracerCoreTWarnFn)CTracerCFileDispositionTCOVERAGE_COREctracez8*** COVERAGE_CORE is 'ctrace' but can't import CTracer!
   FTc                   @  s   e Zd ZU dZg Zded< h dZdVddZdWddZdXd d!Z	dWd"d#Z
dYd$d%ZdYd&d'ZdZd)d*Zd[d1d2ZdYd3d4ZdYd5d6ZdYd7d8ZdYd9d:ZdYd;d<Zd\d=d>Zd]d@dAZd^dDdEZejdFdGd_dIdJZd`dNdOZdadRdSZd\dTdUZdFS )b	Collectora  Collects 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.

    zList[Collector]_collectors>   geventeventletgreenletshould_trace,Callable[[str, FrameType], TFileDisposition]check_include Callable[[str, FrameType], bool]should_start_context.Optional[Callable[[FrameType], Optional[str]]]file_mapperCallable[[str], str]timidboolbranchwarnr   concurrency	List[str]metacovreturnNonec
              
   C  s  || _ || _|| _|| _|| _|| _|| _t| jts#J d| jt	
 | _|  d| _d| _t | _d| _|  |  |r@d}
nt	d}
|
sNtrLd}
nd}
|
dkrkt| _d|	rZdnd	i| _t| _d
| _d
| _d
| _n5|
dkrt| _i | _t| _d| _d| _d| _n|
dkrt| _i | _t| _d
| _d
| _d| _ntd|
t| j}|t j! }|rd"t#|}td| || j$@ }t%|d	krd"t#|}td| d
}d}z7d|v rd}ddl&}|j'| _nd|v rd}ddl(}|j)j'| _nd|v rd}ddl*}|j'| _d|v rd}W n t+y& } zd| d}t||d}~ww | jr<t,| jds<td-|| . |sB|sIddl}|| _| /  dS )a  Create a collector.

        `should_trace` is a function, taking a file name and a frame, 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.

        `should_start_context` is a function taking a frame, and returning a
        string. If the frame should be the start of a new context, the string
        is the new context. If the frame should not be the start of a new
        context, return None.

        `file_mapper` is a function taking a filename, and returning a Unicode
        filename.  The result is the name that will be recorded in the data
        file.

        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
        and an optional slug argument which will be a string or None, 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).  "thread" can be combined with one of the other three.
        Other values are ignored.

        zExpected a list: Npytracer!   r"   sysmontool_id   r#   FTzUnknown core value: z, zUnknown concurrency choices: z"Conflicting concurrency settings: nothingr)   r   r(   r'   threadz Couldn't trace with concurrency=z, the module isn't installed.concur_id_funczACan't support concurrency={} with {}, only threads are supported.)0r*   r,   r.   r0   r4   r5   r6   
isinstancelistosgetpidpid	threadingstatic_contextr   originrA   getenvHAS_CTRACERr   _trace_class_core_kwargsr   file_disposition_classsupports_pluginspacked_arcssystracer   r    r   r   setr   CONCURRENCY_CHOICESjoinsortedLIGHT_THREADSlenr)   
getcurrenteventlet.greenthreadgreenthreadr'   ImportErrorhasattrformattracer_namereset)selfr*   r,   r.   r0   r2   r4   r5   r6   r8   coreconcurrenciesunknownshowlight_threadsdo_threadingtriedr)   r(   r'   exmsgrG    rj   R/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/coverage/collector.py__init__N   s   0








zCollector.__init__strc                 C  s   dt | dd|   dS )Nz<Collector at z#x: >)idr^   r`   rj   rj   rk   __repr__   s   zCollector.__repr__covdatar   contextOptional[str]c                 C  s   || _ || _| j | j dS )z!Use `covdata` for recording data.N)rs   rH   set_context)r`   rs   rt   rj   rj   rk   use_data   s   zCollector.use_datac                 C  s   | j jS )z0Return the class name of the tracer we're using.)rL   __name__rq   rj   rj   rk   r^      s   zCollector.tracer_namec                 C  s0   | j  D ]}|  q| jD ]}|  qdS )z<Clear out existing data, but stay ready for more collection.N)datavaluescleartracersreset_activity)r`   dtracerrj   rj   rk   _clear_data   s
   


zCollector._clear_datac                 C  sH   i | _ i | _t | _tjrddl}|d| _ni | _g | _	| 
  dS )z2Clear collected data, and prepare to collect more.r   Nmodule)ry   file_tracersrR   disabled_pluginsr   PYPY__pypy__newdictshould_trace_cacher|   r   )r`   r   rj   rj   rk   r_     s   
zCollector.resetTTraceFn | Nonec                 C  s   | j d	i | j}| j|_| j|_| j|_| j|_| j|_t|dr&| j	|_	t|dr/| j
|_
t|dr8| j|_t|drA| j|_t|drJ| j|_t|drS| j|_t|dr\| j|_| }| j| |S )
z8Start a new Tracer object, and store it in self.tracers.rA   r   rG   r,   r.   switch_contextdisable_pluginNrj   )rL   rM   ry   r4   
trace_arcsr*   r   r5   r\   rA   r   rG   r,   r.   r   r   startr|   append)r`   r   fnrj   rj   rk   _start_tracer/  s.   






zCollector._start_tracerframer   eventargr   Optional[TTraceFn]c                 C  s&   t d |  }|r||||}|S )z0Called on new threads, installs the real tracer.N)syssettracer   )r`   r   r   r   r   rj   rj   rk   _installation_traceT  s
   
zCollector._installation_tracec                 C  s   g }| j D ]}|j| jkr|| q|  q|| j dd< | j r)| j d   g | _z|   W n   | j r@| j d    | j |  | jrV| j	rX| j	
| j dS dS dS )z#Start collecting trace information.N)r&   rF   r   	post_forkpauser|   r   resumerQ   rG   r   r   )r`   keep_collectorscrj   rj   rk   r   a  s&   

zCollector.startc                 C  s   | j sJ | j d | ur!td | j D ]}td|d|j  q| j d | u s5J d| d| j d |   | j   | j rJ| j d   dS dS )z"Stop collecting trace information.r   zself._collectors:z  
z!Expected current collector to be z, but it's N)r&   printrI   r   popr   )r`   r   rj   rj   rk   stop  s   


zCollector.stopc                 C  sl   | j D ]%}|  | }|r(td t| D ]\}}t|dd|  qq| jr4| jd dS dS )z+Pause tracing, but be prepared to `resume`.z
Coverage.py tracer stats:z>20rn   N)r|   r   	get_statsr   r   itemsrG   r   )r`   r   statskvrj   rj   rk   r     s   
zCollector.pausec                 C  sB   | j D ]}|  q| jr| jr| j| j dS |   dS dS )zResume tracing after a `pause`.N)r|   r   rQ   rG   r   r   r   r`   r   rj   rj   rk   r     s   

zCollector.resumec                 C  s"   | j D ]}t|dr|  qdS )z+After a fork, tracers might need to adjust.r   N)r|   r\   r   r   rj   rj   rk   r     s
   

zCollector.post_forkc                 C  s   t dd | jD S )zkHas any activity been traced?

        Returns a boolean, True if any trace function was invoked.

        c                 s  s    | ]}|  V  qd S )N)activity).0r   rj   rj   rk   	<genexpr>  s    z&Collector._activity.<locals>.<genexpr>)anyr|   rq   rj   rj   rk   	_activity  s   zCollector._activitynew_contextc                 C  s:   |    | jr| j}|r|d| 7 }n|}| j| dS )z Switch to a new dynamic context.|N)
flush_datarH   rs   rv   )r`   r   rt   rj   rj   rk   r     s   zCollector.switch_contextdispositionr   c                 C  s@   |j }|dus	J |j}|j}| d|d d|_d|_dS )z.Disable the plugin mentioned in `disposition`.NzDisabling plug-in z due to previous exceptionF)file_tracer_coverage_plugin_coverage_plugin_namer5   _coverage_enabledtrace)r`   r   r   pluginplugin_namerj   rj   rk   r     s   
zCollector.disable_pluginN)maxsizefilenamec                 C  s
   |  |S )zBA locally cached version of file names mapped through file_mapper.)r0   )r`   r   rj   rj   rk   cached_mapped_file  s   
zCollector.cached_mapped_filer~   Mapping[str, T]Dict[str, T]c                   sr   d}t dD ] }zt| }W n ty$ } z|}W Y d}~qd}~ww  n	t|ts.J | fdd|D S )z<Return a dict like d, but with keys modified by file_mapper.Nr>   c                   s    i | ]\}}|r  ||qS rj   )r   r   r   r   rq   rj   rk   
<dictcomp>  s     z.Collector.mapped_file_dict.<locals>.<dictcomp>)rangerC   r   RuntimeErrorrB   	Exception)r`   r~   runtime_err_r   rh   rj   rq   rk   mapped_file_dict  s   zCollector.mapped_file_dictr   r   c                 C  s   | j |j dS )z1Record that `plugin` was disabled during the run.N)r   addr   )r`   r   rj   rj   rk   plugin_was_disabled  s   zCollector.plugin_was_disabledc                   s,     sdS  jrf jrPi }ttttt f  j}|	 D ]0\}}g }|D ]#}|d@ }|d@ d? }|d@ r:|d9 }|d@ rB|d9 }|
||f q&|||< qnttttt f  j} j | nttttt f  j}	 j |	  fdd	 j	 D }
 j |
    d
S )zSave the collected data to our associated `CoverageData`.

        Data may have also been saved along the way. This forces the
        last of the data to be saved.

        Returns True if there was data to save, False if not.
        Fi l        l        r   l        c                   s    i | ]\}}| j vr||qS rj   )r   r   rq   rj   rk   r     s
    
z(Collector.flush_data.<locals>.<dictcomp>T)r   r4   rP   r   r   rm   r   intry   r   r   r   r   rs   add_arcsr   	add_linesr   add_file_tracersr   )r`   arc_datapacked_datafnamepackedstuplespackedl1l2	line_datar   rj   rq   rk   r     s8   

zCollector.flush_data)r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r3   r5   r   r6   r7   r8   r3   r9   r:   )r9   rm   )rs   r   rt   ru   r9   r:   )r9   r:   )r9   r   )r   r   r   rm   r   r   r9   r   )r9   r3   )r   ru   r9   r:   )r   r   r9   r:   )r   rm   r9   rm   )r~   r   r9   r   )r   r   r9   r:   )rx   
__module____qualname____doc__r&   __annotations__rV   rl   rr   rw   r^   r   r_   r   r   r   r   r   r   r   r   r   r   	functools	lru_cacher   r   r   r   rj   rj   rj   rk   r%   6   s4   
 
 





,
%

#










r%   ):r   
__future__r   r   rD   r   typesr   typingr   r   r   r   r   r	   r
   r   r   r   coverager   coverage.configr   coverage.datar   coverage.debugr   coverage.dispositionr   coverage.exceptionsr   coverage.miscr   r   coverage.pluginr   coverage.pytracerr   coverage.sysmonr   coverage.typesr   r   r   r   r   r   coverage.tracerr   r    rK   r[   rJ   stderrwriteexitr$   r%   rj   rj   rj   rk   <module>   s<   0 
