???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
2a4p                 @   s(  d dgZ ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZ yddlZW n" ek
r   ejZdd ZY nX dd Zd	d Zd
ZG dd dZdd Zdd ZG dd dZdd Zdd ZdddZdd ZG dd  d Zdd Zedkr$e  dS )TraceCoverageResults    N)	monotonicc               C   s   t jd  d S )N)syssettrace r   r   */opt/alt/python36/lib64/python3.6/trace.py_unsettraceE   s    r	   c             C   s   t j|  tj|  d S )N)	threadingr   r   )funcr   r   r   	_settraceH   s    
r   c               C   s   t jd  tjd  d S )N)r   r   r
   r   r   r   r   r	   L   s    
z#pragma NO COVERc               @   s   e Zd ZdddZdd ZdS )_IgnoreNc             C   s:   |s
t  nt || _|sg ndd |D | _ddi| _d S )Nc             S   s   g | ]}t jj|qS r   )ospathnormpath).0dr   r   r   
<listcomp>U   s   z$_Ignore.__init__.<locals>.<listcomp>z<string>   )set_mods_dirs_ignore)selfmodulesdirsr   r   r   __init__S   s    
z_Ignore.__init__c             C   s   || j kr| j | S || jkr,d| j |< dS x*| jD ] }|j|d r4d| j |< dS q4W |d krnd| j |< dS x,| jD ]"}|j|tj rvd| j |< dS qvW d| j |< dS )Nr   .r   )r   r   
startswithr   r   sep)r   filename
modulenamemodr   r   r   r   namesY   s$    







z_Ignore.names)NN)__name__
__module____qualname__r   r#   r   r   r   r   r   R   s   
r   c             C   s    t jj| }t jj|\}}|S )N)r   r   basenamesplitext)r   baser    extr   r   r   _modname   s    r+   c             C   s   t jj| }d}xJtjD ]@}t jj|}|j|r|t| t jkrt|t|kr|}qW |rv| t|d d  }n| }t jj|\}}|jt jd}t j	r|jt j	d}t jj
|\}}|jdS )N r   r   )r   r   normcaser   r   lenr   
splitdrivereplacealtsepr(   lstrip)r   ZcomparepathZlongestdirr)   Zdriver    r*   r   r   r   _fullmodname   s     r4   c               @   s:   e Zd ZdddZdd Zdd Zdd
dZdddZdS )r   Nc             C   s   || _ | j d kri | _ | j j | _|| _| jd kr8i | _| jj | _|| _| jd krZi | _| jj | _|| _|| _| jry@t| jd}tj	|\}}}W d Q R X | j
| j||| W n@ tttfk
r } ztd| j|f tjd W Y d d }~X nX d S )NrbzSkipping counts file %r: %s)file)countscopyZcountercalledfuncscallersinfileoutfileopenpickleloadupdate	__class__OSErrorEOFError
ValueErrorprintr   stderr)r   r7   r9   r;   r:   r<   ferrr   r   r   r      s,    


zCoverageResults.__init__c             C   s   |j do|jdS )N<>)r   endswith)r   r    r   r   r   is_ignored_filename   s    z#CoverageResults.is_ignored_filenamec       	      C   sz   | j }| j}| j}|j }|j}|j}x$|D ]}|j|d||  ||< q*W x|D ]}d||< qPW x|D ]}d||< qfW d S )Nr   r   )r7   r9   r:   get)	r   otherr7   r9   r:   Zother_countsZother_calledfuncsZother_callerskeyr   r   r   r@      s    


