Hz/?pUdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZmZmZmZmZmZmZmZmZmZddlmZmZddlmZeeZgZde d<dZ!Gd d Z"Gd d e"Z#Gd de"Z$dRdZ%dSdZ&dTdZ'dUdVd Z( dWdXd#Z)dYdZd'Z*d[d)Z+d\d*Z,Gd+d,Z-d]d/Z.d^d0Z/d_d3Z0Gd4d5Z1Gd6d7Z2d`dad<Z3 dbdcdCZ4dddEZ5ej6Z7ej6Z8dFZ9 dedfdKZ:dgdMZ;dhdQZ)rr)r*s r+__repr__zDebugControl.__repr__AsX XXDOXXXXr-optionboolc2|dkr |jrdS||jvS)z@Decide whether to output debug information in category `option`.callersF)r"rr*r3s r+r#zDebugControl.shouldDs' Y  4#8 5$,&'r-Iterator[None]c#VK|j}d|_ dV||_dS#||_wxYw)z;A context manager to prevent call stacks from being logged.TN)r")r*olds r+without_callerszDebugControl.without_callersJsH# $ ( EEE$'D ! ! !CD ! ' ' ' 's (msgc|j|dz|drWtjddjd}||jd|d|drt|jd|jdS) zhWrite a line of debug output. `msg` is the line to write. A newline will be appended.  r*rNzself: r6outskip) rwriter#inspectstackf_localsgetdump_stack_framesflush)r*r< caller_selfs r+rCzDebugControl.writeTs #d(### ;;v   >!-//!,Q/8<z!info_formatter..s233das1vv !333333r-z-none-z%*s: %rz%*s:z%*s %sr?z%*s: %s)r!all isinstancetuplerureprset)roridataprefixerys @r+info_formatterrsI ::D I 3333d333 3 333 3 7 7 t 2::D dE " " 7s4d +<+<'='='B'By%t== = = = = tS%0 1 1 7y%00F  )A+vq!99999 y%66 6 6 6 6 7 7r-rCCallable[[str], None]headerrcv|t|t|D]}|d|dS)a,Write a sequence of (label,data) pairs nicely. `write` is a function write(str) that accepts each line of output. `header` is a string to start the section. `info` is a sequence of (label, data) pairs, where label is a str, and data can be a single value, or a list/set/tuple. rkN)rnr)rCrrolines r+write_formatted_inforsV E+f  t$$ j$jjr-limit Optional[int]rBintcxtj||d}dd|DS)aReturn a string summarizing the call stack. The string is multi-line, with one line per stack frame. Each line shows the function name, the file name, and the line number: ... start_import_stop : /Users/ned/coverage/trunk/tests/coveragetest.py @95 import_local_file : /Users/ned/coverage/trunk/tests/coveragetest.py @81 import_local_file : /Users/ned/coverage/trunk/coverage/backward.py @159 ... `limit` is the number of frames to include, defaulting to all of them. `skip` is the number of frames to skip, so that debugging functions can call this and not be included in the result. r>c3JK|]}d|d|d|dfzVdS)z %30s : %s:%dr?NrV)rvts r+rzzshort_stack..s:HHQ^qtQqT1Q4&88HHHHHHr-)rDrEjoin)rrBrEs r+ short_stackrs;$ MOOE$rM *E 99HH%HHH H HHr-rAOptional[TWritable]c|p tj}|t||dz|ddS)z:Print a summary of the stack to stdout, or someplace else.r?)rrBr>N)sysstdoutrCr)rrArBfouts r+rHrHsK  #*DJJ{T!V444555JJtr-2textnumcharsc`tj}||_||S)z(`repr(text)`, but limited to `numchars`.)reprlibRepr maxstringr)rrrs r+ clipped_reprrs$ AAK 66$<<r-id64cHd}tdddD] }|||z z} |dzS)z-Given a 64-bit id, make a shorter 16-bit one.r@i)range)rid16offsets r+short_idrs< D2r""  &=r-cttjd}tjdd|d|}|S)z.A filter to add pid and tid to debug messages.04x5d.z: )r_thread get_identosgetpid)rtids r+r%r%sIg')) * * 0 0Cikk , , ,s , ,d , ,D Kr-c"eZdZdZddgZddZdS) AutoReprMixinz9A mixin implementing an automatic __repr__ for debugging.auto_repr_ignore$coverage.object_idrr.cfdjD}djjt dd|DS)Nc3xK|]4\}}t|ddrt|s|jv.||fV5dS)rSTN)getattrcallabler)rvkvr*s r+rzz)AutoReprMixin.__repr__..sn  q!q*D11 QKK ...F/...   r-z<{klass} @0x{id:x} {attrs}>rkc3*K|]\}}|d|VdS)=NrVrvrrs r+rzz)AutoReprMixin.__repr__..s0??DAqa<Turn things which are nearly dict/list/etc into dict/list/etc.c4i|]\}}|t|SrVsimplify)rvrvvs r+ zsimplify..s$66651b(2,,666r-c34K|]}t|VdSrKr)rvrs r+rzzsimplify..s(00x||000000r-rc i|] \}}d|z| S)rrVrs r+rzsimplify..s"AAAdaQAAAr-) r}dictrr!r~typehasattrrrrs r+rrs!T66AGGII6666 Ae} % %tAww00a000000 J  AAaj.>.>.@.@AAABBBr-cHtjt|dS)zEDebug helper to pretty-print data, including SimpleNamespace objects.N)pprintrrs r+pprs  M(1++r-r Iterable[Callable[[str], str]]c,|}|t|d}|}|D]`}g}|D]2}|||3d|}a||zS)zRun `text` through a series of filters. `filters` is a list of functions. Each takes a string and returns a string. Each is run in turn. Returns: the final string that results after all of the filters have run. Nr>)rstripru splitlinesextendr)rr clean_textendingfnlinesrs r+ filter_textr sJ #j//"" #F D  OO%% 0 0D LLD,,.. / / / /yy &=r-c"eZdZdZd dZd dZdS) CwdTrackerz*A class to add cwd info to debug messages.rrcd|_dSrK)cwdr1s r+r,zCwdTracker.__init__"s "&r-rr.cbtj}||jkrd|d|z}||_|S)z#Add a cwd message for each new cwd.z cwd is now r>)rgetcwdr)r*rrs r+filterzCwdTracker.filter%s9ikk $(??****T1DDH r-Nrhrr.rr.)rOrPrQrRr,rrVr-r+rr sB44''''r-rceZdZdZddZe d d!dZdZdZed"dZ ed#dZ ed$dZ d%dZ d$dZ d S)&r&z9A file-like object that includes pid and cwd information.r(rrr4r rc ||_||_t||_|jr|jdt j|dtj d|d ttddttdrB|dtjdtjddSdSdS) NrzNew process: executable: r>zNew process: cmd: {!r} argvgetppidzNew process: pid: z, parent pid: )r(rr!r insertrrrCr executablermrrrrr)r*r(rr s r+r,zDebugOutputFile.__init__0s  (G}}   a L  :<<#6 7 7 7 JJG3>GGG H H H JJ188fd9S9STT U U Ur9%% a _ __RZ\\___`````  a a a ar-NTrVFfileobjrrinterimrc| ||||S|\}}||r|t|dd}n`tjdt }|dvrt t|}n!|rt|dd}n tj}||||}| |||S)axGet a DebugOutputFile. If `fileobj` is provided, then a new DebugOutputFile is made with it. If `fileobj` isn't provided, then a file is chosen (`file_name` if provided, or COVERAGE_DEBUG_FILE, or stderr), and a process-wide singleton DebugOutputFile is made. `show_process` controls whether the debug file adds process-level information, and filters is a list of other message filters to apply. `filters` are the text filters to apply to the stream to annotate with pids, etc. If `interim` is true, then a future `get_one` can replace this one. Nazutf-8)encodingCOVERAGE_DEBUG_FILE)rstderr) _get_singleton_dataopenrenvironrGFORCED_DEBUG_FILErrr_set_singleton_data)clsrrrr rthe_one is_interims r+r'zDebugOutputFile.get_oneAs4  3w g66 6!5577 ?j?$y#@@@JNN+@BSTT  444%c955GG)"9cGDDDGG!jGc'<99G  # #GW 5 5 5r-z'$coverage.debug.DebugOutputFile.the_onethe_one_and_is_interimrrctj|j}t||j||f|t j|j<dS)z-Set the one DebugOutputFile to rule them all.N)types ModuleType SYS_MOD_NAMEsetattrSINGLETON_ATTRrmodules)rrrsingleton_modules r+rz#DebugOutputFile._set_singleton_datawsH!+C,<== #"4w6HIII(8 C$%%%r-&Tuple[Optional[DebugOutputFile], bool]cvtj|j}t ||jdS)zGet the one DebugOutputFile.)NT)rrrGrrr)rrs r+rz#DebugOutputFile._get_singleton_data~s1;??3+;<<');\JJJr-cT|jtjvrtj|j=dSdS)z6Delete the one DebugOutputFile, just for tests to use.N)rrr)rs r+_del_singleton_dataz#DebugOutputFile._del_singleton_datas/  s{ * * C,--- + *r-rr.c|jJ|jt||j|jdS)z9Just like file.write, but filter through all our filters.N)r(rCrr rI)r*rs r+rCzDebugOutputFile.writesL|''' ;tT\::;;; r-cJ|jJ|jdS)zFlush our file.N)r(rIr1s r+rIzDebugOutputFile.flushs*|''' r-)r(rrr4r r)NNTrVF) rrrrrr4r rrr4rr&)rr&rr4rr)rrrh)rr.rr)rOrPrQrRr, classmethodr'rrrrr rCrIrVr-r+r&r&.sCCaaaa"&*#'!24 ++++[+d=L-N999[9 KKK[K ...[.  r-r&Fr<rEr4ctd}||dz|rt|ddSdS)z.Write a log message as forcefully as possible.Trr>r?r@N)r&r'rCrH)r<rErAs r+logrsY  ! !$ ! / /CIIc$h +c******++r-rV decoratorCallable[..., Any]butnotrprivatecfd}|S)z2A class decorator to apply a decorator to methods.ctj|tjD]L\}}||jvr|dkrs|dr-|vr2t |||M|S)Nr,rx)rD getmembers isroutiner startswithr)rnamemethrrrs r+ _decoratorz$decorate_methods.._decorators!,S'2CDD 0 0JD$3<''z!!4??3#7#7v~~ Cyy / / / / r-rV)rrrrs``` r+decorate_methodsrs0        r-funccHtjdfd }|S)z;A function decorator to stop in the debugger for each call.argsrkwargsrcpddl}tjt_||i|SNr)pudbr __stdout__r set_trace)rr r#rs r+_wrapperzbreak_in_pudb.._wrappers: ^  tT$V$$$r-)rrr rrr functoolswraps)rr&s` r+ break_in_pudbr*s=_T%%%%%% Or-rT show_args show_stack show_returncdfd }|S)z:A method decorator to debug-log each call to the function.rrrcPtjdfd }|S)Nr*rrr rct|td}|Btjddt t d}t |t|d} rvdtt|}dd| D}|dz }||z }|r|r|dz }||z }|dz } rE|d z }|d d t Dz }t t}|d|dd j|d }td | |g|Ri|} rB|d|dd jd| d }td || S)N08drk04dr{z, c3*K|]}dj|VdS)z{}={!r}Nrl)rvitems r+rzzCshow_calls.._decorator.._wrapper..s-#W#W$4I$4d$;#W#W#W#W#W#Wr-()z @ z; c34K|]}t|VdSrK)_clean_stack_line)rvrws r+rzzCshow_calls.._decorator.._wrapper..s+"\"\A#4Q#7#7"\"\"\"\"\"\r-r>Trz return )r OBJ_ID_ATTRrrnextOBJ_IDSrrmaprrrrCALLSrOr&r'rC)r*rr oidextraeargsekwargscallidr<retrr+r-r,s r+r&z0show_calls.._decorator.._wrappers$ T22C{>>>4==>>>k3///E  #dD//22))#W#W #W#W#WWW "W"TME   ]"\"\AYAYA[A["\"\"\\\\%[[F@@6@@@ @u@@@C  # #D # 1 1 7 7 < < <$t-d---f--C ALLvLLLDMLL3LLL'''55;;C@@@Jr-)r*rrrr rrrr')rr&r+r-r,s` r+rzshow_calls.._decoratorsM              4r-rrrrrV)r+r,r-rs``` r+ show_callsrEs5 : r-scj|}|tjt dzd}|tjtjdzd}|t jdzd}|S)z6Simplify some paths in a stack trace, for compactness./r{)stripreplacerpathdirname__file__rr)rFs r+r8r8s|  A "'//(++c1266A "'//"+..4b99A #*s"B''A Hr-envMapping[str, str]List[Tuple[str, str]]cRddh}hd}hd}g}|D]u\}d}|vrd}ntfd|Drd}|rHtfd|Drtjd d |}||fvt |S) aLFilter environment variables for a debug display. Select variables to display (with COV or PY in the name, or HOME, TEMP, or TMP), and also cloak sensitive values with asterisks. Arguments: env: a dict of environment variable names and values. Returns: A list of pairs (name, value) to show. COVPY>TMPHOMETEMP>APIKEYPASSTOKENSECRET SIGNATUREFTc3 K|]}|vV dSrKrVrvslugrs r+rzz/relevant_environment_display..s'00$000000r-c3 K|]}|vV dSrKrVr^s r+rzz/relevant_environment_display.. s'22D44<222222r-z\w*)ranyresubr$r)rNslugsincludecloakto_showvalkeeprs @r+relevant_environment_displayrksDME%%%G B B BEGYY[[ ( ( c 7??DD 0000%000 0 0 D  (2222E22222 .fUC-- NND#; ' ' ' g & &&r-)rir.rr.)rorprrq)rCrrr.rorprrr")rrrBrrr.)NNr)rrrArrBrrr)r)rr.rrrr.)rrrrr)rrrr)rrrr)rr.r rrr.)F)r<r.rEr4rr)rVF)rrrrrr4rrrD)TFF)r+r4r,r4r-r4rr)rFr.rr.)rNrOrrP)=rR __future__rrTr(rDr[ itertoolsrrrcrrrrtypingrrrrrr r r r r coverage.miscrrcoverage.typesrr__annotations__rrrXrcrnrrrrHrrr%rrrrrr&rrr*countr;r=r9rEr8rkrVr-r+rss..--""""""    =<<<<<<<$$$$$$^B  ::::::::z55555555 J J J J J, J J J.... 77776$IIIII. #        $     *        eeeeeeeeP+++++( )/   # #####L    ''''''r-