AlkantarClanX12

Your IP : 18.117.94.77


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/trace.cpython-35.opt-1.pyc



��YfA{�@s@dZddgZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
ZddlmZyddlZWn'ek
r�ejZdd�ZYnXd	d
�Zdd�Zdd
�ZdZejd�ZGdd�d�Zdd�Zdd�ZGdd�d�Zdd�Zdd�Z ddd�Z!dd�Z"Gdd�d�Z#d d!�Z$dd"d#�Z%d$d%�Z&Gd&d'�d'e�Z'd(d)�Z(d*d+�Z)d,d-�Z*d.d/�Z+dd0d1�Z,d2d3�Z-e.d4kr<e%�dS)5a�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)�warn)�	monotoniccCstjd�dS)N)�sys�settrace�rr�*/opt/alt/python35/lib64/python3.5/trace.py�_unsettraceEsr
cCstj|�tj|�dS)N)�	threadingrr)�funcrrr	�	_settraceHs
r
cCstjd�tjd�dS)N)rrrrrrr	r
Ls
cCs|jdtjd�dS)Na	Usage: %s [OPTIONS] <file> [ARGS]

Meta-options:
--help                Display this help then exit.
--version             Output version information then exit.

Otherwise, exactly one of the following three options must be given:
-t, --trace           Print each line to sys.stdout before it is executed.
-c, --count           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.
-l, --listfuncs       Keep track of which functions are executed at least
                      once and write the results to sys.stdout after the
                      program exits.
-T, --trackcalls      Keep track of caller/called pairs and write the
                      results to sys.stdout after the program exits.
-r, --report          Generate a report from a counts file; do not execute
                      any code.  `--file' must specify the results file to
                      read, which must have been created in a previous run
                      with `--count --file=FILE'.

Modifiers:
-f, --file=<file>     File to accumulate counts over several runs.
-R, --no-report       Do not generate the coverage report files.
                      Useful if you want to accumulate over several runs.
-C, --coverdir=<dir>  Directory where the report files.  The coverage
                      report for <package>.<module> is written to file
                      <dir>/<package>/<module>.cover.
-m, --missing         Annotate executable lines that were not executed
                      with '>>>>>> '.
-s, --summary         Write a brief summary on stdout for each file.
                      (Can only be used with --count or --report.)
-g, --timing          Prefix each line with the time since the program started.
                      Only used while tracing.

Filters, may be repeated multiple times:
--ignore-module=<mod> Ignore the given module(s) and its submodules
                      (if it is a package).  Accepts comma separated
                      list of module names
--ignore-dir=<dir>    Ignore files in the given directory (multiple
                      directories can be joined by os.pathsep).
r)�writer�argv)�outfilerrr	�_usagePs*rz#pragma NO COVERz^\s*(#.*)?$c@s.eZdZdddd�Zdd�ZdS)�_IgnoreNcCsS|st�n	t|�|_|s*gndd�|D�|_ddi|_dS)NcSs"g|]}tjj|��qSr)�os�path�normpath)�.0�drrr	�
<listcomp>�s	z$_Ignore.__init__.<locals>.<listcomp>z<string>�)�set�_mods�_dirs�_ignore)�self�modules�dirsrrr	�__init__�s
z_Ignore.__init__cCs�||jkr|j|S||jkr:d|j|<dSx5|jD]*}|j|d�rDd|j|<dSqDW|dkr�d|j|<dSx8|jD]-}|j|tj�r�d|j|<dSq�Wd|j|<dS)Nr�.r)rr�
startswithrr�sep)r�filename�
modulename�modrrrr	�names�s$




z
_Ignore.names)�__name__�
__module__�__qualname__r!r(rrrr	r�srcCs.tjj|�}tjj|�\}}|S)z-Return a plausible module name for the patch.)rr�basename�splitext)r�baser%�extrrr	�_modname�sr0cCstjj|�}d}xitjD]^}tjj|�}|j|�r"|t|�tjkr"t|�t|�kr"|}q"W|r�|t|�dd�}n|}tjj|�\}}|jtjd�}tj	r�|jtj	d�}tjj
|�\}}|jd�S)z,Return a plausible module name for the path.�rNr")rr�normcaserr#�lenr$�
splitdrive�replace�altsepr-�lstrip)rZcomparepathZlongest�dirr.Zdriver%r/rrr	�_fullmodname�s (
	r9c@sgeZdZddddddd�Zdd�Zdd�Zdd	dd
d�Zddd
�ZdS)rNcCs]||_|jdkr!i|_|jj�|_||_|jdkrTi|_|jj�|_||_|jdkr�i|_|jj�|_||_||_|jrYyTt|jd��}tj	|�\}}}WdQRX|j
|j|||��WnNtt
tfk
rX}z%td|j|fdtj�WYdd}~XnXdS)N�rbzSkipping counts file %r: %s�file)�counts�copyZcounter�calledfuncs�callers�infiler�open�pickle�load�update�	__class__�OSError�EOFError�
ValueError�printr�stderr)rr<r>r@r?r�f�errrrr	r!�s,									 zCoverageResults.__init__cCs|jd�o|jd�S)z_Return True if the filename does not refer to a file
        we want to have reported.
        �<�>)r#�endswith)rr%rrr	�is_ignored_filename�sz#CoverageResults.is_ignored_filenamec	Cs�|j}|j}|j}|j}|j}|j}x,|D]$}|j|d�||||<q=Wx|D]}d||<qlWx|D]}d||<q�WdS)z.Merge in the data from another CoverageResultsrrN)r<r>r?�get)	r�otherr<r>r?Zother_countsZother_calledfuncsZ