zCoverageResults.updateTFc       !      C   s  | j rDt  td | j }x(t|D ]\}}}td|||f  q$W | jrt  td d }}	xvt| jD ]h\\}
}}\}}}|
|krt  td|
d |
}d}	||
kr|	|krtd| |}	td||||f  qlW i }x8| jD ].\}}|j|i  }||< | j||f ||< qW i }x$|j D ]\}}| j|r@q&|jdrX|d d }|d krt	j
jt	j
j|}t|}n$|}t	j
j|st	j| t|}|rt|}ni }tj|}t	j
j||d
 }t|d}tj|j\}}W d Q R X | j|||||\}}|r&|r&td| | }||||f||< q&W |r|rtd x2t|D ]&}|| \}}}}td||   q`W | jry&tj| j| j | jft| jdd	 W n6 tk
r }  ztd|  tj d W Y d d } ~ X nX d S )Nzfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r,   z***z  -->z    %s.%s -> %s.%sz.pycr   z.coverr5   d   zlines   cov%   module   (path)z%5d   %3d%%   %s   (%s)wbz"Can't save counts files because %s)r6   )!r9   rE   sortedr:   r7   rM   itemsrL   rK   r   r   dirnameabspathr+   existsmakedirsr4   _find_executable_linenos	linecachegetlinesjoinr=   tokenizedetect_encodingreadlinewrite_results_fileintr<   r>   dumprB   r   rF   )!r   Zshow_missingsummarycoverdirZcallsr    r!   funcnameZlastfileZ	lastcfileZpfileZpmodZpfunccfileZcmodZcfuncZper_filelineno	lines_hitZsumscountr3   lnotabsourceZ	coverpathfpencoding_n_hitsn_linespercentmrH   r   r   r   write_results   s|    






zCoverageResults.write_resultsc             C   s   yt |d|d}W n6 tk
rH } ztd||f tjd dS d }~X nX d}d}	| xt|dD ]r\}
}|
|kr|jd||
   |	d7 }	|d7 }n.|
|krt|kr|jd |d7 }n
|jd	 |j|jd
 qdW W d Q R X |	|fS )Nw)rm   z3trace: Could not open %r for writing: %s - skipping)r6   r   r   z%5d: z>>>>>> z          )r   r   )	r=   rB   rE   r   rF   	enumeratewritePRAGMA_NOCOVER
expandtabs)r   r   linesrj   rh   rm   r<   rH   rp   ro   rg   liner   r   r   r`   5  s(    



z"CoverageResults.write_results_file)NNNNN)TFN)N)r$   r%   r&   r   rL   r@   rs   r`   r   r   r   r   r      s    

[c             C   s0   i }x&t j| D ]\}}||krd||< qW |S )Nr   )disZfindlinestarts)codestrslinenosrn   rg   r   r   r   _find_lines_from_codeU  s
    r   c             C   s8   t | |}x(| jD ]}tj|r|jt|| qW |S )N)r   	co_constsinspectZiscoder@   _find_lines)r}   r~   r   cr   r   r   r   _  s
    

r   c             C   s   i }t j}t| |dr}tj|j}x^|D ]V\}}}}	}
|t jkr||t jkr||\}}|	\}}xt||d D ]}d||< qlW |}q*W W d Q R X |S )N)rm   r   )tokenINDENTr=   r]   generate_tokensr_   STRINGrange)r    rm   r   Z
prev_ttyperG   tokZttypeZtstrstartendr{   ZslineZscolZelineZecolir   r   r   _find_stringsk  s    

r   c             C   s   y(t j| }|j }|j}W d Q R X W n6 tk
r^ } ztd| |f tjd i S d }~X nX t|| d}t	| |}t
||S )Nz%Not printing coverage data for %r: %s)r6   exec)r]   r=   readrm   rB   rE   r   rF   compiler   r   )r    rG   progrm   rH   r}   r~   r   r   r   rY     s    
rY   c            	   @   s   e Zd Zddddf f dddf	ddZdd Zdd	d
Zdd Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )r   r   r   NFc
       
      C   s   || _ || _t||| _i | _i | _d| _|| _i | _i | _	i | _
d | _|	rTt | _|rb| j| _nZ|rp| j| _nL|r|r| j| _| j| _n2|r| j| _| j| _n|r| j| _| j| _nd| _d S )Nr   r   )r;   r<   r   ignorer7   Zpathtobasename	donothingtrace_calledfuncs_callers_caller_cache
start_time_timeglobaltrace_trackcallersglobaltraceglobaltrace_countfuncsglobaltrace_ltlocaltrace_trace_and_count
localtracelocaltrace_tracelocaltrace_count)
r   ri   r   
countfuncscountcallers
ignoremods
ignoredirsr;   r<   timingr   r   r   r     s6    




