B
    u9a¶|  ã               @   s²   d dl Z d dlZd dlZd dlmZmZmZ dddgZeeB eB ZG dd„ de	ƒZ
G dd„ dƒZdd	„ ZG d
d„ dƒZdd„ Zdd„ ZG dd„ deƒZdd„ Zdd„ Zdd„ ZdS )é    N)ÚCO_GENERATORÚCO_COROUTINEÚCO_ASYNC_GENERATORÚBdbQuitÚBdbÚ
Breakpointc               @   s   e Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__© r   r   ú/usr/lib/python3.7/bdb.pyr      s   c               @   sl  e Zd ZdYdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ ZdZd%d&„Zd[d'd(„Zd)d*„ Zd+d,„ Zd-d.„ Zd\d/d0„Zd1d2„ Zd3d4„ Zd]d6d7„Zd8d9„ Zd:d;„ Zd<d=„ Zd>d?„ Z d@dA„ Z!dBdC„ Z"dDdE„ Z#dFdG„ Z$dHdI„ Z%dJdK„ Z&dLdM„ Z'd^dOdP„Z(d_dQdR„Z)d`dSdT„Z*dUdV„ Z+dWdX„ Z,dS )ar   Nc             C   s(   |rt |ƒnd | _i | _i | _d | _d S )N)ÚsetÚskipÚbreaksÚfncacheÚframe_returning)Úselfr   r   r   r   Ú__init__   s    zBdb.__init__c             C   sR   |d|dd…  d kr|S | j  |¡}|sNtj |¡}tj |¡}|| j |< |S )Nú<é   éÿÿÿÿú>)r   ÚgetÚosÚpathÚabspathÚnormcase)r   ÚfilenameÚcanonicr   r   r   r   %   s    
zBdb.canonicc             C   s&   dd l }| ¡  d | _|  d d ¡ d S )Nr   )Ú	linecacheÚ
checkcacheÚbotframeÚ_set_stopinfo)r   r   r   r   r   Úreset6   s    z	Bdb.resetc             C   s–   | j r
d S |dkr|  |¡S |dkr0|  ||¡S |dkrD|  ||¡S |dkrX|  ||¡S |dkrf| jS |dkrt| jS |dkr‚| jS tdt|ƒƒ | jS )	NÚlineZcallÚreturnZ	exceptionZc_callZc_exceptionZc_returnz*bdb.Bdb.dispatch: unknown debugging event:)ÚquittingÚdispatch_lineÚdispatch_callÚdispatch_returnÚdispatch_exceptionÚtrace_dispatchÚprintÚrepr)r   ÚframeZeventÚargr   r   r   r+   =   s$    
zBdb.trace_dispatchc             C   s.   |   |¡s|  |¡r(|  |¡ | jr(t‚| jS )N)Ú	stop_hereÚ
break_hereÚ	user_liner&   r   r+   )r   r.   r   r   r   r'   h   s
    
 zBdb.dispatch_linec             C   sd   | j d kr|j| _ | jS |  |¡s0|  |¡s0d S | jrH|jjt@ rH| jS |  	||¡ | j
r^t‚| jS )N)r!   Úf_backr+   r0   Úbreak_anywhereÚ	stopframeÚf_codeÚco_flagsÚGENERATOR_AND_COROUTINE_FLAGSÚ	user_callr&   r   )r   r.   r/   r   r   r   r(   t   s    
 zBdb.dispatch_callc             C   s|   |   |¡s|| jkrv| jr,|jjt@ r,| jS z|| _|  ||¡ W d d | _X | j	rVt
‚| j|krv| jdkrv|  d d ¡ | jS )Nr   )r0   Úreturnframer5   r6   r7   r8   r+   r   Úuser_returnr&   r   Ú
stoplinenor"   )r   r.   r/   r   r   r   r)   Š   s     zBdb.dispatch_returnc             C   s   |   |¡rF|jjt@ r.|d tkr.|d d ksŠ|  ||¡ | jrŠt‚nD| jrŠ|| jk	rŠ| jjjt@ rŠ|d tt	fkrŠ|  ||¡ | jrŠt‚| j
S )Nr   é   )r0   r6   r7   r8   ÚStopIterationÚuser_exceptionr&   r   r5   ÚGeneratorExitr+   )r   r.   r/   r   r   r   r*       s    
  zBdb.dispatch_exceptionc             C   s$   x| j D ]}t ||¡rdS qW dS )NTF)r   Úfnmatch)r   Zmodule_nameÚpatternr   r   r   Úis_skipped_module¿   s    zBdb.is_skipped_modulec             C   sN   | j r|  |j d¡¡rdS || jkr@| jdkr4dS |j| jkS | jsJdS dS )Nr   Fr   T)r   rC   Ú	f_globalsr   r5   r<   Úf_lineno)r   r.   r   r   r   r0   Æ   s    

zBdb.stop_herec             C   sŒ   |   |jj¡}|| jkrdS |j}|| j| krJ|jj}|| j| krJdS t|||ƒ\}}|r„|j| _|r€|j	r€|  
t|jƒ¡ dS dS d S )NFT)r   r6   Úco_filenamer   rE   Úco_firstlinenoÚ	effectiveÚnumberZ	currentbpÚ	temporaryÚdo_clearÚstr)r   r.   r   ÚlinenoÚbpÚflagr   r   r   r1   Õ   s    

zBdb.break_herec             C   s   t dƒ‚d S )Nz)subclass of bdb must implement do_clear())ÚNotImplementedError)r   r/   r   r   r   rK   ð   s    zBdb.do_clearc             C   s   |   |jj¡| jkS )N)r   r6   rF   r   )r   r.   r   r   r   r4   ÷   s    zBdb.break_anywherec             C   s   d S )Nr   )r   r.   Zargument_listr   r   r   r9   ÿ   s    zBdb.user_callc             C   s   d S )Nr   )r   r.   r   r   r   r2     s    zBdb.user_linec             C   s   d S )Nr   )r   r.   Zreturn_valuer   r   r   r;     s    zBdb.user_returnc             C   s   d S )Nr   )r   r.   Úexc_infor   r   r   r?     s    zBdb.user_exceptionr   c             C   s   || _ || _d| _|| _d S )NF)r5   r:   r&   r<   )r   r5   r:   r<   r   r   r   r"     s    zBdb._set_stopinfoc             C   s$   |d kr|j d }|  |||¡ d S )Nr   )rE   r"   )r   r.   rM   r   r   r   Ú	set_until   s    
zBdb.set_untilc             C   s0   | j r | j j}|r |js | j|_|  d d ¡ d S )N)r   r3   Úf_tracer+   r"   )r   Zcaller_framer   r   r   Úset_step(  s
    
zBdb.set_stepc             C   s   |   |d ¡ d S )N)r"   )r   r.   r   r   r   Úset_next4  s    zBdb.set_nextc             C   s.   |j jt@ r|  |d d¡ n|  |j|¡ d S )Nr   )r6   r7   r8   r"   r3   )r   r.   r   r   r   Ú
set_return8  s    zBdb.set_returnc             C   sP   |d krt  ¡ j}|  ¡  x|r6| j|_|| _|j}qW |  ¡  t  | j¡ d S )N)	ÚsysÚ	_getframer3   r#   r+   rS   r!   rT   Úsettrace)r   r.   r   r   r   Ú	set_trace?  s    

zBdb.set_tracec             C   sL   |   | jd d¡ | jsHt d ¡ t ¡ j}x|rF|| jk	rF|`|j}q,W d S )Nr   )r"   r!   r   rW   rY   rX   r3   rS   )r   r.   r   r   r   Úset_continueN  s    

