
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    ¡ê,a¯t  ã                   @   sê   d Z 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mZ ddl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 )a·  program/module to trace Python program or function execution

Sample use, command line:
  trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs
  trace.py -t --ignore-dir '$prefix' spam.py eggs
  trace.py --trackcalls spam.py eggs

Sample use, programmatically
  import sys

  # create a Trace object, telling it what to ignore, and whether to
  # do tracing or line-counting or both.
  tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,],
                       trace=0, count=1)
  # run the new command using the given tracer
  tracer.run('main()')
  # make a report, placing output in /tmp
  r = tracer.results()
  r.write_results(show_missing=True, coverdir="/tmp")
ÚTraceÚCoverageResultsé    N)Ú	monotonicz#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 |¡‘qS © )ÚosÚpathÚnormpath©Ú.0Údr   r   ú*/opt/alt/python38/lib64/python3.8/trace.pyÚ
<listcomp>G   s   ÿz$_Ignore.__init__.<locals>.<listcomp>z<string>é   )ÚsetÚ_modsÚ_dirsÚ_ignore)ÚselfÚmodulesÚdirsr   r   r   Ú__init__E   s
    ÿz_Ignore.__init__c                 C   s¦   || j kr| j | S || jkr,d| j |< dS | jD ]"}| |d ¡r2d| j |<  dS q2|d krld| j |< dS | jD ]$}| |tj ¡rrd| j |<  dS qrd| j |< dS )Nr   Ú.r   )r   r   Ú
startswithr   r   Úsep)r   ÚfilenameÚ
modulenameÚmodr   r   r   r   ÚnamesK   s$    









z_Ignore.names)NN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   D   s   
r   c                 C   s    t j | ¡}t j |¡\}}|S )z-Return a plausible module name for the patch.)r   r   ÚbasenameÚsplitext)r   Úbaser   Úextr   r   r   Ú_modnamev   s    r&   c                 C   sÂ   t j | ¡}d}tjD ]@}t j |¡}| |¡r|t|ƒ t jkrt|ƒt|ƒkr|}q|rr| t|ƒd d… }n| }t j |¡\}}| t jd¡}t j	r¨| t j	d¡}t j 
|¡\}}| d¡S )z,Return a plausible module name for the path.Ú r   Nr   )r   r   ÚnormcaseÚsysr   Úlenr   Ú
splitdriveÚreplaceÚaltsepr#   Úlstrip)r   ZcomparepathZlongestÚdirr$   Zdriver   r%   r   r   r   Ú_fullmodname}   s     
r0   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d kr8i | _| j ¡ | _|| _| jd krZi | _| j ¡ | _|| _|| _| jrúz@t| jdƒ�}t 	|¡\}}}W 5 Q R X |  
|  |||¡¡ W n@ tttfk
rø } ztd| j|f tjd� W 5 d }~X Y 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   r4   r6   r8   r7   r9   ÚfÚerrr   r   r   r   š   s2    


ÿÿzCoverageResults.__init__c                 C   s   |  d¡o| d¡S )z_Return True if the filename does not refer to a file
        we want to have reported.
        ú<ú>)r   Úendswith)r   r   r   r   r   Úis_ignored_filename´   s    z#CoverageResults.is_ignored_filenamec           	      C   sn   | j }| j}| j}|j }|j}|j}|D ]}| |d¡||  ||< q(|D ]}d||< qJ|D ]}d||< q\dS )z.Merge in the data from another CoverageResultsr   r   N)r4   r6   r7   Úget)	r   Úotherr4   r6   r7   Zother_countsZother_calledfuncsZother_callersÚkeyr   r   r   r=   º   s    
