idEpUdZddlmZddlZddlZddlZddlZddlZddlZddl 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<c3JK|]}d|d|d|dfzVdS)z %30s : %s:%dr?NrV).0ts r+ zshort_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 maxstringrx)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)rkvr*s r+rz)AutoReprMixin.__repr__..sn  q!q*D11 QKK ...F/...   r-z<{klass} @0x{id:x} {attrs}>rkc3*K|]\}}|d|VdS)=NrVrrrs r+rz)AutoReprMixin.__repr__..s0??DAqa<Turn things which are nearly dict/list/etc into dict/list/etc.c4i|]\}}|t|SrVsimplify)rrvvs r+ zsimplify..s$66651b(2,,666r-c34K|]}t|VdSrKr)rrs r+rzsimplify..s(00x||000000r-rc i|] \}}d|z| S)rrVrs r+rzsimplify..s"AAAdaQAAAr-) rudictrr!rvtypehasattrrrrs 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>)rstriprw 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|jt||j|jdS)z9Just like file.write, but filter through all our filters.N)r(rCrr rI)r*rs r+rCzDebugOutputFile.writes@ ;tT\::;;; r-c8|jdS)zFlush our file.N)r(rIr1s r+rIzDebugOutputFile.flushs r-)r(rrr4r r)NNTrVF) rrrrrr4r rrr4rr&)rr&rr4rr)rrrh)rr.rr)rOrPrQrRr, classmethodr'rrrrrrCrIrVr-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+logr sY  ! !$ ! / /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,_)rD getmembers isroutiner startswithr)rnamemethrr rs r+ _decoratorz$decorate_methods.._decorators!,S'2CDD 0 0JD$3<''z!!4??3#7#7v~~ Cyy / / / / r-rV)r rrrs``` 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)rrr rs r+_wrapperzbreak_in_pudb.._wrappers: ^  tT$V$$$r-)rrrrrr 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.rr rcPtjdfd }|S)Nr*rrrrct|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)N08drk04drtz, c3*K|]}dj|VdS)z{}={!r}Nrl)ritems r+rzCshow_calls.._decorator.._wrapper..s-#W#W$4I$4d$;#W#W#W#W#W#Wr-()z @ z; c34K|]}t|VdSrK)_clean_stack_line)rls r+rzCshow_calls.._decorator.._wrapper..s+"\"\A#4Q#7#7"\"\"\"\"\"\r-r>Tr z return )r OBJ_ID_ATTRrrnextOBJ_IDSrrmaprxrrrCALLSrOr&r'rC)r*rroidextraeargsekwargscallidr<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*rrrrrrrr$)rr#r(r*r)s` r+rzshow_calls.._decoratorsM              4r-rr rr rV)r(r)r*rs``` r+ show_callsrCs5 : r-scj|}|tjt dzd}|tjtjdzd}|t jdzd}|S)z6Simplify some paths in a stack trace, for compactness./rt)stripreplacerpathdirname__file__rr{)rDs r+r5r5s|  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 dSrKrVrslugrs r+rz/relevant_environment_display..s'00$000000r-c3 K|]}|vV dSrKrVr\s r+rz/relevant_environment_display.. s'22D44<222222r-z\w*)ranyresubr$r)rLslugsincludecloakto_showvalkeeprs @r+relevant_environment_displayrisDME%%%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)r r rrrr4rr rB)TFF)r(r4r)r4r*r4rr )rDr.rr.)rLrMrrN)=rR __future__rrTr%rDr[ itertoolsrrrarrrrtypingrrrrrr r r r r coverage.miscrrcoverage.typesrr__annotations__rrrXrcrnr~rrrHrrr%rrrrrr&r rr'countr9r;r7rCr5rirVr-r+rqs..--""""""    =<<<<<<<$$$$$$^B  ::::::::z55555555 J J J J J, J J J.... 77776$IIIII. #        $     *        eeeeeeeeP+++++( )/   # #####L    ''''''r-