ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python34/lib64/python3.4/__pycache__/trace.cpython-34.pyc

�
e f�z�@sldZddgZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
ZyddlmZWn"ek
r�ddlmZYnXyddlZWn'ek
rejZdd	�ZYnXd
d�Zdd	�Zd
d�ZdZejd�ZGdd�d�Zdd�Zdd�ZGdd�d�Zdd�Zdd�Z ddd�Z!dd�Z"Gd d�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/d0�Z+dd1d2�Z,d3d4�Z-e.d5krhe%�ndS)6a�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)�	monotonic)�timecCstjd�dS)N)�sys�settrace�r	r	�*/opt/alt/python34/lib64/python3.4/trace.py�_unsettraceHsrcCstj|�tj|�dS)N)�	threadingrr)�funcr	r	r
�	_settraceKs
rcCstjd�tjd�dS)N)rrrr	r	r	r
rOs
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)�outfiler	r	r
�_usageSs*rz#pragma NO COVERz^\s*(#.*)?$c@s.eZdZdddd�Zdd�ZdS)�_IgnoreNcCsT|st�n	t|�|_|s*gndd�|D�|_idd6|_dS)NcSs"g|]}tjj|��qSr	)�os�path�normpath)�.0�dr	r	r
�
<listcomp>�s	z$_Ignore.__init__.<locals>.<listcomp>�z<string>)�set�_mods�_dirs�_ignore)�self�modules�dirsr	r	r
�__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�modrr	r	r
�names�s$




z
_Ignore.names)�__name__�
__module__�__qualname__r"r)r	r	r	r
r�srcCs.tjj|�}tjj|�\}}|S)z-Return a plausible module name for the patch.)rr�basename�splitext)r�baser&�extr	r	r
�_modname�sr1cCs&tjj|�}d}xotjD]d}tjj|�}|j|�r"|t|�tjkr"t|�t|�kr�|}q�q"q"W|r�|t|�dd�}n|}tjj|�\}}|jtjd�}tj	r|jtj	d�}ntjj
|�\}}|jd�S)z,Return a plausible module name for the path.�rNr#)rr�normcaserr$�lenr%�
splitdrive�replace�altsepr.�lstrip)rZcomparepathZlongest�dirr/Zdriver&r0r	r	r
�_fullmodname�s (	r:c@sgeZdZddddddd�Zdd�Zdd�Zdd	dd
d�Zddd
�ZdS)rNcCsY||_|jdkr$i|_n|jj�|_||_|jdkrZi|_n|jj�|_||_|jdkr�i|_n|jj�|_||_||_|jrUyDtjt	|jd��\}}}|j
|j|||��WqUtt
tfk
rQ}z%td|j|fdtj�WYdd}~XqUXndS)N�rbzSkipping counts file %r: %s�file)�counts�copyZcounter�calledfuncs�callers�infiler�pickle�load�open�update�	__class__�OSError�EOFError�
ValueError�printr�stderr)rr=r?rAr@r�errr	r	r
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&r	r	r
�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�keyr	r	r
rE�s						
"

zCoverageResults.updateTFc!Cs�|jr]t�td�|j}x7t|�D]&\}}}td|||f�q0Wn|jr0t�td�d}}	x�t|j�D]�\\}
}}\}
}}|
|kr�t�td|
d�|
}d}	n|
|
kr|	|
krtd|
�|
}	ntd||||f�q�Wni}xH|jD]=\}}|j|i�}||<|j||f||<q@Wi}x�|j�D]}\}}|j|�r�q�n|jd�r�|d
d�}n|d
krt	j
jt	j
j|��}t
|�}n4|}t	j
j|�s8t	j|�nt|�}|rYt|�}ni}tj|�}t	j
j||d�}t|d
��}tj|j�\}}Wd
QX|j|||||�\}}|r�|r�td||�}||||f||<q�q�W|rm|rmtd�x?t|�D].}||\}}}}td||�q8Wn|jr�y5tj|j|j|jft|jd�d�Wq�tk
r�} ztd| dtj �WYd
d
} ~ Xq�Xnd
S)z!
        @param coverdir
        zfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r2z***z  -->z    %s.%s -> %s.%s�.pyc�.pyoNrz.coverr;�dzlines   cov%   module   (path)z%5d   %3d%%   %s   (%s)�wbz"Can't save counts files because %sr<)rTrU���)!r?rJ�sortedr@r=rQ�itemsrPrOrr�dirname�abspathr1�exists�makedirsr:�_find_executable_linenos�	linecache�getlines�joinrD�tokenize�detect_encoding�readline�write_results_file�intrrB�dumprGrrK)!rZshow_missing�summary�coverdirZcallsr&r'�funcnameZlastfileZ	lastcfileZpfileZpmodZpfunc�cfileZcmodZcfuncZper_file�lineno�	lines_hitZsums�countr9�lnotab�sourceZ	coverpath�fp�encoding�_�n_hits�n_linesZpercent�mrLr	r	r