other_callers�keyrrr	rD�s						
"

zCoverageResults.updateTFc!Cs�|jrZt�td�|j}x4t|�D]&\}}}td|||f�q0W|jr$t�td�d}}	x�t|j�D]�\\}
}}\}
}}|
|kr�t�td|
d�|
}d}	|
|
kr|	|
krtd|
�|
}	td||||f�q�Wi}xH|jD]=\}}|j|i�}||<|j||f||<q4Wi}x�|j�D]x\}}|j|�r�q�|jd�r�|d	d�}|d	kr�t	j
jt	j
j|��}t
|�}n1|}t	j
j|�s#t	j|�t|�}|rDt|�}ni}|r�tj|�}t	j
j||d�}t|d��}tj|j�\}}Wd	QRX|j|||||�\}}|r�|r�td
||�}||||f||<q�W|rY|rYtd�x<t|�D].}||\}}}}td||�q'W|jr�y5tj|j|j|jft|jd�d
�Wn<tk
r�} ztd| dtj �WYd	d	} ~ XnXd	S)z!
        @param coverdir
        zfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r1z***z  -->z    %s.%s -> %s.%sz.pycNrz.coverr:�dzlines   cov%   module   (path)z%5d   %3d%%   %s   (%s)�wbz"Can't save counts files because %sr;���)!r>rI�sortedr?r<rQ�itemsrPrOrr�dirname�abspathr0�exists�makedirsr9�_find_executable_linenos�	linecache�getlines�joinrA�tokenize�detect_encoding�readline�write_results_file�intrrB�dumprFrrJ)!rZshow_missing�summary�coverdirZcallsr%r&�funcnameZlastfileZ	lastcfileZpfileZpmodZpfunc�cfileZcmodZcfuncZper_file�lineno�	lines_hitZsums�countr8�lnotab�sourceZ	coverpath�fp�encoding�_�n_hits�n_linesZpercent�mrLrrr	�
write_results
s~	
		

+


	zCoverageResults.write_resultscCsRyt|dd|�}WnFtk
