CasperSecurity

Current Path : /usr/lib/python3.10/__pycache__/
Upload File :
Current File : //usr/lib/python3.10/__pycache__/trace.cpython-310.pyc

o

`�wir�@s�dZddgZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlZdZGdd�d�Zd	d
�Zdd�ZGd
d�d�Zdd�Zdd�Zddd�Zdd�ZGdd�d�Zdd�Zedkrye�dSdS)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@seZdZddd�Zdd�ZdS)�_IgnoreNcCs:|st�nt|�|_|sgndd�|D�|_ddi|_dS)NcSsg|]}tj�|��qS�)�os�path�normpath��.0�drr�/usr/lib/python3.10/trace.py�
<listcomp>Hs�z$_Ignore.__init__.<locals>.<listcomp>z<string>�)�set�_mods�_dirs�_ignore)�self�modules�dirsrrr
�__init__Fs
�z_Ignore.__init__cCs�||jvr
|j|S||jvrd|j|<dS|jD]}|�|d�r*d|j|<dSq|dur6d|j|<dS|jD]}|�|tj�rKd|j|<dSq9d|j|<dS)Nr�.r)rr�
startswithrr�sep)r�filename�
modulename�modrrrr
�namesLs(





�


�
z
_Ignore.names�NN)�__name__�
__module__�__qualname__rrrrrr
rEs
rcCs tj�|�}tj�|�\}}|S)�,Return a plausible module name for the path.)rr�basename�splitext)r�baser�extrrr
�_modnamewsr(cCs�tj�|�}d}tjD] }tj�|�}|�|�r+|t|�tjkr+t|�t|�kr+|}q|r9|t|�dd�}n|}tj�|�\}}|�tjd�}tj	rT|�tj	d�}tj�
|�\}}|�d�S)r#�rNr)rr�normcase�sysr�lenr�
splitdrive�replace�altsepr%�lstrip)r�comparepath�longest�dirr&�driverr'rrr
�_fullmodname~s"
�
r5c@s>eZdZ		ddd�Zdd�Zdd�Zdd
d�Zddd
�ZdS)rNc
Cs||_|jduri|_|j��|_||_|jduri|_|j��|_||_|jdur-i|_|j��|_||_||_|jr�z,t|jd��}t�	|�\}}}Wd�n1sVwY|�
|j|||d��WdStt
tfy�}ztd|j|ftjd�WYd}~dSd}~wwdS)N�rb)�callerszSkipping counts file %r: %s��file)�counts�copy�counter�calledfuncsr7�infile�outfile�open�pickle�load�update�	__class__�OSError�EOFError�
ValueError�printr+�stderr)rr:r=r>r7r?�f�errrrr
r�s:


������zCoverageResults.__init__cCs|�d�o	|�d�S)z_Return True if the filename does not refer to a file
        we want to have reported.
        �<�>)r�endswith)rrrrr
�is_ignored_filename�sz#CoverageResults.is_ignored_filenamec	Csn|j}|j}|j}|j}|j}|j}|D]}|�|d�||||<q|D]}d||<q%|D]}d||<q.dS)z.Merge in the data from another CoverageResultsrrN)r:r=r7�get)	r�otherr:r=r7�other_counts�other_calledfuncs�
other_callers�keyrrr
rC�s

�zCoverageResults.updateTFc"
Cs|jr t�td�|j}t|�D]\}}}td|||f�q|jrht�td�d}}	t|j�D]4\\}
}}\}
}}|
|krNt�td|
d�|
}d}	|
|
kr]|	|
kr]td|
�|
}	td||||f�q3i}|jD]\}}|�|i�}||<|j||f||<qmi}|��D]�\}}|�|�r�q�|�d�r�|d	d
�}|d	ur�t	j
�t	j
�|��}t
|�}n|}t	j
�|�s�t	�|�t|�}|r�t|�}ni}t�|�}t	j
�||d�}t|d��}t�|j�\}}Wd	�n1s�wY|�|||||�\}}|�r|�rtd
||�}||||f||<q�|�r<|�r<td�t|�D]}||\}}}}td||��q(|j�r�z)t|jd��} t�|j|j|jf| d�Wd	�Wd	S1�sbwYWd	St�y�}!ztd|!tj d�WYd	}!~!d	Sd	}!~!wwd	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.
        zfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r)z***z  -->z    %s.%s -> %s.%sz.pycN���z.coverr6�dzlines   cov%   module   (path)z%5d   %3d%%   %s   (%s)�wbrz"Can't save counts files because %sr8)!r=rH�sortedr7r:rP�itemsrOrNrr�dirname�abspathr(�exists�makedirsr5�_find_executable_linenos�	linecache�getlines�joinr@�tokenize�detect_encoding�readline�write_results_file�intr?rA�dumprEr+rI)"r�show_missing�summary�coverdir�callsrr�funcname�lastfile�	lastcfile�pfile�pmod�pfunc�cfile�cmod�cfunc�per_file�lineno�	lines_hit�sums�countr3�lnotab�source�	coverpath�fp�encoding�_�n_hits�n_lines�percent�mrJrKrrr
�
write_results�s�
��






����(� ���zCoverageResults.write_resultsc
Csz	t|d|d�}Wnty'}ztd||ftjd�WYd}~dSd}~wwd}d}	|�Jt|d�D]9\}
}|
|vrN|�d	||
�|	d7}	|d7}n|
|vr`t|vr`|�d
�|d7}n|�d�|�|�d��q4Wd�|	|fS1s{wY|	|fS)
z'Return a coverage results file in path.�w�rz3trace: Could not open %r for writing: %s - skippingr8N)rrrrz%5d: z>>>>>> z       �)	r@rErHr+rI�	enumerate�write�PRAGMA_NOCOVER�
expandtabs)rr�linesr{rxrr?rKr�r�rw�linerrr
rf)s:����



�
��z"CoverageResults.write_results_file)NNNNN)TFN�N)r r!r"rrOrCr�rfrrrr
r�s
�
\cCs,i}t�|�D]\}}||vrd||<q|S)z:Return dict where keys are lines in the line number table.r)�dis�findlinestarts)�code�strs�linenosr�rwrrr
�_find_lines_from_codeIs�r�cCs4t||�}|jD]}t�|�r|�t||��q|S)z<Return lineno dict for all code objects reachable from code.)r��	co_consts�inspect�iscoderC�_find_lines)r�r�r��crrr
r�Ss


�r�cCs�i}tj}t||d��;}t�|j�}|D])\}}}}	}
|tjkr;|tjkr;|\}}|	\}
}t||
d�D]}d||<q4|}qWd�|S1sIwY|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.
    r�rN)�token�INDENTr@rc�generate_tokensre�STRING�range)rrr�
prev_ttyperJ�tok�ttype�tstr�start�endr��sline�scol�eline�ecol�irrr
�
_find_strings_s"


�
�
�
r�c
Cs�zt�|��}|��}|j}Wd�n1swYWnty=}ztd||ftjd�iWYd}~Sd}~wwt||d�}t	||�}t
||�S)zAReturn dict where keys are line numbers in the line number table.Nz%Not printing coverage data for %r: %sr8�exec)rcr@�readrrErHr+rI�compiler�r�)rrJ�progrrKr�r�rrr
r_vs$������

r_c@sveZdZ			ddd�Zdd	�Zdd
d�Zdd
�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS) rrrrNFc

Cs�||_||_t||�|_i|_i|_d|_||_i|_i|_	i|_
d|_|	r*t�|_|r2|j
|_dS|r:|j|_dS|rH|rH|j|_|j|_dS|rT|j|_|j|_dS|r`|j|_|j|_dSd|_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>r?r�ignorer:�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)
rrzr��
countfuncs�countcallers�
ignoremods�
ignoredirsr>r?�timingrrr
r�s6
zTrace.__init__cCs ddl}|j}|�|||�dS)Nr)�__main__�__dict__�runctx)r�cmdr��dictrrr
�run�sz	Trace.runc	Cs�|duri}|duri}|jst�|j�t�|j�zt|||�W|js2t�d�t�d�dSdS|jsBt�d�t�d�wwr�)r��	threading�settracer�r+r�)rr��globals�localsrrr
r��s