�
write_results
s|	
		

+	
	!
	zCoverageResults.write_resultscCsNyt|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~W|j�|	|fS)
z'Return a coverage results file in path.�wrsz2trace: Could not open %r for writing: %s- skippingr<rNrz%5d: z       z>>>>>> �)rr)rDrGrJrrK�	enumerater�rx_blank�match�PRAGMA_NOCOVER�
expandtabs�close)rr�linesrprnrsrrLrvrurm�liner	r	r
rfbs,





z"CoverageResults.write_results_file)r*r+r,r"rPrErxrfr	r	r	r
r�s	UcCsCi}x6tj|�D]%\}}||krd||<qqW|S)z:Return dict where keys are lines in the line number table.r)�disZfindlinestarts)�code�strs�linenosrtrmr	r	r
�_find_lines_from_code�s
r�cCsOt||�}x9|jD].}tj|�r|jt||��qqW|S)z<Return lineno dict for all code objects reachable from code.)r��	co_consts�inspectZiscoderE�_find_lines)r�r�r��cr	r	r
r��s
r�c
Cs�i}tj}t|d|���}tj|j�}x�|D]\}}}}	}
|tjkr�|tjkr�|\}}|	\}
}x(t||
d�D]}d||<q�Wq�n|}q=WWdQX|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.
    rsrN)�token�INDENTrDrc�generate_tokensre�STRING�range)r&rsrZ
prev_ttype�f�tokZttypeZtstr�start�endr�ZslineZscolZelineZecol�ir	r	r
�
_find_strings�s	r�cCs�y1tj|��}|j�}|j}WdQXWnFtk
ry}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)rcrD�readrsrGrJrrK�compiler�r�)r&r��progrsrLr�r�r	r	r
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�|_n|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)rArr�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)
rror��
countfuncs�countcallers�
ignoremods�
ignoredirsrAr�timingr	r	r
r"�s6										zTrace.__init__cCs,ddl}|j}|j|||�dS)Nr)�__main__�__dict__�runctx)r�cmdr��dictr	r	r
�run�s	z	Trace.runc
Csr|dkri}n|dkr*i}n|jsCt|j�nzt|||�Wd|jsmt�nXdS)N)r�rr�r�r)rr��globals�localsr	r	r
r��s				zTrace.runctxcOsVd}|js"tj|j�nz|||�}Wd|jsQtjd�nX|S)N)r�rrr�)rr
�args�kw�resultr	r	r
�runfuncs		z
Trace.runfuncc
Cs_|j}|j}|r't|�}nd}|j}d}||jkrq|j|dk	r3|j|}q3n�d|j|<dd�tj|�D�}t|�dkr3dd�tj|d�D�}t|�dkr3dd�tj|d�D�}	t|	�dkr0|	dj}||j|<q0q3n|dk	rRd||f}n|||fS)NcSs%g|]}tj|�r|�qSr	)r�Z
isfunction)rr�r	r	r
rs	z1Trace.file_module_function_of.<locals>.<listcomp>rcSs%g|]}t|t�r|�qSr	)�
isinstancer�)rrr	r	r
r%s	rcSs%g|]}t|d�r|�qS)�	__bases__)�hasattr)rr�r	r	r
r(s	z%s.%s)	�f_code�co_filenamer1�co_namer��gcZ
get_referrersr4r*)
r�framer�r&r'rkZclsnameZfuncsZdictsZclassesr	r	r
�file_module_function_ofs,			
  
zTrace.file_module_function_ofcCsG|dkrC|j|�}|j|j�}d|j||f<ndS)zkHandler for call events.

        Adds information about who called who to the self._callers dict.
        �callrN)r��f_backr�)rr��why�arg�	this_funcZparent_funcr	r	r
r�7szTrace.globaltrace_trackcallerscCs/|dkr+|j|�}d|j|<ndS)zoHandler for call events.

        Adds (filename, modulename, funcname) to the self._calledfuncs dict.
        r�rN)r�r�)rr�r�r�r�r	r	r