zTrace.__init__c             C   s    dd l }|j}| j||| d S )Nr   )__main____dict__runctx)r   cmdr   dictr   r   r   run  s    z	Trace.runc          
   C   sL   |d kri }|d kri }| j s(t| j zt||| W d | j sFt  X d S )N)r   r   r   r   r	   )r   r   globalslocalsr   r   r   r     s      
zTrace.runctxc             O   s<   d }| j stj| j z|||}W d | j s6tjd  X |S )N)r   r   r   r   )r   r   argskwresultr   r   r   runfunc  s    zTrace.runfuncc       
      C   s   |j }|j}|rt|}nd }|j}d }|| jkrL| j| d k	r| j| }nd | j|< dd tj|D }t|dkrdd tj|d D }t|dkrdd tj|d D }	t|	dkr|	d j}|| j|< |d k	rd||f }|||fS )Nc             S   s   g | ]}t j|r|qS r   )r   Z
isfunction)r   rG   r   r   r   r     s    z1Trace.file_module_function_of.<locals>.<listcomp>r   c             S   s   g | ]}t |tr|qS r   )
isinstancer   )r   r   r   r   r   r     s    r   c             S   s   g | ]}t |d r|qS )	__bases__)hasattr)r   r   r   r   r   r     s    z%s.%s)	f_codeco_filenamer+   co_namer   gcZget_referrersr.   r$   )
r   framer}   r    r!   re   ZclsnameZfuncsZdictsclassesr   r   r   file_module_function_of  s,    




zTrace.file_module_function_ofc             C   s0   |dkr,| j |}| j |j}d| j||f< d S )Ncallr   )r   f_backr   )r   r   whyarg	this_funcZparent_funcr   r   r   r     s    
zTrace.globaltrace_trackcallersc             C   s    |dkr| j |}d| j|< d S )Nr   r   )r   r   )r   r   r   r   r   r   r   r   r     s    
zTrace.globaltrace_countfuncsc             C   sj   |dkrf|j }|jjdd }|rbt|}|d k	rf| jj||}|sf| jrZtd||jf  | j	S nd S d S )Nr   __file__z! --- modulename: %s, funcname: %s)
r   	f_globalsrM   r+   r   r#   r   rE   r   r   )r   r   r   r   r}   r    r!   Z	ignore_itr   r   r   r     s    zTrace.globaltrace_ltc             C   s   |dkr~|j j}|j}||f}| jj|dd | j|< | jrTtdt | j  dd tj	j
|}td||tj||f dd | jS )	Nr{   r   r   z%.2f )r   z
%s(%d): %sr,   )r   r   f_linenor7   rM   r   rE   r   r   r   r'   rZ   getliner   )r   r   r   r   r    rg   rO   bnamer   r   r   r   2  s    z Trace.localtrace_trace_and_countc             C   sd   |dkr^|j j}|j}| jr4tdt | j  dd tjj|}td||t	j
||f dd | jS )Nr{   z%.2fr   )r   z
%s(%d): %sr,   )r   r   r   r   rE   r   r   r   r'   rZ   r   r   )r   r   r   r   r    rg   r   r   r   r   r   A  s    zTrace.localtrace_tracec             C   s<   |dkr6|j j}|j}||f}| jj|dd | j|< | jS )Nr{   r   r   )r   r   r   r7   rM   r   )r   r   r   r   r    rg   rO   r   r   r   r   N  s    zTrace.localtrace_countc             C   s   t | j| j| j| j| jdS )N)r;   r<   r9   r:   )r   r7   r;   r<   r   r   )r   r   r   r   resultsV  s    
zTrace.results)NN)r$   r%   r&   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s   0
)	c                 s  t j } | jdddd | jdd}|jddd	d
d |jddd	dd |jddd	dd |jddd	dd | jd}|j }|jddd	dd |jddd	dd |jdddd |jd d!d"d |jd#d$d	d%d |jd&d'd	d(d |jd)d*d	d+d | jd,d-}|jd.d/g d0d1 |jd2d/g d3d1 | jd4d5d6d7 | jd8t jd9d7 | j }|jrd:d;jt	j
f}tjjt	jf| tjjt	jf|   fd<d=d>d? |jD |_fd@d?|jD |_|jr|js| jdA t|j|jdB}|j|j|j|jS t|j|j|j|jgs*| jdC |jrL|jsB|jrL| jdD |jrh|j rh| jdE |jd kr~| jdF |jf|jt	_ tjj!|jt	jdG< t"|j|j|j|j|j|j|j|j|j#dH	}yJt$|j}t%|j& |jdI}W d Q R X |jdJd d dK}	|j'||	|	 W nP t(k
rT }
 zt	j)dLt	j dG |
