B
    ê¹`06  ã               @   s–  d 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yddlZW n e	k
rd   ddl
ZY nX ddlmZmZ ddlmZ eeƒZg ZdZG dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZdd„ Zdd„ Zdd„ Zd6dd„Zd7dd„Zd8dd„Zdd„ Zdd„ ZG dd„ deƒZdd„ Zd d!„ Z d"d#„ Z!G d$d%„ d%eƒZ"G d&d'„ d'eƒZ#d9d)d*„Z$d:d,d-„Z%d.d/„ Z&e '¡ Z(e '¡ Z)d0Z*d;d2d3„Z+d4d5„ Z,dS )<z'Control of and utilities for debugging.é    N)ÚreprlibÚStringIO)Úisolate_modulec               @   sB   e Zd ZdZdZdd„ Zdd„ Zdd„ Zej	d	d
„ ƒZ
dd„ ZdS )ÚDebugControlz!Control and output for debugging.Fc             C   sR   t |ƒt | _d| _g }|  d¡r,| t¡ tj||  d¡|d| _	| j	j
| _dS )z4Configure the options and output file for debugging.FÚpidÚprocess)Úshow_processÚfiltersN)ÚlistÚFORCED_DEBUGÚoptionsÚsuppress_callersÚshouldÚappendÚadd_pid_and_tidÚDebugOutputFileÚget_oneÚoutputÚoutfileÚ
raw_output)Úselfr   r   r	   © r   úV/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/coverage/debug.pyÚ__init__$   s    


zDebugControl.__init__c             C   s   d| j | jf S )Nz'<DebugControl options=%r raw_output=%r>)r   r   )r   r   r   r   Ú__repr__3   s    zDebugControl.__repr__c             C   s   |dkr| j rdS || jkS )z@Decide whether to output debug information in category `option`.ÚcallersF)r   r   )r   Úoptionr   r   r   r   6   s    zDebugControl.shouldc             c   s$   | j }d| _ z
dV  W d|| _ X dS )z;A context manager to prevent call stacks from being logged.TN)r   )r   Úoldr   r   r   Úwithout_callers<   s
    
zDebugControl.without_callersc             C   sr   | j  |d ¡ |  d¡rLt ¡ d d j d¡}|dk	rL| j  d |¡¡ |  d¡rdt| j dd | j  	¡  dS )	zhWrite a line of debug output.

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

        Ú
r   é   r   Nzself: {!r}
r   )ÚoutÚskip)
r   Úwriter   ÚinspectÚstackÚf_localsÚgetÚformatÚdump_stack_framesÚflush)r   ÚmsgZcaller_selfr   r   r   r#   F   s    

zDebugControl.writeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úshow_repr_attrr   r   r   Ú
contextlibÚcontextmanagerr   r#   r   r   r   r   r      s   
r   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚDebugControlStringz8A `DebugControl` that writes to a StringIO, for testing.c                s   t t| ƒ |tƒ ¡ d S )N)Úsuperr3   r   r   )r   r   )Ú	__class__r   r   r   X   s    zDebugControlString.__init__c             C   s
   | j  ¡ S )z,Get the output text from the `DebugControl`.)r   Úgetvalue)r   r   r   r   Ú
get_output[   s    zDebugControlString.get_output)r,   r-   r.   r/   r   r7   Ú__classcell__r   r   )r5   r   r3   V   s   r3   c               @   s   e Zd ZdZdd„ ZdS )ÚNoDebuggingzBA replacement for DebugControl that will never try to do anything.c             C   s   dS )z'Should we write debug messages?  Never.Fr   )r   r   r   r   r   r   b   s    zNoDebugging.shouldN)r,   r-   r.   r/   r   r   r   r   r   r9   `   s   r9   c             C   s   d  d|  d ¡S )zMake a nice header string.z
--{:-<60s}ú )r(   )Úlabelr   r   r   Úinfo_headerg   s    r<   c             #   s¤   t | ƒ} | sdS d‰ t‡ fdd„| D ƒƒs.t‚xp| D ]h\}}|g krHd}t|t ttfƒrŒdˆ |f }x6|D ]}dˆ d ||f V  d	}qjW q4d
ˆ ||f V  q4W dS )z¦Produce 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 )N)Úlen)Ú.0ÚlÚ_)Ú	label_lenr   r   ú	<genexpr>w   s    z!info_formatter.<locals>.<genexpr>z-none-z%*s:z%*s %sr    Ú z%*s: %s)r
   ÚallÚAssertionErrorÚ