zBdb.set_continuec             C   s"   | j | _d | _d| _t d ¡ d S )NT)r!   r5   r:   r&   rW   rY   )r   r   r   r   Úset_quit]  s    zBdb.set_quitFc       
      C   sb   |   |¡}dd l}| ||¡}|s.d||f S | j |g ¡}||krN| |¡ t|||||ƒ}	d S )Nr   zLine %s:%d does not exist)r   r   Úgetliner   Ú
setdefaultÚappendr   )
r   r   rM   rJ   ÚcondÚfuncnamer   r$   ÚlistrN   r   r   r   Ú	set_breakn  s    

zBdb.set_breakc             C   s4   ||ft jkr| j|  |¡ | j| s0| j|= d S )N)r   Úbplistr   Úremove)r   r   rM   r   r   r   Ú_prune_breaks€  s    
zBdb._prune_breaksc             C   sn   |   |¡}|| jkrd| S || j| kr6d||f S x&tj||f d d … D ]}| ¡  qNW |  ||¡ d S )NzThere are no breakpoints in %szThere is no breakpoint at %s:%d)r   r   r   rd   ÚdeleteMerf   )r   r   rM   rN   r   r   r   Úclear_break  s    

zBdb.clear_breakc          
   C   sR   y|   |¡}W n& tk