f  W Y d d }
~
X n t*k
rh   Y nX |j+ }|j,s|j|j|j|j d S )MNz	--versionversionz	trace 2.0)actionr   zMain optionsz(One of these (or --report) must be givenz-cz--count
store_truezCount the number of times each line is executed and write the counts to <module>.cover for each module executed, in the module's directory. See also --coverdir, --file, --no-report below.)r   helpz-tz--tracez3Print each line to sys.stdout before it is executedz-lz--listfuncszKeep track of which functions are executed at least once and write the results to sys.stdout after the program exits. Cannot be specified alongside --trace or --count.z-Tz--trackcallsz^Keep track of caller/called pairs and write the results to sys.stdout after the program exits.Z	Modifiersz-rz--reportzGenerate a report from a counts file; does not execute any code. --file must specify the results file to read, which must have been created in a previous run with --count --file=FILEz-Rz--no-reportz^Do not generate the coverage report files. Useful if you want to accumulate over several runs.z-fz--filez+File to accumulate counts over several runs)r   z-Cz
--coverdirzDirectory where the report files go. The coverage report for <package>.<module> will be written to file <dir>/<package>/<module>.coverz-mz	--missingz?Annotate executable lines that were not executed with ">>>>>> "z-sz	--summaryz\Write a brief summary for each file to sys.stdout. Can only be used with --count or --reportz-gz--timingzQPrefix each line with the time since the program started. Only used while tracingZFilterszCan be specified multiple timesz--ignore-moduleappendzqIgnore the given module(s) and its submodules (if it is a package). Accepts comma separated list of module names.)r   defaultr   z--ignore-dirzWIgnore files in the given directory (multiple directories can be joined by os.pathsep).r    ?zfile to run as main program)nargsr   	argumentszarguments to the programlibzpython{0.major}.{0.minor}c                s4   t jjt jj| } | jdjd } t jj| S )Nz$prefixz$exec_prefix)r   r   
expanduser
expandvarsr0   r   )s)_exec_prefix_prefixr   r   parse_ignore_dir  s    zmain.<locals>.parse_ignore_dirc             S   s$   g | ]}|j d D ]}|j qqS ),)splitstrip)r   r   r"   r   r   r   r     s   zmain.<locals>.<listcomp>c                s&   g | ]}|j tjD ]} |qqS r   )r   r   pathsep)r   r   r   )r   r   r   r     s   z-r/--report requires -f/--file)r;   r<   zLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallsz8cannot specify both --listfuncs and (--trace or --count)z3--summary can only be used with --count or --reportz3filename is missing: required with the main optionsr   )r   r   r   r   r;   r<   r   r   r   )r   r$   __package__
__cached__zCannot run file %r because: %s)-argparseArgumentParseradd_argumentadd_argument_groupadd_mutually_exclusive_group	REMAINDER
parse_argsZ
ignore_dirformatr   version_infor   r   r\   base_prefixbase_exec_prefixZignore_moduleZreportr6   errorr   rs   missingrc   rd   anyr   ri   Z	listfuncsZ
trackcallsr    r   argvrU   r   r   r=   r   r   r   rB   exit
SystemExitr   Z	no_report)parserZgrpZ_grpZoptsZrel_pathr   trl   r}   ZglobsrH   r   )r   r   r   r   main\  s    


















(r   r   )N) __all__r   rZ   r   rer   r   r]   r   r   r|   r>   Ztimer   r   r
   ImportErrorr   r   r	   rx   r   r+   r4   r   r   r   r   rY   r   r   r$   r   r   r   r   <module>2   sF   2 /

 M 