isinstanceÚsetÚtuple)Úinfor;   ÚdataÚprefixÚer   )rB   r   Úinfo_formatterl   s    

rN   c             C   s2   |   t|ƒ¡ xt|ƒD ]}|   d| ¡ qW dS )z.Write a sequence of (label,data) pairs nicely.z %sN)r#   r<   rN   )ÚwriterÚheaderrJ   Úliner   r   r   Úwrite_formatted_info„   s    rR   c             C   s&   t  ¡ | |d… }d dd„ |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
        ...

    `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   c             s   s(   | ] }d |d |d |d f V  qdS )z%30s : %s:%dé   r    é   Nr   )r?   Útr   r   r   rC   ž   s    zshort_stack.<locals>.<genexpr>)r$   r%   Újoin)Úlimitr"   r%   r   r   r   Úshort_stack‹   s    rY   c             C   s.   |pt j}| t| |d d¡ | d¡ dS )z:Print a summary of the stack to stdout, or someplace else.r    )rX   r"   r   N)ÚsysÚstdoutr#   rY   )rX   r!   r"   r   r   r   r)   ¡   s    
r)   é2   c             C   s   t  ¡ }||_| | ¡S )z(`repr(text)`, but limited to `numchars`.)r   ÚReprÚ	maxstringÚrepr)ÚtextÚnumcharsÚrr   r   r   Úclipped_repr¨   s    rc   c             C   s.   d}x t dddƒD ]}|| |? N }qW |d@ S )z-Given a 64-bit id, make a shorter 16-bit one.r   é@   é   iÿÿ  )Úrange)Zid64Zid16Úoffsetr   r   r   Úshort_id¯   s    rh   c             C   s(   d  tt ¡ ƒ¡}d  t ¡ || ¡} | S )z.A filter to add pid and tid to debug messages.z{:04x}z{:5d}.{}: {})r(   rh   Ú_threadÚ	get_identÚosÚgetpid)r`   Útidr   r   r   r   ·   s    r   c               @   s    e Zd ZdZddgZdd„ ZdS )ÚSimpleReprMixinz'A mixin implementing a simple __repr__.Úsimple_repr_ignorez$coverage.object_idc                s@   ‡ fdd„ˆ j  ¡ D ƒ}djˆ jjtˆ ƒd dd„ |D ƒ¡dS )Nc             3   s8   | ]0\}}t |d dƒrt|ƒs|ˆ jkr||fV  qdS )r0   TN)ÚgetattrÚcallablero   )r?   ÚkÚv)r   r   r   rC   Å   s    z+SimpleReprMixin.__repr__.<locals>.<genexpr>z<{klass} @0x{id:x} {attrs}>r:   c             s   s   | ]\}}d   ||¡V  qdS )z{}={!r}N)r(   )r?   rr   rs   r   r   r   rC   Í   s    )ÚklassÚidÚattrs)Ú__dict__Úitemsr(   r5   r,   ru   rW   )r   Z
show_attrsr   )r   r   r   Ã   s
    zSimpleReprMixin.__repr__N)r,   r-   r.   r/   ro   r   r   r   r   r   rn   ¿   s   rn   c             C   sj   t | tƒrdd„ |  ¡ D ƒS t | ttfƒr@t| ƒdd„ | D ƒƒS t| dƒrbtdd„ | j ¡ D ƒƒS | S dS )z>Turn things which are nearly dict/list/etc into dict/list/etc.c             S   s   i | ]\}}t |ƒ|“qS r   )Úsimplify)r?   rr   Úvvr   r   r   ú
