o
    g(Q                     @  sh  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mZ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%drddZ&dsddZ'dtddZ(dudd Z)d!gZ*d"e"d#< g Z+d"e"d$< edvd&d'Z,edwd(d'Z,dxd*d'Z,		+	+	+dydzd2d3Z-d{d|d6d7Z.d}d~d;d<Z/dd>d?Z0dd@dAZ1dBhZ2ddEdFZ3ddHdIZ4ddJdKZ5ddNdOZ6G dPdQ dQZ7G dRdS dSZ8G dTdU dUZ9G dVdW dWZ:dddZd[Z;	\	+dddbdcZ<ddfdgZ=e> Z?e> Z@dBZA	h	+	+dddldmZBddpdqZCdS )z'Control of and utilities for debugging.    )annotationsN)
overloadAnyCallableIOIterableIteratorMappingOptionalListTuple)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Optional[IO[str]]	file_nameOptional[str]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-   N/var/www/html/bloggers_ems/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__G   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,   r4   r-   r-   r.   r!   J   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_callersP   s   zDebugControl.without_callersexcmsgr<   Optional[BaseException]c             	   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: r6   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.   rE   Z   s   	

zDebugControl.writeN)r   r   r   r   r   r   r   r   )r   r0   r4   r0   r   r5   )r   r8   r=   r0   r<   r>   r   r   )__name__
__module____qualname____doc__show_repr_attrr/   r3   r!   
contextlibcontextmanagerr:   rE   r-   r-   r-   r.   r   (   s    

	r   c                   @  s4   e Zd ZdZdddZ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 rQ   r-   r2   r-   r-   r.   r/   q      zNoDebugging.__init__r4   r0   r5   c                 C  s   dS )z'Should we write debug messages?  Never.Fr-   r7   r-   r-   r.   r!   u   r]   zNoDebugging.shouldNr;   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.   rE   y   s   zNoDebugging.writer   r   rR   rS   )rT   rU   rV   rW   r/   r!   rE   r-   r-   r-   r.   r[   o   s
    

r[   labelr0   r   c                 C  s   d d|  d S )zMake a nice header string.z
--{:-<60s} format)r`   r-   r-   r.   info_header~   s   rd   infoIterable[Tuple[str, Any]]Iterator[str]c                 #  s    t | } | s	dS d t fdd| D sJ | D ]L\}}|g kr$d}t|tr>ttt|dk r>d |t|f V  qt|t ttfr^d |f }|D ]}d d	 ||f V  d
}qNqd ||f 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 rQ   len).0l_	label_lenr-   r.   	<genexpr>   s    z!info_formatter.<locals>.<genexpr>z-none-z%*s: %rz%*s:z%*s %srA   r@   z%*s: %s)r   all
isinstancetuplerj   reprset)re   r`   dataprefixer-   rn   r.   info_formatter   s&   ry   rE   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.

    ra   N)rd   ry   )rE   r{   re   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 rQ   )rstrip)rk   rl   r-   r-   r.   rp          zexc_one_line.<locals>.<genexpr>)rG   format_exception_onlytyperF   )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\   rQ   r-   r   r-   r-   r.   short_filename   r]   r   c                 C  r\   rQ   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   
FrD   intfullr5   	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 rQ   )r   searchr   )fir   r-   r-   r.   r      s    zshort_stack.<locals>.<lambda>z>30sz : z#xra   :r?   )rJ   rK   	itertools	dropwhilefunctionidframer   r   linenor"   rF   )rD   r   r   r   BORING_PRELUDErK   r   r   
frame_infor|   r   r-   r-   r.   short_stack   s&   