zCoverageResults.updateTFc           "   
   C   sî  | j r@tƒ  tdƒ | j }t|ƒD ]\}}}td|||f ƒ q"| jrÐtƒ  tdƒ d }}	t| jƒD ]h\\}
}}\}}}|
|krœtƒ  td|
dƒ |
}d}	||
krº|	|krºtd|ƒ |}	td||||f ƒ qfi }| jD ].\}}| |i ¡ }||< | j||f ||< qÚi }| ¡ D �]\}}|  |¡�r0�q| d¡�rH|d	d
… }|d	k�rpt	j
 t	j
 |¡¡}t|ƒ}n$|}t	j
 |¡�sŒt	 |¡ t|ƒ}|�r¤t|ƒ}ni }t |¡}t	j
 ||d ¡}t|dƒ�}t |j¡\}}W 5 Q R X |  |||||¡\}}|�r|�rtd| | ƒ}||||f||< �q|�rt|�rttdƒ t|ƒD ]&}|| \}}}}td||  ƒ �qL| j�rêz6t| jdƒ� } t | j| j | jf| d¡ W 5 Q R X W n6 tk
�rè }! ztd|! tj d� W 5 d	}!~!X Y nX d	S )af  
        Write the coverage results.

        :param show_missing: Show lines that had no hits.
        :param summary: Include coverage summary per module.
        :param coverdir: If None, the results of each module are placed in its
                         directory, otherwise it is included in the directory
                         specified.
        zfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r'   z***z  -->z    %s.%s -> %s.%sz.pycNéÿÿÿÿz.coverr1   éd   zlines   cov%   module   (path)z%5d   %3d%%   %s   (%s)Úwbr   z"Can't save counts files because %sr2   )!r6   rB   Úsortedr7   r4   rJ   ÚitemsrI   rH   r   r   ÚdirnameÚabspathr&   ÚexistsÚmakedirsr0   Ú_find_executable_linenosÚ	linecacheÚgetlinesÚjoinr:   ÚtokenizeÚdetect_encodingÚreadlineÚwrite_results_fileÚintr9   r;   Údumpr?   r)   rC   )"r   Zshow_missingÚsummaryÚcoverdirZcallsr   r   ÚfuncnameZlastfileZ	lastcfileZpfileZpmodZpfuncÚcfileZcmodZcfuncZper_fileÚlinenoÚ	lines_hitZsumsÚcountr/   ÚlnotabÚsourceZ	coverpathÚfpÚencodingÚ_Ún_hitsÚn_linesZpercentÚmrD   rE   r   r   r   Úwrite_resultsÌ   sŠ    
ÿÿ





  ÿ ÿzCoverageResults.write_resultsc              
   C   sð   zt |d|d�}W n> tk
rP } z td||f tjd� W Y ¢dS d}~X Y nX d}d}	|�„ t|dƒD ]r\}
}|
|krž| d	||
  ¡ |	d7 }	|d7 }n.|
|krÂt|krÂ| d
¡ |d7 }n
| d¡ | | d¡¡ qjW 5 Q R X |	|fS )z'Return a coverage results file in path.Úw©rj   z3trace: Could not open %r for writing: %s - skippingr2   )r   r   Nr   r   z%5d: z>>>>>> z       é   )	r:   r?   rB   r)   rC   Ú	enumerateÚwriteÚPRAGMA_NOCOVERÚ
expandtabs)r   r   Úlinesrg   re   rj   r9   rE   rm   rl   rd   Úliner   r   r   r]   (  s.    ÿÿ



z"CoverageResults.write_results_file)NNNNN)TFN)N)r   r    r!   r   rI   r=   ro   r]   r   r   r   r   r   ™   s       ÿ

\c                 C   s,   i }t  | ¡D ]\}}||krd||< q|S )z:Return dict where keys are lines in the line number table.r   )ÚdisZfindlinestarts)ÚcodeÚstrsÚlinenosrk   rd   r   r   r   Ú_find_lines_from_codeH  s
    
