
    /~hP                       U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlmZmZmZmZ ddlmZmZmZ ddlmZmZ ddlmZmZ  ee      Zg Zde d	<   dZ! G d
 d      Z" G d de"      Z#d0dZ$d1dZ%	 	 	 	 	 	 	 	 d2dZ&d3dZ'dgZ(de d<   g Z)de d<   ed4d       Z*ed5d       Z*d6dZ*	 	 	 	 d7	 	 	 	 	 	 	 	 	 d8dZ+d9d:dZ,d;d<dZ-d=dZ.d>dZ/dhZ0d?dZ1d@d Z2dAd!Z3dBd"Z4 G d# d$      Z5 G d% d&      Z6 G d' d(      Z7 G d) d*      Z8dCdDd+Z9	 	 dE	 	 	 	 	 	 	 dFd,Z:dGd-Z; ejx                         Z= ejx                         Z>dZ?	 	 	 dH	 	 	 	 	 	 	 dId.Z@dJd/ZAy)Kz'Control of and utilities for debugging.    )annotationsN)overloadAnyCallableIO)IterableIteratorMapping)human_sorted_itemsisolate_module)AnyCallable	TWritablez	list[str]FORCED_DEBUGc                  r    e Zd ZdZdZ	 d
	 	 	 	 	 	 	 ddZddZddZej                  dd       Z
dddd	Zy)DebugControlz!Control and output for debugging.FNc                   t        |      t        z   | _        d| _        g }| j	                  d      rF|j                  t               j                         |j                  t               j                         | j	                  d      r#|j                  t               j                         | j	                  d      r|j                  t               t        j                  |||      | _        | j                  j                  | _        y)z4Configure the options and output file for debugging.Fprocesspytestpid)	file_namefiltersN)listr   optionssuppress_callersshouldappend
CwdTrackerfilterProcessTrackerPytestTrackeradd_pid_and_tidDebugOutputFileget_oneoutputoutfile
raw_output)selfr   r$   r   r   s        W/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/coverage/debug.py__init__zDebugControl.__init__.   s     G}|3 %;;y!NN:<../NN>+223;;x NN=?112;;uNN?+%-- . 

 ++--    c                <    d| j                   d| j                  dS )Nz<DebugControl options=z raw_output=>)r   r&   r'   s    r(   __repr__zDebugControl.__repr__H   s"    ''7|DOOCVVWXXr*   c                B    |dk(  r| j                   ry|| j                  v S )z@Decide whether to output debug information in category `option`.callersF)r   r   r'   options     r(   r   zDebugControl.shouldK   s$    Y4#8#8$,,&'r*   c              #  b   K   | j                   }d| _         	 d || _         y# || _         w xY ww)z;A context manager to prevent call stacks from being logged.TN)r   )r'   olds     r(   without_callerszDebugControl.without_callersQ   s3      ## $	($'D!CD!s   /# /	,/excc          	     $   | j                   j                  |dz          |I| j                   j                  dj                  t        j                  d||j
                                     | j                  d      rTt        j                         d   d   j                  j                  d      }|| j                   j                  d|d       | j                  d      rt        | j                   d	       | j                   j                          y)
zWrite a line of debug output.

        `msg` is the line to write. A newline will be appended.

        If `exc` is provided, a stack trace of the exception will be written
        after the message.

        
N r'      r   zself: r0   outskip)r$   writejoin	tracebackformat_exception__traceback__r   inspectstackf_localsgetdump_stack_framesflush)r'   msgr7   caller_selfs       r(   r?   zDebugControl.write[   s     	#*%?KKbggi&@&@sCL]L]&^_`;;v!--/!,Q/88<<VDK&!!F;/"<=;;y!$++A6r*   N)r   Iterable[str]r$   IO[str] | Noner   
str | NonereturnNone)rP   strr2   rR   rP   bool)rP   zIterator[None]rJ   rR   r7   zBaseException | NonerP   rQ   )__name__
__module____qualname____doc__show_repr_attrr)   r.   r   
contextlibcontextmanagerr5   r?    r*   r(   r   r   )   sj    +N !%	.. . 	.
 
.4Y( ( ( >B r*   r   c                  .    e Zd ZdZddZddZddd	dZy)
NoDebuggingzBA replacement for DebugControl that will never try to do anything.c                     y rL   r]   r-   s    r(   r)   zNoDebugging.__init__r   s    r*   c                     y)z'Should we write debug messages?  Never.Fr]   r1   s     r(   r   zNoDebugging.shouldv   s    r*   Nr6   c                   t        d      )zThis will never be called.z)NoDebugging.write should never be called.)AssertionError)r'   rJ   r7   s      r(   r?   zNoDebugging.writez   s    HIIr*   rP   rQ   rS   rU   )rV   rW   rX   rY   r)   r   r?   r]   r*   r(   r_   r_   p   s    L >B Jr*   r_   c                0    dj                  d| z   dz         S )zMake a nice header string.z
--{:-<60s} format)labels    r(   info_headerrj      s    s5y}--r*   c              #    K   t        |       } | sydt        fd| D              sJ | D ]  \  }}|g k(  rd}t        |t              r4t	        t        t        |                  dk  rd|t        |      fz   Qt        |t         t        t        f      rd|fz  }|D ]  }ddz   ||fz   d	} d
||fz    yw)zProduce a sequence of formatted lines from info.

    `info` is a sequence of pairs (label, data).  The produced lines are
    nicely formatted, ready to print.

    N   c              3  @   K   | ]  \  }}t        |      k    y wrL   len).0l_	label_lens      r(   	<genexpr>z!info_formatter.<locals>.<genexpr>   s     3das1v	!3s   z-none-z%*s: %rz%*s:z%*s %sr;   r:   z%*s: %s)r   all
isinstancetuplero   reprset)infori   dataprefixers   s        @r(   info_formatterr~      s      :DI3d3333 7t2:DdE"s4d+<'='By%t===tS%01y%00F )A+vq!999 y%6667s   C Cc                \     | t        |             t        |      D ]  } | d|         y)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.

    rf   N)rj   r~   )r?   headerrz   lines       r(   write_formatted_infor      s3     
+f
t$ $jr*   c                p    t        j                  t        |       |       }dj                  d |D              S )zIGet a one-line summary of an exception, including class name and message.|c              3  <   K   | ]  }|j                           y wrL   )rstrip)rp   rq   s     r(   rt   zexc_one_line.<locals>.<genexpr>   s     .1AHHJ.s   )rA   format_exception_onlytyper@   )r7   liness     r(   exc_one_liner      s-    ++DIs;E88....r*   )z5.*[/\\]pytest-of-.*[/\\]pytest-\d+([/\\]popen-gw\d+)?ztmp:list[tuple[str, str]]_FILENAME_REGEXES_FILENAME_SUBSc                     y rL   r]   filenames    r(   short_filenamer          r*   c                     y rL   r]   r   s    r(   r   r      r   r*   c                   t         st        j                  D ]  }t         j                  |df        ddl}t         j                  t
        j                  j                  |j                        df       t         j                  d d       | Et        D ]  \  }}t        j                  |||       }  t         D ]  \  }}| j                  ||      }  | S )zIShorten a file name. Directories are replaced by prefixes like 'syspath:'zsyspath:r   Nzcov:c                    t        | d         S Nr   rn   )pairs    r(   <lambda>z short_filename.<locals>.<lambda>   s    c$q'l r*   T)keyreverse)r   syspathr   coverageosdirname__file__sortr   resubreplace)r   pathdirr   patr   beforeafters          r(   r   r      s    xx 	9G!!7J"78	9rwwx/@/@A6JK!:TJ) 	2HCvvc31H	2+ 	7MFE''6H	7Or*   c                   g d}t        j                         d| d   }|s |D ]  }t        j                  |fd|      } g }|D ]n  }|j                  dd}	|r|	t        |j                        ddz  }	|j                  }
|rt        |
      }
|	|
 d	|j                   z  }	|j                  |	       p d
j                  |      S )a^  Return 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
        ...

    `skip` is the number of closest immediate frames to skip, so that debugging
    functions can call this and not be included in the result.

    If `full` is true, then include all frames.  Otherwise, initial "boring"
    frames (ones in site-packages and earlier) are omitted.

    `short_filenames` will shorten filenames using `short_filename`, to reduce
    the amount of repetitive noise in stack traces.

    )z<string>z
\bigor.py$z\bsite-packages\bNc                B    t        j                  || j                        S rL   )r   searchr   )fir   s     r(   r   zshort_stack.<locals>.<lambda>   s    RYYsBKK%@ r*   z>30sz : z#xrf   :r9   )rD   rE   	itertools	dropwhilefunctionidframer   r   linenor   r@   )r>   full	frame_idsshort_filenamesBORING_PRELUDErE   r   r   
frame_infor   r   s              r(   short_stackr      s    8N *1$r)BE! 	C'' #@E	
 E 
%%d+3/r***+B/q11D&&%h/H8*Aj//011T 99Ur*   c                F    | j                  t        |dz         dz          y)z&Print a summary of the stack to `out`.r;   )r>   r9   N)r?   r   r<   s     r(   rH   rH   
  s    IIktAv&-.r*   c                Z    t        j                         }||_        |j                  |       S )z(`repr(text)`, but limited to `numchars`.)reprlibRepr	maxstringrx   )textnumcharsrs      r(   clipped_reprr     s"    AAK66$<r*   c                D    d}t        ddd      D ]
  }|| |z	  z  } |dz  S )z-Given a 64-bit id, make a shorter 16-bit one.r   @      i  )range)id64id16offsets      r(   short_idr     s7    D2r" &=r*   c                ~    t        t        j                               d}t        j                         dd| d|  } | S )z.A filter to add pid and tid to debug messages.04x5d.z: )r   _thread	get_identr   getpid)r   tids     r(   r!   r!     s@     g'')*3/Ciik"Qse2dV,DKr*   z$coverage.object_idc                    d | j                   j                         D        }dj                  | j                  j                  t        |       dj                  d |D                    S )z<A function implementing an automatic __repr__ for debugging.c              3  ~   K   | ]5  \  }}t        |d d      r#t        j                  |      s|t        vr||f 7 yw)rZ   TN)getattrrD   ismethodAUTO_REPR_IGNORErp   kvs      r(   rt   zauto_repr.<locals>.<genexpr>*  sD      1a1&-  #%% 
As   ;=z<{klass} @{id:#x}{attrs}>r:   c              3  2   K   | ]  \  }}d | d|  yw)rf   =Nr]   r   s      r(   rt   zauto_repr.<locals>.<genexpr>3  s      ;1!AaUm;   )klassr   attrs)__dict__itemsrh   	__class__rV   r   r@   )r'   
show_attrss     r(   	auto_reprr   (  s^    ==..0J '--nn%%d8gg;
;; .  r*   c                   t        | t              r-| j                         D ci c]  \  }}|t        |       c}}S t        | t        t
        f      r t        |       d | D              S t        | d      r:t        | j                  j                         D  ci c]  \  }} d|z   |  c} }      S | S c c}}w c c} }w )z>Turn things which are nearly dict/list/etc into dict/list/etc.c              3  2   K   | ]  }t        |        y wrL   )simplify)rp   vvs     r(   rt   zsimplify.<locals>.<genexpr><  s     0x|0r   r   r   )	rv   dictr   r   r   rw   r   hasattrr   )r   r   r   s      r(   r   r   7  s    !T,-GGI651b(2,66	Ae}	%tAw0a000	J	ajj.>.>.@AdaQABB 7 Bs   B4B:
c                @    t        j                   t        |              y)zEDebug helper to pretty-print data, including SimpleNamespace objects.N)pprintr   )r   s    r(   ppr   C  s     MM(1+r*   c                    | j                         }| t        |      d }|} |D ]O  }g }| j                         D ]'  }|j                   ||      j                                ) dj	                  |      } Q | |z   S )aQ  Run `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. After each filter, the text is split into
    lines, and each line is passed through the next filter.

    Returns: the final string that results after all of the filters have
    run.

    Nr9   )r   ro   
splitlinesextendr@   )r   r   
clean_textending	filter_fnr   r   s          r(   filter_textr   I  s     J#j/"#FD  	OO% 	7DLL43356	7yy	 
 &=r*   c                       e Zd ZdZddZddZy)r   z*A class to add cwd info to debug messages.c                    d | _         y rL   )cwdr-   s    r(   r)   zCwdTracker.__init__a  s	    #r*   c                l    t        j                         }|| j                  k7  rd|d|z   }|| _        |S )z#Add a cwd message for each new cwd.zcwd is now r9   )r   getcwdr   )r'   r   r   s      r(   r   zCwdTracker.filterd  s7    iik$((? r*T1DDHr*   Nrd   r   rR   rP   rR   rV   rW   rX   rY   r)   r   r]   r*   r(   r   r   _  s    4$r*   r   c                       e Zd ZdZddZddZy)r   z)Track process creation for debug logging.c                D    t        j                         | _        d| _        y )NF)r   r   r   did_welcomer-   s    r(   r)   zProcessTracker.__init__o  s    		 r*   c                J   d}t        j                         }| j                  |k7  rd| j                   d| d}|| _        nT| j                  sHt	        t
        dd      }d|dt
        j                  dd	|dz   d
t        j                         dz   }|rd| _        ||z   S |S )z1Add a message about how new processes came to be.r:   zNew process: forked z -> r9   argvNzNew process: pid=z, executable: zNew process: cmd: zNew process parent pid: T)r   r   r   r   r   r   
executablegetppid)r'   r   welcomer   r  s        r(   r   zProcessTracker.filters  s    iik88s?,TXXJd3%rBGDH!!3-D$v^CNN3ERH&thb12,RZZ\,<B?@  #DT>!Kr*   Nrd   r   r   r]   r*   r(   r   r   m  s    3!r*   r   c                       e Zd ZdZddZddZy)r    z<Track the current pytest test name to add to debug messages.c                    d | _         y rL   )	test_namer-   s    r(   r)   zPytestTracker.__init__  s	    %)r*   c                n    t        j                  d      }|| j                  k7  rd| d|z   }|| _        |S )z+Add a message when the pytest test changes.PYTEST_CURRENT_TESTzPytest context: r9   )r   getenvr  )r'   r   r  s      r(   r   zPytestTracker.filter  s<    II34	&%i[3d:D&DNr*   Nrd   r   r   r]   r*   r(   r    r      s    F*r*   r    c                      e Zd ZdZ	 	 	 	 ddZe	 	 	 	 d	 	 	 	 	 	 	 	 	 dd       ZdZdZedd       Z	edd       Z
edd	       Zdd
ZddZy)r"   z9A file-like object that includes pid and cwd information.c                d    || _         t        |      | _        t        j                         | _        y rL   )r%   r   r   r   r   r   )r'   r%   r   s      r(   r)   zDebugOutputFile.__init__  s#    
 G}99;r*   Nc                   |	 | ||      S | j                         \  }}||r|t        |dd      }not        j                  dt              }|dv rt        t        |      }n@|r.t        |dd      }t        j                  |j                         nt        j                  } | ||      }| j                  ||       |j                  st        |      |_        |S )a  Get 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.

        `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.

        azutf-8)encodingCOVERAGE_DEBUG_FILE)stdoutstderr)_get_singleton_dataopenr   r
  FORCED_DEBUG_FILEr   r   atexitregistercloser  _set_singleton_datar   r   )clsfileobjr   r   interimthe_one
is_interims          r(   r#   zDebugOutputFile.get_one  s    , w((!557?j$y#@ II&;=NO	 44%c95G"9cGDGOOGMM2!jjG'7+G##GW5"7mGOr*   z'$coverage.debug.DebugOutputFile.the_onethe_one_and_is_interimc                    t        j                  | j                        }t        || j                  ||f       |t
        j                  | j                  <   y)z-Set the one DebugOutputFile to rule them all.N)types
ModuleTypeSYS_MOD_NAMEsetattrSINGLETON_ATTRr   modules)r  r  r  singleton_modules       r(   r  z#DebugOutputFile._set_singleton_data  sG     !++C,<,<= #"4"4w6HI(8C$$%r*   c                    t         j                  j                  | j                        }t	        || j
                  d      S )zGet the one DebugOutputFile.)NT)r   r&  rG   r#  r   r%  )r  r'  s     r(   r  z#DebugOutputFile._get_singleton_data  s3     ;;??3+;+;<'););\JJr*   c                t    | j                   t        j                  v rt        j                  | j                   = yy)z6Delete the one DebugOutputFile, just for tests to use.N)r#  r   r&  )r  s    r(   _del_singleton_dataz#DebugOutputFile._del_singleton_data  s-     s{{*C,,- +r*   c                    | j                   J | j                   j                  t        || j                               | j                   j	                          y)z9Just like file.write, but filter through all our filters.N)r%   r?   r   r   rI   )r'   r   s     r(   r?   zDebugOutputFile.write  s?    ||''';tT\\:;r*   c                T    | j                   J | j                   j                          y)zFlush our file.N)r%   rI   r-   s    r(   rI   zDebugOutputFile.flush  s"    ||'''r*   )r%   rN   r   Iterable[Callable[[str], str]])NNr]   F)
r  rN   r   rO   r   r-  r  rT   rP   r"   )r  r"   r  rT   rP   rQ   )rP   z#tuple[DebugOutputFile | None, bool]rd   )r   rR   rP   rQ   )rV   rW   rX   rY   r)   classmethodr#   r#  r%  r  r  r*  r?   rI   r]   r*   r(   r"   r"     s    C 0  #' $24,, , 0	,
 , 
, ,f =L-N9 9 K K
 . .
r*   r"   c                x    t         j                  d      }|j                  | dz          |rt        |d       yy)z.Write a log message as forcefully as possible.Tr  r9   r;   r<   N)r"   r#   r?   rH   )rJ   rE   r=   s      r(   logr1    s7    

!
!$
!
/CIIc$hc* r*   c                      fd}|S )z2A class decorator to apply a decorator to methods.c                    t        j                  | t         j                        D ]E  \  }}|| j                  vr|dk7  rs|j	                  d      r.|v r3t        | | |             G | S )Nr)   rr   )rD   
getmembers	isroutiner   
startswithr$  )r  namemethbutnot	decoratorprivates      r(   
_decoratorz$decorate_methods.<locals>._decorator  sr    !,,S'2C2CD 	0JD$3<<'z!4??3#7v~Cy/	0 
r*   r]   )r:  r9  r;  r<  s   ``` r(   decorate_methodsr=     s    
 r*   c                D     t        j                         d fd       }|S )z;A function decorator to stop in the debugger for each call.c                 n    dd l }t        j                  t        _        |j	                           | i |S r   )pudbr   
__stdout__r  	set_trace)argskwargsr@  funcs      r(   _wrapperzbreak_in_pudb.<locals>._wrapper  s+    ^^
T$V$$r*   )rC  r   rD  r   rP   r   	functoolswraps)rE  rF  s   ` r(   break_in_pudbrJ    s%    __T% %
 Or*   c                     d fd}|S )z:A method decorator to debug-log each call to the function.c                L     t        j                         d fd       }|S )Nc                   t        | t        d       }|9t        j                         ddt	        t
              d}t        | t        |       d}rbdj                  t        t        |            }dj                  d |j                         D              }|dz  }||z  }|r|r|dz  }||z  }|dz  }r1|d	z  }|d
j                  t        d      j                               z  }t	        t              }| d|dd
j                   | d}t        j!                  d      j#                  |        
| g|i |}	r>| d|dd
j                   d|	d}t        j!                  d      j#                  |       |	S )N08drf   04dr:   z, c              3  :   K   | ]  } d j                   |   yw)z{}={!r}Nrg   )rp   items     r(   rt   zCshow_calls.<locals>._decorator.<locals>._wrapper.<locals>.<genexpr>3  s     #W$4I$4$4d$;#Ws   ()z @ z; T)r   r9   r0  z return )r   OBJ_ID_ATTRr   r   nextOBJ_IDSr$  r@   maprx   r   r   r   CALLSrV   r"   r#   r?   )r'   rC  rD  oidextraeargsekwargscallidrJ   retrE  	show_argsshow_return
show_stacks             r(   rF  z0show_calls.<locals>._decorator.<locals>._wrapper*  s{   $T2C{S)4=*=>k3/E		#dD/2))#W#WWWTME ;t#D#O#O#QRR%[FE6#,augR@C##D#177<t-d-f-CQvcl!DMM?(3'L'''5;;C@Jr*   )r'   r   rC  r   rD  r   rP   r   rG  )rE  rF  r_  r`  ra  s   ` r(   r<  zshow_calls.<locals>._decorator)  s%    			 
	4 r*   rE  r   rP   r   r]   )r_  ra  r`  r<  s   ``` r(   
show_callsrc  #  s    : r*   c                &   ddh}h d}h d}g }| j                         D ]e  \  }d}|v rd}nt        fd|D              rd}|s(t        fd|D              rt        j                  d	d
|      }|j	                  |f       g t        |      S )aL  Filter 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.

    COVPY>   TMPHOMETEMP>   APIKEYPASSTOKENSECRET	SIGNATUREFTc              3  &   K   | ]  }|v  
 y wrL   r]   rp   slugr7  s     r(   rt   z/relevant_environment_display.<locals>.<genexpr>_  s     0$0   c              3  &   K   | ]  }|v  
 y wrL   r]   rq  s     r(   rt   z/relevant_environment_display.<locals>.<genexpr>b  s     2D44<2rs  z\w*)r   anyr   r   r   r   )envslugsincludecloakto_showvalkeepr7  s          @r(   relevant_environment_displayr~  I  s     DME%GBEGYY[ 	(	c7?D0%00D2E22ffUC-NND#;'	( g&&r*   )ri   rR   rP   rR   )rz   Iterable[tuple[str, Any]]rP   zIterator[str])r?   zCallable[[str], None]r   rR   rz   r  rP   rQ   )r7   	ExceptionrP   rR   )r   rR   rP   rR   )r   rQ   rP   rQ   )r   rO   rP   rO   )r   FFF)
r>   intr   rT   r   rT   r   rT   rP   rR   )r   )r=   r   r>   r  rP   rQ   )2   )r   rR   r   r  rP   rR   )r   r  rP   r  r   )r'   r   rP   rR   )r   r   rP   r   )r   r   rP   rQ   )r   rR   r   r-  rP   rR   )F)rJ   rR   rE   rT   rP   rQ   )r]   F)r:  Callable[..., Any]r9  rM   r;  rT   rP   r  rb  )TFF)r_  rT   ra  rT   r`  rT   rP   r  )rw  zMapping[str, str]rP   r   )BrY   
__future__r   r  r[   rH  rD   r   r   r   r   r   r   rA   r!  r   typingr   r   r   r   collections.abcr   r	   r
   coverage.miscr   r   coverage.typesr   r   r   __annotations__r  r   r_   rj   r~   r   r   r   r   r   r   rH   r   r   r!   r   r   r   r   r   r   r   r    r"   r1  r=  rJ  countrV  rX  rT  rc  r~  r]   r*   r(   <module>r     sA   . "      	  	  
     8 7 < 1B i  D DNJ, J.
76  $ 
	$/ G, (  )+% *		 
	 
	 
	" !	3
3
3 3 	3
 	3l/
 ** 	,  8 ^ ^B+ !  	( )//
	# ### # 	#L'r*   