r   rC   r   c                 C  s   |  t|d dd  dS )z&Print a summary of the stack to `out`.rA   )rD   r?   N)rE   r   rB   r-   r-   r.   rN   	  s   rN   2   textnumcharsc                 C  s   t  }||_|| S )z(`repr(text)`, but limited to `numchars`.)reprlibRepr	maxstringrt   )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_id  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.z: )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 )rX   TN)getattrrJ   ismethodAUTO_REPR_IGNORErk   kvr-   r-   r.   rp   )  s    
zauto_repr.<locals>.<genexpr>z<{klass} @{id:#x}{attrs}>r@   c                 s  s$    | ]\}}d | d|V  qdS )ra   =Nr-   r   r-   r-   r.   rp   2  s   " )klassr   attrs)__dict__itemsrc   	__class__rT   r   rF   )r,   
show_attrsr-   r-   r.   	auto_repr'  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>9      zsimplify.<locals>.<dictcomp>c                 s  s    | ]}t |V  qd S rQ   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   )	rr   dictr   r   rs   r   hasattrr   r   r   r-   r-   r.   r   6  s   

r   c                 C  s   t  t|  dS )zEDebug helper to pretty-print data, including SimpleNamespace objects.N)pprintr   r   r-   r-   r.   ppB  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extendrF   )r   r   
clean_textending	filter_fnr   r|   r-   r-   r.   filter_textH  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 rQ   )cwdr2   r-   r-   r.   r/   `     
zCwdTracker.__init__r   r0   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$   c  s
   
zCwdTracker.filterNr_   r   r0   r   r0   rT   rU   rV   rW   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_welcomer2   r-   r-   r.   r/   n  s   

zProcessTracker.__init__r   r0   c                 C  s   d}t  }| j|krd| j d| d}|| _n(| jsAttdd}d|dtjdd	|d }tt d
rA|dt  d7 }|rJd| _|| 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: getppidzNew process parent pid: T)	r   r   r   r   r   r   
executabler   r   )r,   r   welcomer   r   r-   r-   r.   r$   r  s"   


zProcessTracker.filterNr_   r   r   r-   r-   r-   r.   r%   l  s    
r%   c                   @  r   )r&   z<Track the current pytest test name to add to debug messages.r   r   c                 C  r   rQ   )	test_namer2   r-   r-   r.   r/     r   zPytestTracker.__init__r   r0   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                   @  sx   e Zd ZdZd$ddZe					
d%d&ddZdZdZ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 rQ   )r*   r   r   r   r   r   )r,   r*   r   r-   r-   r.   r/     s   
zDebugOutputFile.__init__Nr-   Ffileobjr   r   interimr5   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_onethe_one_and_is_interimr  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
ModuleTypeSYS_MOD_NAMEsetattrSINGLETON_ATTRr   modules)r  r  r   singleton_moduler-   r-   r.   r    s   z#DebugOutputFile._set_singleton_data&Tuple[Optional[DebugOutputFile], bool]c                 C  s   t j| j}t|| jdS )zGet the one DebugOutputFile.)NT)r   r  rM   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   r0   c                 C  s0   | j dusJ | j t|| j | j   dS )z9Just like file.write, but filter through all our filters.N)r*   rE   r   r   rO   )r,   r   r-   r-   r.   rE     s   zDebugOutputFile.writec                 C  s   | j dusJ | j   dS )zFlush our file.N)r*   rO   r2   r-   r-   r.   rO     s   zDebugOutputFile.flush)r*   r   r   r   )NNr-   F)
r   r   r   r   r   r   r   r5   r   r(   )r  r(   r   r5   r   r   )r   r  r_   )r   r0   r   r   )rT   rU   rV   rW   r/   classmethodr)   r	  r  r  r   r  rE   rO   r-   r-   r-   r.   r(     s&    
	3
r(   r=   rK   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?   rA   rB   N)r(   r)   rE   rN   )r=   rK   rC   r-   r-   r.   log  s
   r  r-   	decoratorCallable[..., Any]butnotr   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   )rJ   
getmembers	isroutiner   
startswithr
  )r  namemethr  r  r  r-   r.   
_decorator  s   
z$decorate_methods.<locals>._decoratorr-   )r  r  r  r  r-   r  r.   decorate_methods   s   r  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)r   r!  r"  r  r-   r.   _wrapper  s   zbreak_in_pudb.<locals>._wrapperN)r   r   r!  r   r   r   	functoolswrapsr  r&  r-   r%  r.   break_in_pudb  s   r+  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.r  r   r   c                   s"   t  d fdd}|S )	Nr,   r   r   r!  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08dra   04dr@   z, c                 s  s    | ]}d j | V  qdS )z{}={!r}Nrb   )rk   itemr-   r-   r.   rp   3  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
  rF   maprt   r   r   r   CALLSrT   r(   r)   rE   )
r,   r   r!  oidextraeargsekwargscallidr=   ret)r  r,  r.  r-  r-   r.   r&  *  s2    z0show_calls.<locals>._decorator.<locals>._wrapper)r,   r   r   r   r!  r   r   r   r'  r*  r,  r.  r-  r%  r.   r  )  s   zshow_calls.<locals>._decoratorNr  r   r   r   r-   )r,  r-  r.  r  r-   r?  r.   
show_calls#  s   rA  envMapping[str, str]c                   s   ddh}h d}h d}g }|   D ]5\ }d} |v rd}nt fdd|D r,d}|rGt fd	d|D r@t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	SIGNATUREFTc                 3      | ]}| v V  qd S rQ   r-   rk   slugr  r-   r.   rp   _  r   z/relevant_environment_display.<locals>.<genexpr>c                 3  rO  rQ   r-   rP  rR  r-   r.   rp   b  r   z\w*)r   anyr   r   r"   r   )rB  slugsincludecloakto_showvalkeepr-   rR  r.   relevant_environment_displayI  s    r[  )r`   r0   r   r0   )re   rf   r   rg   )rE   rz   r{   r0   re   rf   r   r   )r<   r~   r   r0   )r   r0   r   r0   )r   r   r   r   )r   r   r   r   )r   FFF)
rD   r   r   r5   r   r5   r   r5   r   r0   )r   )rC   r   rD   r   r   r   )r   )r   r0   r   r   r   r0   )r   r   r   r   r   )r,   r   r   r0   )r   r   r   r   )r   r   r   r   )r   r0   r   r   r   r0   )F)r=   r0   rK   r5   r   r   )r-   F)r  r  r  r   r  r5   r   r  r@  )TFF)r,  r5   r-  r5   r.  r5   r   r  )rB  rC  r   r   )DrW   
__future__r   r   rY   r(  rJ   r   r   r   r   r   r   rG   r  r   typingr   r   r   r   r   r   r	   r
   r   r   coverage.miscr   r   coverage.typesr   r   r   __annotations__r   r   r[   rd   ry   r}   r   r   r   r   r   rN   r   r   r'   r   r   r   r   r   r#   r%   r&   r(   r  r  r+  countr6  r8  r4  rA  r[  r-   r-   r-   r.   <module>   s   0G




6





a

&