�
�zTrace.runctxc	OsPd}|jst�|j�z||i|��}W|jst�d�|S|js't�d�wwr�)r�r+r�r�)r�func�args�kw�resultrrr
�runfunc�s
��z
Trace.runfuncc
Cs�|j}|j}|r
t|�}nd}|j}d}||jvr&|j|dur%|j|}nCd|j|<dd�t�|�D�}t|�dkridd�t�|d�D�}t|�dkridd�t�|d�D�}	t|	�dkri|	dj}||j|<|dursd||f}|||fS)NcSsg|]	}t�|�r|�qSr)r��
isfunction)rrJrrr
r��
�z1Trace.file_module_function_of.<locals>.<listcomp>rcSsg|]	}t|t�r|�qSr)�
isinstancer�r
rrr
r�r�rcSsg|]	}t|d�r|�qS)�	__bases__)�hasattr)rr�rrr
r�r�z%s.%s)	�f_code�co_filenamer(�co_namer��gc�
get_referrersr,r )
r�framer�rrrm�clsname�funcs�dicts�classesrrr
�file_module_function_of�s.


�



zTrace.file_module_function_ofcCs4|dkr|�|�}|�|j�}d|j||f<dSdS)zkHandler for call events.

        Adds information about who called who to the self._callers dict.
        �callrN)r��f_backr�)rr��why�arg�	this_func�parent_funcrrr
r��s