r4 } zt|ƒS d }~X Y nX | ¡  |  |j|j¡ d S )N)Úget_bpbynumberÚ
ValueErrorrL   rg   rf   Úfiler$   )r   r/   rN   Úerrr   r   r   Úclear_bpbynumberž  s    zBdb.clear_bpbynumberc             C   s`   |   |¡}|| jkrd| S x6| j| D ](}tj||f }x|D ]}| ¡  q@W q(W | j|= d S )NzThere are no breakpoints in %s)r   r   r   rd   rg   )r   r   r$   ZblistrN   r   r   r   Úclear_all_file_breaks«  s    


zBdb.clear_all_file_breaksc             C   s0   | j s
dS xtjD ]}|r| ¡  qW i | _ d S )NzThere are no breakpoints)r   r   Ú
bpbynumberrg   )r   rN   r   r   r   Úclear_all_breaksº  s    zBdb.clear_all_breaksc             C   s†   |st dƒ‚yt|ƒ}W n" t k
r:   t d| ƒd ‚Y nX ytj| }W n" tk
rl   t d| ƒd ‚Y nX |d kr‚t d| ƒ‚|S )NzBreakpoint number expectedz Non-numeric breakpoint number %sz!Breakpoint number %d out of rangezBreakpoint %d already deleted)rj   Úintr   ro   Ú
IndexError)r   r/   rI   rN   r   r   r   ri   Ç  s    zBdb.get_bpbynumberc             C   s"   |   |¡}|| jko || j| kS )N)r   r   )r   r   rM   r   r   r   Ú	get_breakÛ  s    

zBdb.get_breakc             C   s4   |   |¡}|| jkr0|| j| kr0tj||f p2g S )N)r   r   r   rd   )r   r   rM   r   r   r   Ú
get_breaksá  s    

zBdb.get_breaksc             C   s&   |   |¡}|| jkr| j| S g S d S )N)r   r   )r   r   r   r   r   Úget_file_breaksë  s    


zBdb.get_file_breaksc             C   s   | j S )N)r   )r   r   r   r   Úget_all_breaksö  s    zBdb.get_all_breaksc             C   sª   g }|r|j |kr|j}x.|d k	rF| ||jf¡ || jkr>P |j}qW | ¡  tdt|ƒd ƒ}x$|d k	r†| |j |j	f¡ |j}qdW |d kr¢tdt|ƒd ƒ}||fS )Nr   r   )
Útb_frameÚtb_nextr_   rE   r!   r3   ÚreverseÚmaxÚlenÚ	tb_lineno)r   ÚfÚtÚstackÚir   r   r   Ú	get_stacký  s     




zBdb.get_stackú: c             C   sØ   dd l }dd l}|\}}|  |jj¡}d||f }|jjrH||jj7 }n|d7 }d|jkrf|jd }	nd }	|	r~|| |	¡7 }n|d7 }d|jkr°|jd }
|d7 }|| |
¡7 }| |||j	¡}|rÔ||| 
¡  7 }|S )Nr   z%s(%r)z<lambda>Z__args__z()Z
__return__z->)r   Úreprlibr   r6   rF   Úco_nameÚf_localsr-   r]   rD   Ústrip)r   Zframe_linenoZlprefixr   rƒ   r.   rM   r   ÚsÚargsÚrvr$   r   r   r   Úformat_stack_entry  s*    	


zBdb.format_stack_entryc          	   C   sŽ   |d krdd l }|j}|d kr"|}|  ¡  t|tƒr@t|ddƒ}t | j¡ z*yt	|||ƒ W n t
k
rr   Y nX W d d| _t d ¡ X d S )Nr   z<string>ÚexecT)Ú__main__Ú__dict__r#   Ú
isinstancerL   ÚcompilerW   rY   r+   r‹   r   r&   )r   ÚcmdÚglobalsÚlocalsrŒ   r   r   r   Úrun:  s    

zBdb.runc          	   C   st   |d krdd l }|j}|d kr"|}|  ¡  t | j¡ z&yt|||ƒS  tk
rX   Y nX W d d| _t d ¡ X d S )Nr   T)	rŒ   r   r#   rW   rY   r+   Úevalr   r&   )r   Úexprr‘   r’   rŒ   r   r   r   ÚrunevalP  s    
zBdb.runevalc             C   s   |   |||¡ d S )N)r“   )r   r   r‘   r’   r   r   r   Úrunctxd  s    z
Bdb.runctxc           	   O   s®   t | ƒdkr| ^}}} n>| s&tdƒ‚n0d|krB| d¡}| ^}} ntdt | ƒd  ƒ‚| ¡  t |j¡ d }z(y|| |Ž}W n tk
r’   Y nX W d d|_t d ¡ X |S )Nr=   z6descriptor 'runcall' of 'Bdb' object needs an argumentÚfuncz7runcall expected at least 1 positional argument, got %dr   T)	r{   Ú	TypeErrorÚpopr#   rW   rY   r+   r   r&   )rˆ   Úkwdsr   r˜   Zresr   r   r   Úruncallk  s&    



zBdb.runcall)N)r   )N)N)FNN)r‚   )NN)NN)-r   r	   r
   r   r   r#   r+   r'   r(   r)   r*   rC   r0   r1   rK   r4   r9   r2   r;   r?   r"   rR   rT   rU   rV   rZ   r[   r\   rc   rf   rh   rm   rn   rp   ri   rs   rt   ru   rv   r   rŠ   r“   r–   r—   rœ   r   r   r   r   r      sV   
+


 


&

c               C   s   t ƒ  ¡  d S )N)r   rZ   r   r   r   r   rZ   ‰  s    rZ   c               @   sV   e Zd ZdZi ZdgZddd„Zdd„ Zdd	„ Zd
d„ Z	ddd„Z
dd„ Zdd„ ZdS )r   r   NFc             C   s   || _ d | _|| _|| _|| _|| _d| _d| _d| _t	j
| _t	 j
d7  _
| j | ¡ ||f| jkr|| j||f  | ¡ n| g| j||f< d S )NTr   r   )ra   Úfunc_first_executable_linerk   r$   rJ   r`   ÚenabledÚignoreÚhitsr   ÚnextrI   ro   r_   rd   )r   rk   r$   rJ   r`   ra   r   r   r   r   ©  s    zBreakpoint.__init__c             C   s>   | j | jf}d | j| j< | j|  | ¡ | j| s:| j|= d S )N)rk   r$   ro   rI   rd   re   )r   Úindexr   r   r   rg   ½  s
    
zBreakpoint.deleteMec             C   s
   d| _ d S )NT)rž   )r   r   r   r   ÚenableË  s    zBreakpoint.enablec             C   s
   d| _ d S )NF)rž   )r   r   r   r   ÚdisableÏ  s    zBreakpoint.disablec             C   s"   |d krt j}t|  ¡ |d d S )N)rk   )rW   Ústdoutr,   Úbpformat)r   Úoutr   r   r   ÚbpprintÓ  s    zBreakpoint.bpprintc             C   sš   | j rd}nd}| jr |d }n|d }d| j|| j| jf }| jrT|d| jf 7 }| jrj|d| jf 7 }| jr–| jdkr€d	}nd
}|d| j|f 7 }|S )Nzdel  zkeep zyes  zno   z%-4dbreakpoint   %s at %s:%dz
	stop only if %sz
	ignore next %d hitsr   r‡   Ú z"
	breakpoint already hit %d time%s)rJ   rž   rI   rk   r$   r`   rŸ   r    )r   ZdispÚretÚssr   r   r   r¦   Ý  s$    