r�BszTrace.globaltrace_countfuncscCs�|dkr�|j}|jjdd�}|r�t|�}|dk	r�|jj||�}|s�|jr�td||jf�n|j	Sq�q�dSndS)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_globalsrQr1r�r)r�rJr�r�)rr�r�r�r�r&r'Z	ignore_itr	r	r
r�Ks		
zTrace.globaltrace_ltcCs�|dkr�|jj}|j}||f}|jj|d�d|j|<|jrwtdt�|jdd�ntj	j
|�}td||tj||�fdd�n|j
S)	Nr�rrz%.2fr�� z
%s(%d): %sr2)r�r��f_linenor=rQr�rJr�rrr-r`�getliner�)rr�r�r�r&rmrS�bnamer	r	r
r�bs	 	! z Trace.localtrace_trace_and_countcCs�|dkr�|jj}|j}|jrKtdt�|jdd�ntjj|�}td||t	j
||�fdd�n|jS)Nr�z%.2fr�r�z
%s(%d): %sr2)r�r�r�r�rJr�rrr-r`r�r�)rr�r�r�r&rmr�r	r	r
r�qs		! zTrace.localtrace_tracecCsW|dkrP|jj}|j}||f}|jj|d�d|j|<n|jS)Nr�rr)r�r�r�r=rQr�)rr�r�r�r&rmrSr	r	r
r�~s	#zTrace.localtrace_countc
Cs1t|jd|jd|jd|jd|j�S)NrArr?r@)rr=rArr�r�)rr	r	r
�results�s		z
Trace.results)r*r+r,r"r�r�r�r�r�r�r�r�r�r�r�r	r	r	r
r�s0)	
cCs2tjjdtjd|f�tjd�dS)Nz%s: %s
rr)rrKrr�exit)�msgr	r	r
�	_err_exit�s!r�c"Cs�ddl}|dkr$tj}nyV|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]\}}|dkrxttj�tjd�n|dkr�tjjd�tjd�n|dks�|dkr�d}qCn|dks�|dkr�d}qCn|dks|dkrd}qCn|d ks(|d!kr4d}qCn|d"ksL|d#krXd}qCn|d$ksp|d%kr|d}qCn|d&ks�|d'kr�d}qCn|d(ks�|d)kr�|}	qCn|d*ks�|d+kr�d}
qCn|d,ks|d-kr|}
qCn|d.ks$|d/kr0d}qCn|d0krox*|j	d1�D]}|j
|j��qLWqCn|d2kr?x�|j	tj
�D]�}tjj|�}|jd3tjjtjd4d5tjdd6���}|jd7tjjtjd4d5tjdd6���}tjj|�}|j
|�q�WqCndsCtd8��qCW|rt|sg|rttd9�n|p�|p�|p�|p�|s�td:�n|r�|r�td;�n|r�|	r�td<�n|r�t|�dkr�td=�n|r.td>|	d?|	�}|j|
d
|d@|
�nQ|t_|d}tjj	|�dtjd<t||dA|dB|dC|dD|d>|	d?|	d|�}yft|��}t|j�|dE�}WdQXi|dF6dGdH6ddI6ddJ6}|j|||�WnQt k
r?}z tdKtjd|f�WYdd}~Xnt!k
rPYnX|j"�}|s|j|
d
|d@|
�ndS)LNrrztcrRf:d:msC:lTg�help�versionr�ro�reportz	no-reportrizfile=�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_prefixzShould never get herez8cannot 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 runrArrjr�r�r�r�r�r�r�r*�__package__�
__cached__zCannot run file %r because: %s)#�getoptrr�errorrKrr�r�stdout�split�append�stripr�pathsepr�
expandvarsr6rb�base_prefixr��base_exec_prefixr�AssertionErrorr�r4rrxrrDr�r�r�rG�
SystemExitr�)rr�ZoptsZ	prog_argvr�r�ror�Z	no_reportZcounts_filer�Zignore_modulesZignore_dirsrjrir�r�r�Zopt�valr(�sr�Zprogname�trrr�ZglobsrLr	r	r
�main�s�	! 
		





	

-
r�cCstdtd�t|�dS)Nz(The trace.usage() function is deprecated�)�_warn�DeprecationWarningr)rr	r	r
�usage0s
r�c@s"eZdZdddd�ZdS)�IgnoreNcCs'tdtd�tj|||�dS)Nz$The class trace.Ignore is deprecatedr�)r�r�rr")rr r!r	r	r
r"6s
zIgnore.__init__)r*r+r,r"r	r	r	r
r�5sr�cCstdtd�t|�S)Nz*The trace.modname() function is deprecatedr�)r�r�r1)rr	r	r
�modname;s
r�cCstdtd�t|�S)Nz.The trace.fullmodname() function is deprecatedr�)r�r�r:)rr	r	r
�fullmodname@s
r�cCstdtd�t||�S)Nz7The trace.find_lines_from_code() function is deprecatedr�)r�r�r�)r�r�r	r	r
�find_lines_from_codeEs
r�cCstdtd�t||�S)Nz-The trace.find_lines() function is deprecatedr�)r�r�r�)r�r�r	r	r
�
find_linesJs
r�cCs tdtd�t|dd�S)Nz/The trace.find_strings() function is deprecatedr�rs)r�r�r�)r&rsr	r	r
�find_stringsOs
r�cCstdtd�t|�S)Nz:The trace.find_executable_linenos() function is deprecatedr�)r�r�r_)r&r	r	r
�find_executable_linenosTs
r�r�)/�__doc__�__all__r`r�rerr�rcr�r�r�rB�warningsrr�rrr��ImportErrorrrrrrr~r�r|rr1r:rr�r�r�r_rr�r�r�r�r�r�r�r�r�r�r*r	r	r	r
�<module>1s^

	-2�
��

Zerion Mini Shell 1.0