r}   c                 C   s4   t | |ƒ}| jD ]}t |¡r| t||ƒ¡ q|S )z<Return lineno dict for all code objects reachable from code.)r}   Ú	co_constsÚinspectZiscoder=   Ú_find_lines)rz   r{   r|   Úcr   r   r   r€   R  s
    


r€   c              	   C   sŠ   i }t j}t| |d��j}t |j¡}|D ]R\}}}}	}
|t jkrv|t jkrv|\}}|	\}}t||d ƒD ]}d||< qh|}q(W 5 Q R X |S )zÄReturn a dict of possible docstring positions.

    The dict maps line numbers to strings.  There is an entry for
    line that contains only a string or a part of a triple-quoted
    string.
    rq   r   )ÚtokenÚINDENTr:   rZ   Úgenerate_tokensr\   ÚSTRINGÚrange)r   rj   r   Z
prev_ttyperD   ÚtokZttypeZtstrÚstartÚendrx   ZslineZscolZelineZecolÚir   r   r   Ú_find_strings^  s    


r‹   c              
   C   sŠ   z(t  | ¡�}| ¡ }|j}W 5 Q R X W n@ tk
rh } z"td| |f tjd� i  W Y ¢S d}~X Y nX t|| dƒ}t	| |ƒ}t
||ƒS )zAReturn dict where keys are line numbers in the line number table.z%Not printing coverage data for %r: %sr2   NÚexec)rZ   r:   Úreadrj   r?   rB   r)   rC   Úcompiler‹   r€   )r   rD   Úprogrj   rE   rz   r{   r   r   r   rV   u  s    ÿÿ
rV   c                	   @   sv   e Zd Zddd„Zdd	„ Zd d
d„Zdd„ Zde_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   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 )ax  
        @param count true iff it should count number of times each
                     line is executed
        @param trace true iff it should print out each line that is
                     being counted
        @param countfuncs true iff it should just output a list of
                     (filename, modulename, funcname,) for functions
                     that were called at least once;  This overrides
                     `count' and `trace'
        @param ignoremods a list of the names of modules to ignore
        @param ignoredirs a list of the names of directories to ignore
                     all of the (recursive) contents of
        @param infile file from which to read stored counts to be
                     added into the results
        @param outfile file in which to write the results
        @param timing true iff timing information be displayed
        r   Nr   )r8   r9   r   Úignorer4   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   rf   r’   Ú
countfuncsÚcountcallersÚ
ignoremodsÚ
ignoredirsr8   r9   Útimingr   r   r   r   „  s6    




zTrace.__init__c                 C   s    dd l }|j}|  |||¡ d S )Nr   )Ú__main__Ú__dict__Úrunctx)r   Úcmdr¥   Údictr   r   r   Úrun¶  s    z	Trace.runc              	   C   sh   |d kri }|d kri }| j s6t | j¡ t | j¡ zt|||ƒ W 5 | j sbt d ¡ t d ¡ X d S )N)r‘   Ú	threadingÚsettracer™   r)   rŒ   )r   r¨   ÚglobalsÚlocalsr   r   r   r§   »  s      
zTrace.runctxc               	   O   sª   t | ƒdkr| ^}}} nV| s&tdƒ‚nHd|krZ| d¡}| ^}} dd l}|jdtdd� ntdt | ƒd  ƒ‚d }|js„t |j	¡ z|| |Ž}W 5 |js¤t d ¡ X |S )	Né   z8descriptor 'runfunc' of 'Trace' object needs an argumentÚfuncr   z0Passing 'func' as keyword argument is deprecated)Ú
stacklevelz7runfunc expected at least 1 positional argument, got %dr   )
r*   Ú	TypeErrorÚpopÚwarningsÚwarnÚDeprecationWarningr‘   r)   r¬   r™   )ÚargsÚkwr   r°   r´   Úresultr   r   r   ÚrunfuncÈ  s.    

 ÿ
ÿzTrace.runfuncz($self, func, /, *args, **kw)c           
      C   sð   |j }|j}|rt|ƒ}nd }|j}d }|| jkrL| j| d k	rÒ| j| }n†d | j|< dd„ t |¡D ƒ}t|ƒdkrÒdd„ t |d ¡D ƒ}t|ƒdkrÒdd„ t |d ¡D ƒ}	t|	ƒdkrÒ|	d j}|| j|< |d k	ræd||f }|||fS )Nc                 S   s   g | ]}t  |¡r|‘qS r   )r   Z