zBreakpoint.bpformatc             C   s   d| j | j| jf S )Nzbreakpoint %s at %s:%s)rI   rk   r$   )r   r   r   r   Ú__str__û  s    zBreakpoint.__str__)FNN)N)r   r	   r
   r¡   rd   ro   r   rg   r£   r¤   r¨   r¦   r¬   r   r   r   r   r   Ž  s   


c             C   sN   | j s| j|jkrdS dS |jj| j kr,dS | js:|j| _| j|jkrJdS dS )NFT)ra   r$   rE   r6   r„   r   )Úbr.   r   r   r   Úcheckfuncname  s    r®   c             C   sº   t j| |f }x¦|D ]ž}|js qt||ƒs,q| jd7  _|jsf|jdkr\| jd8  _qq²|dfS qy<t|j|j|j	ƒ}|r |jdkr˜| jd8  _n|dfS W q   |dfS qW dS )Nr   r   TF)NN)
r   rd   rž   r®   r    r`   rŸ   r”   rD   r…   )rk   r$   r.   Z	possiblesr­   Úvalr   r   r   rH   $  s*    




rH   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTdbc             C   s    |j j}|sd}td||ƒ d S )Nz???z+++ call)r6   r„   r,   )r   r.   rˆ   Únamer   r   r   r9   U  s     zTdb.user_callc             C   sT   dd l }|jj}|sd}|  |jj¡}| ||j|j¡}td||j|d| 	¡ ƒ d S )Nr   z???z+++ú:)
r   r6   r„   r   rF   r]   rE   rD   r,   r†   )r   r.   r   r±   Úfnr$   r   r   r   r2   Y  s     zTdb.user_linec             C   s   t d|ƒ d S )Nz
+++ return)r,   )r   r.   Zretvalr   r   r   r;   `  s    zTdb.user_returnc             C   s   t d|ƒ |  ¡  d S )Nz+++ exception)r,   r[   )r   r.   Z	exc_stuffr   r   r   r?   b  s    
zTdb.user_exceptionN)r   r	   r
   r9   r2   r;   r?   r   r   r   r   r°   T  s   r°   c             C   s&   t d| dƒ t| d ƒ}t d|ƒ d S )Nzfoo(ú)é
   zbar returned)r,   Úbar)ÚnÚxr   r   r   Úfoof  s    r¹   c             C   s   t d| dƒ | d S )Nzbar(r´   r=   )r,   )Úar   r   r   r¶   k  s    r¶   c              C   s   t ƒ } |  d¡ d S )Nzimport bdb; bdb.foo(10))r°   r“   )r~   r   r   r   Útesto  s    r»   )rA   rW   r   Úinspectr   r   r   Ú__all__r8   Ú	Exceptionr   r   rZ   r   r®   rH   r°   r¹   r¶   r»   r   r   r   r   Ú<module>   s&   
    |t"0