<dictcomp>Ô   s    zsimplify.<locals>.<dictcomp>c             s   s   | ]}t |ƒV  qd S )N)ry   )r?   rz   r   r   r   rC   Ö   s    zsimplify.<locals>.<genexpr>rw   c             S   s   i | ]\}}|d | “qS )Ú.r   )r?   rr   rs   r   r   r   r{   Ø   s    N)	rG   Údictrx   r
   rI   ÚtypeÚhasattrry   rw   )rs   r   r   r   ry   Ñ   s    

ry   c             C   s   t   t| ƒ¡ dS )zEDebug helper to pretty-print data, including SimpleNamespace objects.N)Úpprintry   )rs   r   r   r   ÚppÝ   s    r   c             C   sd   |   ¡ }| t|ƒd… }|} x>|D ]6}g }x"|  ¡ D ]}| ||ƒ ¡ ¡ q4W d |¡} q"W | | S )zë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.

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

    Nr   )Úrstripr>   Ú
splitlinesÚextendrW   )r`   r	   Z
clean_textÚendingÚfnÚlinesrQ   r   r   r   Úfilter_textã   s    

rˆ   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
CwdTrackerz*A class to add cwd info to debug messages.c             C   s
   d | _ d S )N)Úcwd)r   r   r   r   r   ú   s    zCwdTracker.__init__c             C   s*   t  ¡ }|| jkr&d |¡| }|| _|S )z#Add a cwd message for each new cwd.zcwd is now {!r}
)rk   ÚgetcwdrŠ   r(   )r   r`   rŠ   r   r   r   Úfilterý   s
    
zCwdTracker.filterN)r,   r-   r.   r/   r   rŒ   r   r   r   r   r‰   ø   s   r‰   c               @   s:   e Zd ZdZdd„ ZdZedd	d
„ƒZdd„ Zdd„ Z	dS )r   z9A file-like object that includes pid and cwd information.c             C   s€   || _ || _t|ƒ| _| jr|| j dtƒ j¡ |  dtj	f ¡ |  dt
tdd ƒf ¡ ttdƒr||  dt ¡ t ¡ f ¡ d S )Nr   zNew process: executable: %r
zNew process: cmd: %r
ÚargvÚgetppidz%New process: pid: %r, parent pid: %r
)r   r   r
   r	   Úinsertr‰   rŒ   r#   rZ   Ú
executablerp   r   rk   rl   rŽ   )r   r   r   r	   r   r   r   r     s    

zDebugOutputFile.__init__z'$coverage.debug.DebugOutputFile.the_oneNTr   Fc             C   s€   |dk	r| |||ƒS t j | jd¡\}}|dks4|r||dkr`tj dt¡}|rZt|dƒ}nt j}| |||ƒ}||ft j| j< |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
        (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.

        N)NTZCOVERAGE_DEBUG_FILEÚa)	rZ   Úmodulesr'   ÚSYS_MOD_NAMErk   ÚenvironÚFORCED_DEBUG_FILEÚopenÚstderr)ÚclsÚfileobjr   r	   ÚinterimZthe_oneZ