�zTrace.globaltrace_trackcallerscCs$|dkr|�|�}d|j|<dSdS)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_countfuncscCsp|dkr6|j}|j�dd�}|r4t|�}|dur0|j�||�}|s2|jr-td||jf�|j	SdSdSdSdS)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_globalsrPr(r�rr�rHr�r�)rr�r�r�r�rr�	ignore_itrrr
r�s"���zTrace.globaltrace_ltcCs�|dkr?|jj}|j}||f}|j�|d�d|j|<|jr*tdt�|jdd�tj	�
|�}td||t�||�fdd�|j
S)	Nr�rr�%.2f� �r��
%s(%d): %sr))r�r��f_linenor:rPr�rHr�rrr$r`�getliner�)rr�r�r�rrwrU�bnamerrr
r�(s
��z Trace.localtrace_trace_and_countcCsd|dkr/|jj}|j}|jrtdt�|jdd�tj�|�}td||t	�
||�fdd�|jS)Nr�r�r�r�r�r))r�r�r�r�rHr�rrr$r`r�r�)rr�r�r�rrwr�rrr
r�7s
��zTrace.localtrace_tracecCs<|dkr|jj}|j}||f}|j�|d�d|j|<|jS)Nr�rr)r�r�r�r:rPr�)rr�r�r�rrwrUrrr
r�DszTrace.localtrace_countcCst|j|j|j|j|jd�S)N)r>r?r=r7)rr:r>r?r�r�)rrrr
�resultsLs

�z
Trace.results)	rrrrrrNNFr)r r!r"rr�r�r�r�r�r�r�r�r�r�r�rrrr
r�s 
�2

)	
cs�ddl}|��}|jdddd�|�dd�}|jdd	d
dd�|jd
dd
dd�|jddd
dd�|jddd
dd�|�d�}|��}|jddd
dd�|jddd
dd�|jdddd �|jd!d"d#d �|jd$d%d
d&d�|jd'd(d
d)d�|jd*d+d
d,d�|�d-d.�}|jd/d0gd1d2�|jd3d0gd4d2�|jd5d
d6d7d2�|jd8d9d:d;�|jd<|jd=d;�|��}|jr�t�	d>��t�	d?����fd@dA��dBdC�|j
D�|_
�fdDdC�|jD�|_|jr�|js�|�
dE�t|j|jdF�}|�|j|j|j�St|j|j|j|jg��s
|�
dG�|j�r|j�s|j�r|�
dH�|j�r+|j�s+|�
dI�|jdu�r6|�
dJ�t|j|j|j|j|j
|j|j|j|jdK�	}zk|j�ruddl}|j}|�|�\}	}
}|jg|j�t _!dL|j|
j"|
j#|
ddM�}n:|jg|j�t _!t$j%�&|j�t j%d<t'�(|j��}
t)|
�*�|jdN�}Wd�n	1�s�wY|jdLdddO�}|�+|||�Wn(t,�y�}zt �-dPt j!d|f�WYd}~nd}~wt.�y�Ynw|�/�}|j0�s�|�|j|j|j�dSdS)QNrz	--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.�	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 tracing�FilterszCan 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--moduleFzTrace a module. �progname�?zfile to run as main program)�nargsr��	argumentszarguments to the program�stdlib�
platstdlibcs4tj�tj�|��}|�d���d��}tj�|�S)Nz$prefixz$exec_prefix)rr�
expanduser�
expandvarsr.r	)�s)�_exec_prefix�_prefixrr
�parse_ignore_dir�szmain.<locals>.parse_ignore_dircSs$g|]}|�d�D]}|���q	qS)�,)�split�strip)rr�rrrr
r�s

��zmain.<locals>.<listcomp>cs&g|]}|�tj�D]}�|��q
qSr)rr�pathsep)rr�r)r	rr
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 --reportz3progname is missing: required with the main options)r�r�r�r�r>r?r�r�)r r��__package__�
__loader__�__spec__�
__cached__r�)r�r rrzCannot run file %r because: %s)1�argparse�ArgumentParser�add_argument�add_argument_group�add_mutually_exclusive_group�	REMAINDER�
parse_args�
ignore_dir�	sysconfig�get_path�
ignore_module�reportr9�errorrr��missingrjrk�anyr�rz�	listfuncs�
trackcallsr�rr��module�runpy�_get_module_detailsr�rr+�argv�parent�loaderrrr[�io�	open_coder�r�r�rE�exit�
SystemExitr��	no_report)r�parser�grp�_grp�optsr��tr$�module_name�mod_name�mod_specr��globsr~rKr)rrr	r
�mainRs��
�
�
�
�

�
���
�
�
��
�
�
��
�

�
�




��	��$���r7r�r�)�__doc__�__all__r)r`rr+rr�rcr�r�r�rA�timerr�r�r�rr(r5rr�r�r�r_rr7r rrrr
�<module>s@20

O
�
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY