grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j-rã@södZddgZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlZdZGdd„dƒZd d „Zd d „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ú,/opt/alt/python310/lib64/python3.10/trace.pyÚ Hsÿz$_Ignore.__init__..zé)Ú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)rZ comparepathZlongestÚdirr&Zdriverr'rrr Ú _fullmodname~s"   € r2c@s>eZdZ  ddd„Zdd„Zdd„Zdd d „Zdd d „ZdS)rNc Cs||_|jdur i|_|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ÚcopyZcounterÚ calledfuncsr4ÚinfileÚoutfileÚopenÚpickleÚloadÚupdateÚ __class__ÚOSErrorÚEOFErrorÚ ValueErrorÚprintr+Ústderr)rr7r9r:r4r;Ú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)r7r9r4Úget) rÚotherr7r9r4Z other_countsZother_calledfuncsZ other_callersÚkeyrrr r?»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<|�rz %s.%s -> %s.%sz.pycNéÿÿÿÿz.coverr3édzlines cov% module (path)z%5d %3d%% %s (%s)Úwbrz"Can't save counts files because %sr5)!r9rDÚsortedr4r7rLÚitemsrKrJrrÚdirnameÚabspathr(ÚexistsÚmakedirsr2Ú_find_executable_linenosÚ linecacheÚgetlinesÚjoinr<ÚtokenizeÚdetect_encodingÚreadlineÚwrite_results_fileÚintr;r=ÚdumprAr+rE)"rZ show_missingÚsummaryÚcoverdirZcallsrrÚfuncnameZlastfileZ lastcfileZpfileZpmodZpfuncÚcfileZcmodZcfuncZper_fileÚlinenoÚ lines_hitZsumsÚcountr1ÚlnotabÚsourceZ coverpathÚfpÚencodingÚ_Ún_hitsÚn_linesZpercentÚmrFrGrrr Ú 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©rlz3trace: Could not open %r for writing: %s - skippingr5N)rrrrz%5d: z>>>>>> z é) r<rArDr+rEÚ enumerateÚwriteÚPRAGMA_NOCOVERÚ expandtabs) rrÚlinesrirgrlr;rGrornrfÚlinerrr r_)s:ÿÿ€ý    ò ÿïz"CoverageResults.write_results_file)NNNNN)TFN©N)r r!r"rrKr?rqr_rrrr ršs ÿ \cCs,i}t |¡D] \}}||vrd||<q|S)z:Return dict where keys are lines in the line number table.r)ÚdisZfindlinestarts)ÚcodeÚstrsÚlinenosrmrfrrr Ú_find_lines_from_codeIs €r€cCs4t||ƒ}|jD]}t |¡r| t||ƒ¡q|S)z.rcSsg|] }t|tƒr|‘qSr)Ú isinstancer¬r rrr rër·rcSsg|] }t|dƒr|‘qS)Ú __bases__)Úhasattr)r r„rrr rîr·z%s.%s) Úf_codeÚ co_filenamer(Úco_namer˜ÚgcZ get_referrersr,r ) rÚframer}rrrdZclsnameZfuncsZdictsZclassesrrr Ú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_funcZ 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_globalsrLr(r“rr•rDr½r )rr¿rÃrÄr}rrZ ignore_itrrr ržs"ÿúñzTrace.globaltrace_ltcCs„|dkr?|jj}|j}||f}|j |d¡d|j|<|jr*tdtƒ|jdd�tj   |¡}td||t   ||¡fdd�|j S) Nrzrrú%.2fú ©rŒú %s(%d): %sr))r»r¼Úf_linenor7rLr™rDršrrr$rYÚgetliner )rr¿rÃrÄrrfrNÚbnamerrr rŸ(s  ÿÿz Trace.localtrace_trace_and_countcCsd|dkr/|jj}|j}|jrtdtƒ|jdd�tj |¡}td||t   ||¡fdd�|j S)NrzrÈrÉrÊrËr)) r»r¼rÌr™rDršrrr$rYrÍr )rr¿rÃrÄrrfrÎrrr r¡7s  ÿÿzTrace.localtrace_tracecCs<|dkr|jj}|j}||f}|j |d¡d|j|<|jS)Nrzrr)r»r¼rÌr7rLr )rr¿rÃrÄrrfrNrrr r¢Ds zTrace.localtrace_countcCst|j|j|j|j|jd�S)N)r:r;r9r4)rr7r: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   )   c sìddl}| ¡}|jdddd�| dd¡}|jdd d d d �|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ƒ|_|j rû|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 .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 . will be written to file //.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 tracingZFilterszCan 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 programZstdlibZ platstdlibcs4tj tj |¡¡}| dˆ¡ dˆ¡}tj |¡S)Nz$prefixz $exec_prefix)rrÚ expanduserÚ expandvarsr.r )Ús)Ú _exec_prefixÚ_prefixrr Úparse_ignore_dir�s zmain..parse_ignore_dircSs$g|]}| d¡D]}| ¡‘q qS)ú,)ÚsplitÚstrip)r r�rrrr r¢s  ÿÿzmain..cs&g|]}| tj¡D]}ˆ|ƒ‘q qSr)rárÚpathsep)r r�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 rärçzCannot run file %r because: %s)1ÚargparseÚArgumentParserÚ add_argumentZadd_argument_groupZadd_mutually_exclusive_groupZ REMAINDERÚ parse_argsZ ignore_dirÚ sysconfigZget_pathZ ignore_moduleZreportr6ÚerrorrrqZmissingrbrcÚanyr•rhZ listfuncsZ trackcallsrÖrr§ÚmoduleÚrunpyZ_get_module_detailsr¼rÙr+ÚargvÚparentÚloaderrrrTÚioÚ open_coder‘r�rªrAÚexitÚ SystemExitrÏZ no_report)rèÚparserZgrpZ_grpZoptsrÏÚtrðZ module_nameZmod_nameZmod_specr}ZglobsrkrGr)rÝrÞrßr ÚmainRsôÿ ÿ ÿ ÿ ÿ  ÿ ÿÿÿ ÿ ÿ ÿÿ ÿ ÿ ÿÿ ÿ  ÿ ÿ      ýú ÿü$€ÿÿrúr¨r{)Ú__doc__Ú__all__rôrYrr+rìr…r\r‚r¾r|r=Útimerršr®rwrr(r2rr€rƒrŽrXrrúr rrrr Ús@ 20 O ÿ