is_interimZdebug_file_namer   r   r   r     s    zDebugOutputFile.get_onec             C   s"   | j  t|| jƒ¡ | j  ¡  dS )z9Just like file.write, but filter through all our filters.N)r   r#   rˆ   r	   r*   )r   r`   r   r   r   r#   =  s    zDebugOutputFile.writec             C   s   | j  ¡  dS )zFlush our file.N)r   r*   )r   r   r   r   r*   B  s    zDebugOutputFile.flush)NTr   F)
r,   r-   r.   r/   r   r“   Úclassmethodr   r#   r*   r   r   r   r   r     s   &r   Fc             C   s.   t jdd}| | d ¡ |r*t|dd dS )z.Write a log message as forcefully as possible.T)rš   r   r    )r!   r"   N)r   r   r#   r)   )r+   r%   r!   r   r   r   ÚlogG  s    rœ   r   c                s   ‡ ‡‡fdd„}|S )z2A class decorator to apply a decorator to methods.c                s^   xXt  | t j¡D ]F\}}|| jkr$q|dkr<ˆs<| d¡r<q|ˆ krFqt| |ˆ|ƒƒ qW | S )Nr   rA   )r$   Ú
getmembersÚ	isroutinerw   Ú
startswithÚsetattr)r˜   ÚnameÚmeth)ÚbutnotÚ	decoratorÚprivater   r   Ú
_decoratorQ  s    
z$decorate_methods.<locals>._decoratorr   )r¤   r£   r¥   r¦   r   )r£   r¤   r¥   r   Údecorate_methodsO  s    r§   c                s   t  ˆ ¡‡ fdd„ƒ}|S )z;A function decorator to stop in the debugger for each call.c                 s"   dd l }tjt_| ¡  ˆ | |ŽS )Nr   )ÚpudbrZ   Ú
__stdout__r[   Ú	set_trace)ÚargsÚkwargsr¨   )Úfuncr   r   Ú_wrappera  s    zbreak_in_pudb.<locals>._wrapper)Ú	functoolsÚwraps)r­   r®   r   )r­   r   Úbreak_in_pudb_  s    r±   z$coverage.object_idTc                s   ‡ ‡‡fdd„}|S )z:A method decorator to debug-log each call to the function.c                s    t  ˆ ¡‡ ‡‡‡fdd„ƒ}|S )Nc       
         s(  t | td ƒ}|d kr4d t ¡ ttƒ¡}t| t|ƒ d}ˆr”d t	t
|ƒ¡}d dd„ | ¡ D ƒ¡}|d7 }||7 }|r„|r„|d7 }||7 }|d7 }ˆr¾|d7 }|d	 d
d„ tƒ  ¡ D ƒ¡7 }ttƒ}d ||ˆ j|¡}tjdd |¡ ˆ | f|ž|Ž}	ˆr$d ||ˆ j|	¡}tjdd |¡ |	S )Nz{:08d} {:04d}rD   z, c             s   s   | ]}d j |Ž V  qdS )z{}={!r}N)r(   )r?   Úitemr   r   r   rC   z  s    zCshow_calls.<locals>._decorator.<locals>._wrapper.<locals>.<genexpr>ú(ú)z @ z; c             s   s   | ]}t |ƒV  qd S )N)Ú_clean_stack_line)r?   r@   r   r   r   rC   ƒ  s    z{} {:04d} {}{}
T)rš   z{} {:04d} {} return {!r}
)rp   ÚOBJ_ID_ATTRr(   rk   rl   ÚnextÚOBJ_IDSr    rW   Úmapr_   rx   rY   rƒ   ÚCALLSr,   r   r   r#   )
r   r«   r¬   ÚoidÚextraZeargsZekwargsZcallidr+   Úret)r­   Ú	show_argsÚshow_returnÚ
show_stackr   r   r®   q  s2    z0show_calls.<locals>._decorator.<locals>._wrapper)r¯   r°   )r­   r®   )r¾   r¿   rÀ   )r­   r   r¦   p  s    zshow_calls.<locals>._decoratorr   )r¾   rÀ   r¿   r¦   r   )r¾   r¿   rÀ   r   Ú
show_callsn  s    rÁ   c             C   sP   |   ¡ } |  tj t¡d d¡} |  tj tj¡d d¡} |  tjd d¡} | S )z6Simplify some paths in a stack trace, for compactness.ú/rD   )ÚstripÚreplacerk   ÚpathÚdirnameÚ__file__rZ   rL   )Úsr   r   r   rµ     s
    rµ   )Nr   )NNr   )r\   )F)r   F)TFF)-r/   r1   r¯   r$   Ú	itertoolsrk   r€   rZ   ri   ÚImportErrorÚthreadZcoverage.backwardr   r   Zcoverage.miscr   r   r•   Úobjectr   r3   r9   r<   rN   rR   rY   r)   rc   rh   r   rn   ry   r   rˆ   r‰   r   rœ   r§   r±   Úcountr¸   rº   r¶   rÁ   rµ   r   r   r   r   Ú<module>   sR   7



A


"