isfunction)r   rD   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   ú  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   Úframerz   r   r   rb   ZclsnameZfuncsZdictsÚclassesr   r   r   Úfile_module_function_ofã  s,    




zTrace.file_module_function_ofc                 C   s0   |dkr,|   |¡}|   |j¡}d| j||f< dS )zkHandler for call events.

        Adds information about who called who to the self._callers dict.
        Úcallr   N)rÄ   Úf_backr”   )r   rÂ   ÚwhyÚargÚ	this_funcZparent_funcr   r   r   r˜     s    
zTrace.globaltrace_trackcallersc                 C   s    |dkr|   |¡}d| j|< dS )zoHandler for call events.

        Adds (filename, modulename, funcname) to the self._calledfuncs dict.
        rÅ   r   N)rÄ   r“   )r   rÂ   rÇ   rÈ   rÉ   r   r   r   rš     s    
zTrace.globaltrace_countfuncsc                 C   sj   |dkrf|j }|j dd¡}|rbt|ƒ}|dk	rf| j ||¡}|sf| jrZtd||jf ƒ | j	S ndS dS )z’Handler for call events.

        If the code block being entered is to be ignored, returns `None',
        else returns self.localtrace.
        rÅ   Ú__file__Nz! --- modulename: %s, funcname: %s)
r¾   Ú	f_globalsrJ   r&   r�   r   r’   rB   rÀ   r�   )r   rÂ   rÇ   rÈ   rz   r   r   Z	ignore_itr   r   r   r›      s    ÿzTrace.globaltrace_ltc                 C   s„   |dkr~|j j}|j}||f}| j |d¡d | j|< | jrTtdtƒ | j  dd� tj	 
|¡}td||t ||¡f dd� | jS )	Nrx   r   r   ú%.2fú ©r‰   ú
%s(%d): %sr'   )r¾   r¿   Úf_linenor4   rJ   r–   rB   r—   r   r   r"   rW   Úgetliner�   )r   rÂ   rÇ   rÈ   r   rd   rL   Úbnamer   r   r   rœ   7  s    
ÿÿz Trace.localtrace_trace_and_countc                 C   sd   |dkr^|j j}|j}| jr4tdtƒ | j  dd� tj |¡}td||t	 
||¡f dd� | jS )Nrx   rÌ   rÍ   rÎ   rÏ   r'   )r¾   r¿   rÐ   r–   rB   r—   r   r   r"   rW   rÑ   r�   )r   rÂ   rÇ   rÈ   r   rd   rÒ   r   r   r   rž   F  s    
ÿÿzTrace.localtrace_tracec                 C   s<   |dkr6|j j}|j}||f}| j |d¡d | j|< | jS )Nrx   r   r   )r¾   r¿   rÐ   r4   rJ   r�   )r   rÂ   rÇ   rÈ   r   rd   rL   r   r   r   rŸ   S  s    zTrace.localtrace_countc                 C   s   t | j| j| j| j| jd�S )N)r8   r9   r6   r7   )r   r4   r8   r9   r“   r”   )r   r   r   r   Úresults[  s
    
ýzTrace.results)	r   r   r   r   r   r   NNF)NN)r   r    r!   r   rª   r§   rº   Ú__text_signature__rÄ   r˜   rš   r›   rœ   rž   rŸ   rÓ   r   r   r   r   r   ƒ  s&            þ
2
)	c                     sØ  dd l } |  ¡ }|jd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dd
dd� | d¡}| ¡ }|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� | d-d.¡}|jd/d0g d1d2� |jd3d0g d4d2� |jd5d
d6d7d2� |jd8d9d:d;� |jd<| jd=d;� | ¡ }|j�rˆt 	d>¡‰t 	d?¡‰ ‡ ‡fd@dA„‰dBdC„ |j
D ƒ|_
‡fdDdC„|jD ƒ|_|j�rü|j�sØ| dE¡ t|j|jdF�}| |j|j|j¡S t|j|j|j|jgƒ�s | dG¡ |j�rB|j�s8|j�rB| dH¡ |j�r\|j�s\| dI¡ |jd k�rr| dJ¡ t|j|j|j|j|j
|j|j|j|jdK�	}zÀ|j�rðdd l}|j}| |¡\}	}
}|jf|j•t _!dL|j|
j"|
j#|
d dMœ}n^|jf|j•t _!t$j% &|j¡t j%d< t'|jdNƒ�}t(| )¡ |jdOƒ}W 5 Q R X |jdLd d dPœ}| *|||¡ W nP t+k
�rš } zt  ,dQt j!d |f ¡ W 5 d }~X Y n t-k
�r®   Y nX | .¡ }|j/�sÔ| |j|j|j¡ d S )RNr   z	--versionÚversionz	trace 2.0)ÚactionrÕ   zMain optionsz(One of these (or --report) must be givenz-cz--countÚ
store_truez»Count 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--listfuncsz§Keep 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--reportz¶Generate 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
--coverdirz†Directory 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).z--moduleFzTrace a module. Úprognameú?zfile to run as main program)ÚnargsrØ   Ú	argumentszarguments to the programZstdlibZ
platstdlibc                    s4   t j t j | ¡¡} |  dˆ¡ dˆ ¡} t j | ¡S )Nz$prefixz$exec_prefix)r   r   Ú
expanduserÚ
expandvarsr,   r	   )Ús)Ú_exec_prefixÚ_prefixr   r   Úparse_ignore_dir¬  s    zmain.<locals>.parse_ignore_dirc                 S   s$   g | ]}|  d ¡D ]}| ¡ ‘qqS )ú,)ÚsplitÚstrip)r   rŠ   r   r   r   r   r   ±  s     ÿzmain.<locals>.<listcomp>c                    s&   g | ]}|  tj¡D ]}ˆ |ƒ‘qqS r   )ræ   r   Úpathsep)r   rŠ   rá   )rä   r   r   r   ³  s     ÿz-r/--report requires -f/--file)r8   r9   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 --reportz3progname is missing: required with the main options)r    r¡   r¢   r£   r8   r9   r¤   r¥   )r   rÊ   Ú__package__Ú
__loader__Ú__spec__Ú
__cached__r1   rŒ   )rÊ   r   ré   rì   zCannot run file %r because: %s)0ÚargparseÚArgumentParserÚadd_argumentZadd_argument_groupZadd_mutually_exclusive_groupZ	REMAINDERÚ
parse_argsZ
ignore_dirÚ	sysconfigZget_pathZignore_moduleZreportr3   Úerrorr   ro   Zmissingr`   ra   Úanyr’   rf   Z	listfuncsZ
trackcallsrÛ   r   r¤   ÚmoduleÚrunpyZ_get_module_detailsr¿   rÞ   r)   ÚargvÚparentÚloaderr   r   rR   r:   rŽ   r�   r§   r?   ÚexitÚ
SystemExitrÓ   Z	no_report)rí   ÚparserZgrpZ_grpZoptsrÓ   Útrõ   Zmodule_nameZmod_nameZmod_specrz   Zglobsri   rE   r   )râ   rã   rä   r   Úmaina  sò    ÿ
ÿ
ÿ
ÿ
ÿ

ÿ
ÿÿÿ
ÿ
ÿ
ÿÿ
ÿ
ÿ
ÿÿ
ÿ

ÿ
ÿ




   ýú	ü(rý   r¥   )N)Ú__doc__Ú__all__rW   r   r)   rñ   r‚   rZ   r   rÁ   ry   r;   Útimer   r—   r«   ru   r   r&   r0   r   r}   r€   r‹   rV   r   rý   r   r   r   r   r   Ú<module>   s:   2 0

 _ 