ra}z&td||fdtj�dSWYdd}~XnXd}d}	|��x�t|d�D]�\}
}|
|kr�|jd||
�|	d7}	|d7}n^tj|�r�|jd	�n?|
|krt	|kr|jd
�|d7}n
|jd	�|j|j
d��q�WWdQRX|	|fS)
z'Return a coverage results file in path.�wrqz2trace: Could not open %r for writing: %s- skippingr;rNrz%5d: z       z>>>>>> �)rr)rArFrIrrJ�	enumerater�rx_blank�match�PRAGMA_NOCOVER�
expandtabs)rr�linesrnrlrqrrLrtrsrk�linerrr	rd`s,




!z"CoverageResults.write_results_file)r)r*r+r!rPrDrvrdrrrr	r�s	VcCs@i}x3tj|�D]"\}}||krd||<qW|S)z:Return dict where keys are lines in the line number table.r)�disZfindlinestarts)�code�strs�linenosrrrkrrr	�_find_lines_from_code�s
r�cCsLt||�}x6|jD]+}tj|�r|jt||��qW|S)z<Return lineno dict for all code objects reachable from code.)r��	co_consts�inspectZiscoderD�_find_lines)r�r�r��crrr	r��s
r�c
Cs�i}tj}t|d|���}tj|j�}x�|D]y\}}}}	}
|tjkr�|tjkr�|\}}|	\}
}x%t||
d�D]}d||<q�W|}q=WWdQRX|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.
    rqrN)�token�INDENTrAra�generate_tokensrc�STRING�range)r%rqrZ
prev_ttyperK�tokZttypeZtstr�start�endrZslineZscolZelineZecol�irrr	�
_find_strings�s	r�cCs�y2tj|��}|j�}|j}WdQRXWnFtk
rz}z&td||fdtj�iSWYdd}~XnXt||d�}t	||�}t
||�S)zAReturn dict where keys are line numbers in the line number table.Nz%Not printing coverage data for %r: %sr;�exec)rarA�readrqrFrIrrJ�compiler�r�)r%rK�progrqrLr�r�rrr	r]�sr]c@s�eZdZddddffddddd�	Zdd�Zddd	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)rrrNFc

Cs||_||_t||�|_i|_i|_d|_||_i|_i|_	i|_
d|_|	r~t�|_|r�|j
|_n�|r�|j|_nr|r�|r�|j|_|j|_nK|r�|j|_|j|_n*|r|j|_|j|_n	d|_dS)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
        rNr)r@rr�ignorer<Zpathtobasename�	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)
rrmr��
countfuncs�countcallers�
ignoremods�
ignoredirsr@r�timingrrr	r!�s6										zTrace.__init__cCs,ddl}|j}|j|||�dS)Nr)�__main__�__dict__�runctx)r�cmdr��dictrrr	�run�s	z	Trace.runc
Csf|dkri}|dkr$i}|js:t|j�zt|||�Wd|jsat�XdS)N)r�r
r�r�r
)rr��globals�localsrrr	r��s	
	zTrace.runctxcOsPd}|jstj|j�z|||�}Wd|jsKtjd�X|S)N)r�rrr�)rr�args�kw�resultrrr	�runfuncs		z
Trace.runfuncc
CsP|j}|j}|r't|�}nd}|j}d}||jkrn|j|dk	r'|j|}n�d|j|<dd�tj|�D�}t|�dkr'dd�tj|d�D�}t|�dkr'dd�tj|d�D�}	t|	�dkr'|	dj}||j|<|dk	rCd||f}|||fS)NcSs%g|]}tj|�r|�qSr)r�Z
isfunction)rrKrrr	rs	z1Trace.file_module_function_of.<locals>.<listcomp>rcSs%g|]}t|t�r|�qSr)�
isinstancer�)rrrrr	r#s	rcSs%g|]}t|d�r|�qS)�	__bases__)�hasattr)rr�rrr	r&s	z%s.%s)	�f_code�co_filenamer0�co_namer��gcZ
get_referrersr3r))
r�framer�r%r&riZclsnameZfuncsZdicts�classesrrr	�file_module_function_ofs,			
  

zTrace.file_module_function_ofcCsD|dkr@|j|�}|j|j�}d|j||f<dS)zkHandler for call events.

        Adds information about who called who to the self._callers dict.
        �callrN)r��f_backr�)rr��why�arg�	this_funcZparent_funcrrr	r�5szTrace.globaltrace_trackcallerscCs,|dkr(|j|�}d|j|<dS)zoHandler for call events.

        Adds (filename, modulename, funcname) to the self._calledfuncs dict.
        r�rN)r�r�)rr�r�r�r�rrr	r�@szTrace.globaltrace_countfuncscCs�|dkr�|j}|jjdd�}|r�t|�}|dk	r�|jj||�}|s�|jr�td||jf�|j	SndSdS)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_globalsrQr0r�r(r�rIr�r�)rr�r�r�r�r%r&Z	ignore_itrrr	r�Is		
zTrace.globaltrace_ltcCs�|dkr�|jj}|j}||f}|jj|d�d|j|<|jrttdt�|jdd�tj	j
|�}td||tj||�fdd�|j
S)	Nrrrz%.2fr�� z
%s(%d): %sr1)r�r��f_linenor<rQr�rIr�rrr,r^�getliner�)rr�r�r�r%rkrS�bnamerrr	r�`s	 	z Trace.localtrace_trace_and_countcCs�|dkr�|jj}|j}|jrHtdt�|jdd�tjj|�}td||t	j
||�fdd�|jS)Nrz%.2fr�r�z
%s(%d): %sr1)r�r�r�r�rIr�rrr,r^r�r�)rr�r�r�r%rkr�rrr	r�os		zTrace.localtrace_tracecCsT|dkrM|jj}|j}||f}|jj|d�d|j|<|jS)Nrrr)r�r�r�r<rQr�)rr�r�r�r%rkrSrrr	r�|s	 zTrace.localtrace_countc
Cs1t|jd|jd|jd|jd|j�S)Nr@rr>r?)rr<r@rr�r�)rrrr	�results�s		z
Trace.results)r)r*r+r!r�r�r�r�r�r�r�r�r�r�r�rrrr	r�s0)	
cCs2tjjdtjd|f�tjd�dS)Nz%s: %s
rr)rrJrr�exit)�msgrrr	�	_err_exit�s!r�c#Cs,ddl}|dkr!tj}yV|j|dd�ddddddd	d
ddd
dddddg�\}}Wnq|jk
r�}zNtjjdtjd|f�tjjdtjd�tjd�WYdd}~XnXd}d}d}d}d}	d}
g}g}d}
d}d}d}d}x�|D]�\}}|dkrrttj�tjd�|dkr�tjjd�tjd�|dks�|dkr�d}q@|dks�|dkr�d}q@|dks�|dkr�d}q@|d ks|d!krd}q@|d"ks7|d#kr@d}q@|d$ksX|d%krad}q@|d&ksy|d'kr�d}q@|d(ks�|d)kr�|}	q@|d*ks�|d+kr�d}
q@|d,ks�|d-kr�|}
q@|d.ks�|d/krd}q@|d0krBx*|j	d1�D]}|j
|j��q"Wq@|d2kr@x�|j	tj
�D]�}tjj|�}|jd3tjjtjd4d5tjdd6���}|jd7tjjtjd4d5tjdd6���}tjj|�}|j
|�qaWq@q@W|r/|s%|r/td8�|pJ|pJ|pJ|pJ|sWtd9�|rm|rmtd:�|r�|	r�td;�|r�t|�dkr�td<�|r�td=|	d>|	�}|j|
d
|d?|
�nK|t_|d}tjj	|�dtjd<t||d@|dA|dB|dC|d=|	d>|	d|�}yct|��}t|j�|dD�}WdQRXdE|dFdGdHddIdi}|j|||�WnQtk
r�}z tdJtjd|f�WYdd}~Xnt k
r�YnX|j!�}|s(|j|
d
|d?|
�dS)KNrrztcrRf:d:msC:lTg�help�versionr�rm�reportz	no-reportrgzfile=�missingzignore-module=zignore-dir=z	coverdir=�	listfuncsZ
trackcallsr�z%s: %s
z%Try `%s --help' for more information
Fz--helpz	--versionz
trace 2.0
z-Tz--trackcallsTz-lz--listfuncsz-gz--timingz-tz--tracez-cz--countz-rz--reportz-Rz--no-reportz-fz--filez-mz	--missingz-Cz
--coverdirz-sz	--summaryz--ignore-module�,z--ignore-dirz$prefix�lib�python�z$exec_prefixz8cannot specify both --listfuncs and (--trace or --count)zLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallsz,cannot specify both --report and --no-reportz--report requires a --filezmissing name of file to runr@rrhr�r�r�r�r�r�r)r��__package__�
__cached__zCannot run file %r because: %s)"�getoptrr�errorrJrr�r�stdout�split�append�stripr�pathsepr�
expandvarsr5r`�base_prefixr��base_exec_prefixrr�r3rrvrrAr�r�r�rF�
SystemExitr�)rr�ZoptsZ	prog_argvr�r�rmr�Z	no_reportZcounts_filer�Zignore_modulesZignore_dirsrhrgr�r�r�Zopt�valr'�sr�Zprogname�trpr�ZglobsrLrrr	�main�s�		! 


		





	
-
r�cCstdtd�t|�dS)Nz(The trace.usage() function is deprecated�)�_warn�DeprecationWarningr)rrrr	�usage.s
r�c@s"eZdZdddd�ZdS)�IgnoreNcCs'tdtd�tj|||�dS)Nz$The class trace.Ignore is deprecatedr�)r�r�rr!)rrr rrr	r!4s
zIgnore.__init__)r)r*r+r!rrrr	r�3sr�cCstdtd�t|�S)Nz*The trace.modname() function is deprecatedr�)r�r�r0)rrrr	�modname9s
r�cCstdtd�t|�S)Nz.The trace.fullmodname() function is deprecatedr�)r�r�r9)rrrr	�fullmodname>s
r�cCstdtd�t||�S)Nz7The trace.find_lines_from_code() function is deprecatedr�)r�r�r�)r�r�rrr	�find_lines_from_codeCs
r�cCstdtd�t||�S)Nz-The trace.find_lines() function is deprecatedr�)r�r�r�)r�r�rrr	�
find_linesHs
r�cCs tdtd�t|dd�S)Nz/The trace.find_strings() function is deprecatedr�rq)r�r�r�)r%rqrrr	�find_stringsMs
r�cCstdtd�t|�S)Nz:The trace.find_executable_linenos() function is deprecatedr�)r�r�r])r%rrr	�find_executable_linenosRs
r�r�)/�__doc__�__all__r^r�rerr�rar�r�r�rB�warningsrr�Ztimerr�r�ImportErrorrr
r
rr|r�rzrr0r9rr�r�r�r]rr�r�r�r�r�r�r�r�r�r�r)rrrr	�<module>1sX
	-2�
��