o
    v&iT                     @  s  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ZddlmZmZmZ ddlmZmZ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 dZ$G dd de$Z%G dd de%Z&dxddZ'dyddZ(dzddZ)d{d"d#Z*d$gZ+d%e"d&< g Z,d%e"d'< ed|d)d*Z-ed}d+d*Z-d~d-d*Z-d|d.d/Z.		0	0	0ddd7d8Z/ddd;d<Z0ddd@dAZ1ddCdDZ2ddEdFZ3dGhZ4ddJdKZ5ddMdNZ6ddOdPZ7ddQdRZ8ddUdVZ9G dWdX dXZ:G dYdZ dZZ;G d[d\ d\Z<G d]d^ d^Z=dddadbZ>	c	0dddhdiZ?ddldmZ@e	A ZBe	A ZCdGZD	n	0	0dddrdsZEddvdwZFdS )z'Control of and utilities for debugging.    )annotationsN)IterableIteratorMapping)IOAnyCallableFinaloverload)human_sorted_itemsisolate_module)AnyCallable	TWritablez	list[str]FORCED_DEBUGc                   @  sV   e Zd ZdZdZ	ddddZd ddZd!ddZej	d"ddZ
ddd#ddZdS )$DebugControlz!Control and output for debugging.FNoptionsIterable[str]outputIO[str] | None	file_name
str | NonereturnNonec                 C  s   t |t | _d| _g }| dr|t j |t j | dr+|t	 j | dr5|t
 tj|||d| _| jj| _dS )z4Configure the options and output file for debugging.Fprocesspytestpid)r   filtersN)listr   r   suppress_callersshouldappend
CwdTrackerfilterProcessTrackerPytestTrackeradd_pid_and_tidDebugOutputFileget_oner   outfile
raw_output)selfr   r   r   r    r+   T/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/coverage/debug.py__init__+   s    



zDebugControl.__init__strc                 C  s   d| j d| jdS )Nz<DebugControl options=z raw_output=>)r   r)   r*   r+   r+   r,   __repr__E   s   zDebugControl.__repr__optionboolc                 C  s   |dkr	| j r	dS || jv S )z@Decide whether to output debug information in category `option`.callersF)r   r   r*   r2   r+   r+   r,   r   H   s   
zDebugControl.shouldIterator[None]c                 c  s*    | j }d| _ z	dV  W || _ dS || _ w )z;A context manager to prevent call stacks from being logged.TN)r   )r*   oldr+   r+   r,   without_callersN   s   zDebugControl.without_callersexcmsgr:   BaseException | Nonec             	   C  s   | j |d  |dur| j dtd||j | dr:t d d j	
d}|dur:| j d|d | drFt| j dd	 | j   dS )
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: r4   outskip)r   writejoin	tracebackformat_exception__traceback__r   inspectstackf_localsgetdump_stack_framesflush)r*   r;   r:   caller_selfr+   r+   r,   rC   X   s   	

zDebugControl.writeN)r   r   r   r   r   r   r   r   )r   r.   r2   r.   r   r3   r   r6   r;   r.   r:   r<   r   r   )__name__
__module____qualname____doc__show_repr_attrr-   r1   r   
contextlibcontextmanagerr8   rC   r+   r+   r+   r,   r   &   s    

	r   c                   @  sD   e Zd ZdZdddZdd	d
ZejdddZdddddZ	dS )NoDebuggingzBA replacement for DebugControl that will never try to do anything.r   r   c                 C     d S rO   r+   r0   r+   r+   r,   r-   p      zNoDebugging.__init__r2   r.   r3   c                 C  s   dS )z'Should we write debug messages?  Never.Fr+   r5   r+   r+   r,   r   t   r\   zNoDebugging.shouldr6   c                 c  s    dV  dS )z+A dummy context manager to satisfy the api.Nr+   r0   r+   r+   r,   r8   x   s   
zNoDebugging.without_callersNr9   r;   r:   r<   c                C  s   t d)zThis will never be called.z)NoDebugging.write should never be called.)AssertionErrorr*   r;   r:   r+   r+   r,   rC   }   s   zNoDebugging.writer   r   rP   rQ   rR   )
rS   rT   rU   rV   r-   r   rX   rY   r8   rC   r+   r+   r+   r,   rZ   m   s    

rZ   c                   @  s    e Zd ZdZdddd
dZdS )DevNullDebugz)A DebugControl that won't write anywhere.Nr9   r;   r.   r:   r<   r   r   c                C  r[   rO   r+   r^   r+   r+   r,   rC      s   zDevNullDebug.writerR   )rS   rT   rU   rV   rC   r+   r+   r+   r,   r`      s    r`   labelr.   r   c                 C  s   d d|  d S )zMake a nice header string.z
--{:-<60s} format)ra   r+   r+   r,   info_header   s   re   infoIterable[tuple[str, Any]]r   c                 #  s    t | } | s	dS d t fdd| D sJ | D ]b\}}|g kr$d}|d  d}| td rE tt|dk rF | | V  q  td rM n  t d rU n  td r] n  n |D ]}| | V  d	 d
  }qcq	 | | V  qdS )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  s     | ]\}}t | k V  qd S rO   len).0l_	LABEL_LENr+   r,   	<genexpr>   s    z!info_formatter.<locals>.<genexpr>z-none-r/   : r+   rb      )r   alltuplerj   r.   set)rf   ra   dataprefixer+   rn   r,   info_formatter   s,   6ry   rC   Callable[[str], None]headerr   c                 C  s,   | t | t|D ]	}| d|  q
dS )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.

    rb   N)re   ry   )rC   r{   rf   liner+   r+   r,   write_formatted_info   s   r}   r:   	Exceptionc                 C  s$   t t| | }ddd |D S )zIGet a one-line summary of an exception, including class name and message.|c                 s  s    | ]}|  V  qd S rO   )rstrip)rk   rl   r+   r+   r,   rp          zexc_one_line.<locals>.<genexpr>)rE   format_exception_onlytyperD   )r:   linesr+   r+   r,   exc_one_line   s   r   )z5.*[/\\]pytest-of-.*[/\\]pytest-\d+([/\\]popen-gw\d+)?ztmp:list[tuple[str, str]]_FILENAME_REGEXES_FILENAME_SUBSfilenamec                 C  r[   rO   r+   r   r+   r+   r,   short_filename   r\   r   c                 C  r[   rO   r+   r   r+   r+   r,   r      r\   r   c                 C  s   t s(tjD ]	}t |df qddl}t tj|jdf t jdd dd | durGt	D ]\}}t
||| } q.t D ]
\}}| ||} q<| S )	zIShorten a file name. Directories are replaced by prefixes like 'syspath:'zsyspath:r   Nzcov:c                 S  s   t | d S Nr   ri   )pairr+   r+   r,   <lambda>   s    z short_filename.<locals>.<lambda>T)keyreverse)r   syspathr    coverageosdirname__file__sortr   resubreplace)r   pathdirr   patr   beforeafterr+   r+   r,   r      s   
c              
   C  sx   zt | }W n# ty   d}Y |S  ty* } zd| }W Y d}~|S d}~ww tj|j}|j d| }|S )z/A one-line summary of a file, for log messages.zdoes not existzerror: Nz bytes, modified )r   statFileNotFoundErrorr~   datetimefromtimestampst_mtimest_size)r   ssummaryrx   modr+   r+   r,   file_summary   s   r   FrB   intfullr3   	frame_idsshort_filenamesc                 C  s   g d}t  d| d }|s|D ]}t|fdd|}qg }|D ].}|jdd}	|r8|	t|jdd	7 }	|j}
|rAt|
}
|	|
 d
|j	 7 }	|
|	 q"d|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                 S  s   t || jS rO   )r   searchr   )fir   r+   r+   r,   r     s    zshort_stack.<locals>.<lambda>z>30sz : z#xrb   :r=   )rH   rI   	itertools	dropwhilefunctionidframer   r   linenor    rD   )rB   r   r   r   BORING_PRELUDErI   r   r   
frame_infor|   r   r+   r+   r,   short_stack   s&   

r   rA   r   c                 C  s   |  t|d dd  dS )z&Print a summary of the stack to `out`.r?   )rB   r=   N)rC   r   r@   r+   r+   r,   rL   (  s   rL   2   textnumcharsc                 C  s   t  }||_|| S )z(`repr(text)`, but limited to `numchars`.)reprlibRepr	maxstringrepr)r   r   rr+   r+   r,   clipped_repr-  s   
r   id64c                 C  s*   d}t dddD ]}|| |? N }q|d@ S )z-Given a 64-bit id, make a shorter 16-bit one.r   @      i  )range)r   id16offsetr+   r+   r,   short_id4  s   r   c                 C  s.   t t d}t dd| d|  } | S )z.A filter to add pid and tid to debug messages.04x5d.rq   )r   _thread	get_identr   getpid)r   tidr+   r+   r,   r%   <  s   r%   z$coverage.object_idr*   r   c                 C  s<   dd | j  D }dj| jjt| ddd |D dS )z<A function implementing an automatic __repr__ for debugging.c                 s  s:    | ]\}}t |d drt|s|tvr||fV  qdS )rW   TN)getattrrH   ismethodAUTO_REPR_IGNORErk   kvr+   r+   r,   rp   I  s    
zauto_repr.<locals>.<genexpr>z<{klass} @{id:#x}{attrs}>r>   c                 s  s$    | ]\}}d | d|V  qdS )rb   =Nr+   r   r+   r+   r,   rp   S  s   " )klassr   attrs)__dict__itemsrd   	__class__rS   r   rD   )r*   
show_attrsr+   r+   r,   	auto_reprG  s   r   r   c                 C  sf   t | trdd |  D S t | ttfr t| dd | D S t| dr1tdd | j D S | S )z>Turn things which are nearly dict/list/etc into dict/list/etc.c                 S  s   i | ]	\}}|t |qS r+   simplify)rk   r   vvr+   r+   r,   
<dictcomp>Z      zsimplify.<locals>.<dictcomp>c                 s  s    | ]}t |V  qd S rO   r   )rk   r   r+   r+   r,   rp   \  r   zsimplify.<locals>.<genexpr>r   c                 S  s   i | ]	\}}d | |qS )r   r+   r   r+   r+   r,   r   ^  r   )	
isinstancedictr   r   rt   r   hasattrr   r   r   r+   r+   r,   r   W  s   

r   c                 C  s   t jt| dddddS )EDebug helper to pretty-print data, including SimpleNamespace objects.   T   )indentcompact
sort_dictswidth)pprintpformatr   r   r+   r+   r,   ppformatc  s   r   c                 C  s   t t|  dS )r   N)printr   r   r+   r+   r,   pph  s   r   r   Iterable[Callable[[str], str]]c                 C  s\   |   }| t|d }|} |D ]}g }|  D ]}|||  qd|} q| | 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.

    Nr=   )r   rj   
splitlinesextendrD   )r   r   
clean_textending	filter_fnr   r|   r+   r+   r,   filter_textm  s   r   c                   @  $   e Zd ZdZdddZddd	Zd
S )r!   z*A class to add cwd info to debug messages.r   r   c                 C  
   d | _ d S rO   )cwdr0   r+   r+   r,   r-        
zCwdTracker.__init__r   r.   c                 C  s,   t  }|| jkrd|d| }|| _|S )z#Add a cwd message for each new cwd.zcwd is now r=   )r   getcwdr   )r*   r   r   r+   r+   r,   r"     s
   
zCwdTracker.filterNr_   r   r.   r   r.   rS   rT   rU   rV   r-   r"   r+   r+   r+   r,   r!         
r!   c                   @  r   )r#   z)Track process creation for debug logging.r   r   c                 C  s   t  | _d| _d S )NF)r   r   r   did_welcomer0   r+   r+   r,   r-     s   

zProcessTracker.__init__r   r.   c                 C  s   d}t  }| j|krd| j d| d}|| _n!| js:ttdd}d|dtjdd	|d d
t  d }|rCd| _|| S |S )z1Add a message about how new processes came to be.r>   zNew process: forked z -> r=   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  r+   r+   r,   r"     s"   

zProcessTracker.filterNr_   r   r  r+   r+   r+   r,   r#     s    
r#   c                   @  r   )r$   z<Track the current pytest test name to add to debug messages.r   r   c                 C  r   rO   )	test_namer0   r+   r+   r,   r-     r   zPytestTracker.__init__r   r.   c                 C  s.   t d}|| jkrd| d| }|| _|S )z+Add a message when the pytest test changes.PYTEST_CURRENT_TESTzPytest context: r=   )r   getenvr  )r*   r   r  r+   r+   r,   r"     s
   

zPytestTracker.filterNr_   r   r  r+   r+   r+   r,   r$     r  r$   c                   @  s   e Zd ZU dZd'ddZe					
d(d)ddZdZded< dZ	ded< ed*ddZ
ed+ddZed,dd Zd-d#d$Zd,d%d&ZdS ).r&   z9A file-like object that includes pid and cwd information.r(   r   r   r   c                 C  s   || _ t|| _t | _d S rO   )r(   r   r   r   r   r   )r*   r(   r   r+   r+   r,   r-     s   
zDebugOutputFile.__init__Nr+   Ffileobjr   r   interimr3   r   c                 C  s   |dur	| ||S |   \}}|du s|rO|dur!t|ddd}n#tdt}|dv r1tt|}n|rAt|ddd}t|j	 ntj
}| ||}| || |jsWt||_|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.

        N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   )clsr  r   r   r  the_one
is_interimr+   r+   r,   r'     s$   


zDebugOutputFile.get_onez'$coverage.debug.DebugOutputFile.the_onez
Final[str]SYS_MOD_NAMEthe_one_and_is_interimSINGLETON_ATTRr  r   c                 C  s.   t | j}t|| j||f |tj| j< dS )z-Set the one DebugOutputFile to rule them all.N)types
ModuleTyper  setattrr  r   modules)r  r  r  singleton_moduler+   r+   r,   r    s   z#DebugOutputFile._set_singleton_data#tuple[DebugOutputFile | None, bool]c                 C  s   t j| j}t|| jdS )zGet the one DebugOutputFile.)NT)r   r"  rK   r  r   r  )r  r#  r+   r+   r,   r    s   z#DebugOutputFile._get_singleton_datac                 C  s   | j tjv rtj| j = dS dS )z6Delete the one DebugOutputFile, just for tests to use.N)r  r   r"  )r  r+   r+   r,   _del_singleton_data  s   z#DebugOutputFile._del_singleton_datar   r.   c                 C  s<   | j dusJ | j js| j t|| j | j   dS dS )z9Just like file.write, but filter through all our filters.N)r(   closedrC   r   r   rM   )r*   r   r+   r+   r,   rC     s
   zDebugOutputFile.writec                 C  s(   | j dusJ | j js| j   dS dS )zFlush our file.N)r(   r&  rM   r0   r+   r+   r,   rM     s   zDebugOutputFile.flush)r(   r   r   r   )NNr+   F)
r  r   r   r   r   r   r  r3   r   r&   )r  r&   r  r3   r   r   )r   r$  r_   )r   r.   r   r   )rS   rT   rU   rV   r-   classmethodr'   r  __annotations__r  r  r  r%  rC   rM   r+   r+   r+   r,   r&     s&   
 
	3
r&   r;   rI   c                 C  s2   t jdd}|| d  |rt|dd dS dS )z.Write a log message as forcefully as possible.Tr  r=   r?   r@   N)r&   r'   rC   rL   )r;   rI   rA   r+   r+   r,   log"  s
   r*  r+   	decoratorCallable[..., Any]butnotprivatec                   s    fdd}|S )z2A class decorator to apply a decorator to methods.c                   sZ   t | t jD ]#\}}|| jvrq|dkrs|drq| v r"qt| || q| S )Nr-   rm   )rH   
getmembers	isroutiner   
startswithr!  )r  namemethr-  r+  r.  r+   r,   
_decorator1  s   
z$decorate_methods.<locals>._decoratorr+   )r+  r-  r.  r5  r+   r4  r,   decorate_methods*  s   r6  funcr   c                   s   t  d fdd}|S )	z;A function decorator to stop in the debugger for each call.argsr   kwargsr   c                    s&   dd l }tjt_|   | i |S r   )pudbr   
__stdout__r  	set_trace)r8  r9  r:  r7  r+   r,   _wrapperC  s   zbreak_in_pudb.<locals>._wrapperN)r8  r   r9  r   r   r   	functoolswrapsr7  r>  r+   r=  r,   break_in_pudb@  s   rC  T	show_args
show_stackshow_returnc                   s   d fdd}|S )z:A method decorator to debug-log each call to the function.r7  r   r   c                   s"   t  d fdd}|S )	Nr*   r   r8  r9  r   c           
        sF  t | td }|d u rt ddttd}t| t| d}rMdtt	|}ddd |
 D }|d7 }||7 }|rE|rE|d7 }||7 }|d	7 }r_|d
7 }|dtdd 7 }tt}| d|dd j | d}tjdd|  | g|R i |}	r| d|dd j d|	d}tjdd| |	S )N08drb   04dr>   z, c                 s  s    | ]}d j | V  qdS )z{}={!r}Nrc   )rk   itemr+   r+   r,   rp   d  s    zCshow_calls.<locals>._decorator.<locals>._wrapper.<locals>.<genexpr>()z @ z; T)r   r=   r)  z return )r   OBJ_ID_ATTRr   r   nextOBJ_IDSr!  rD   mapr   r   r   r   CALLSrS   r&   r'   rC   )
r*   r8  r9  oidextraeargsekwargscallidr;   ret)r7  rD  rF  rE  r+   r,   r>  [  s2    z0show_calls.<locals>._decorator.<locals>._wrapper)r*   r   r8  r   r9  r   r   r   r?  rB  rD  rF  rE  r=  r,   r5  Z  s   zshow_calls.<locals>._decoratorNr7  r   r   r   r+   )rD  rE  rF  r5  r+   rW  r,   
show_callsS  s   rY  envMapping[str, str]c           	        s   ddh}h d}h d}dh}d}g }|   D ]I\ }d} |v r$d}nt fd	d
|D r1d}|r`t fdd
|D rEtdd|} |v rYt||krY|d|d  d }| |f q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	SIGNATURECOVERAGE_PROCESS_CONFIG<   FTc                 3      | ]}| v V  qd S rO   r+   rk   slugr2  r+   r,   rp     r   z/relevant_environment_display.<locals>.<genexpr>c                 3  ri  rO   r+   rj  rl  r+   r,   rp     r   z\w*N   z...)r   anyr   r   rj   r    r   )	rZ  SLUGSINCLUDECLOAKTRUNCATETRUNCATE_LENto_showvalshowr+   rl  r,   relevant_environment_display|  s*   rx  )ra   r.   r   r.   )rf   rg   r   r   )rC   rz   r{   r.   rf   rg   r   r   )r:   r~   r   r.   )r   r.   r   r.   )r   r   r   r   )r   r   r   r   )r   FFF)
rB   r   r   r3   r   r3   r   r3   r   r.   )r   )rA   r   rB   r   r   r   )r   )r   r.   r   r   r   r.   )r   r   r   r   r   )r*   r   r   r.   )r   r   r   r   )r   r   r   r.   )r   r   r   r   )r   r.   r   r   r   r.   )F)r;   r.   rI   r3   r   r   )r+   F)r+  r,  r-  r   r.  r3   r   r,  rX  )TFF)rD  r3   rE  r3   rF  r3   r   r,  )rZ  r[  r   r   )GrV   
__future__r   r   r  rX   r   r@  rH   r   r   r   r   r   r   rE   r  collections.abcr   r   r   typingr   r   r   r	   r
   coverage.miscr   r   coverage.typesr   r   r   r(  r  r   rZ   r`   re   ry   r}   r   r   r   r   r   r   rL   r   r   r%   r   r   r   r   r   r   r!   r#   r$   r&   r*  r6  rC  countrN  rP  rL  rY  rx  r+   r+   r+   r,   <module>   s   G





8






d

)