B
    u9aô  ã            "   @   sà  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G dd„ deƒZdddddd	d
ddg	Zdd„ Zdd„ Zdd„ ZG dd„ deƒZdZG dd„ dejejƒZedk	r^ddddddddddd d!d"d#d$d%d&d'dd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6g"Zx*eD ]"Zeeed7e ƒj ¡ d8 7 Zq(W eejj7 Z[[dId9d„ZdJd:d„Z d;d„ Z!d<d	„ Z"dd=œd>d
„Z#dKd?d„Z$d@d„ Z%dAZ&dBdC„ Z'dDd„ Z(dEZ)dFdG„ Z*e+dHkrÜd dl,Z,e, *¡  dS )Lé    Nc               @   s   e Zd ZdS )ÚRestartN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú/usr/lib/python3.7/pdb.pyr   U   s   r   ÚrunÚpmÚPdbÚrunevalÚrunctxÚruncallÚ	set_traceÚpost_mortemÚhelpc          	   C   sx   t  dt  | ¡ ¡}yt|ƒ}W n tk
r4   d S X |4 x,t|ddD ]\}}| |¡rJ| ||fS qJW W d Q R X d S )Nzdef\s+%s\s*[(]é   )Ústart)ÚreÚcompileÚescapeÚopenÚOSErrorÚ	enumerateÚmatch)ÚfuncnameÚfilenameZcreÚfpÚlinenoÚliner   r   r   Úfind_function\   s    
r   c             C   sX   t  | ¡\}}t  | ¡r,| j| jkr,|dfS t  | ¡r>|dfS t  ||d … ¡|d fS )Nr   )ÚinspectZ
findsourceZisframeÚ	f_globalsÚf_localsZismoduleZgetblock)ÚobjÚlinesr   r   r   r   Úgetsourcelinesi   s    
r%   c             C   s8   t t | ¡ƒ}| ¡  x|D ]\}}||kr|S qW dS )Nr   )ÚlistÚdisZfindlinestartsÚreverse)ÚcodeZlastiZ
linestartsÚir   r   r   r   Úlasti2linenor   s    r+   c               @   s   e Zd Zdd„ ZdS )Ú_rstrc             C   s   | S )Nr   )Úselfr   r   r   Ú__repr__}   s    z_rstr.__repr__N)r   r   r   r.   r   r   r   r   r,   {   s   r,   z
-> c               @   s  e Zd ZdZd£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d%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ ZeZd¤d8d9„Zd:d;„ ZeZ eZ!eZ"d<d=„ Z#eZ$d>d?„ Z%d@dA„ Z&dBdC„ Z'eZ(dDdE„ Z)eZ*dFdG„ Z+eZ,dHdI„ Z-eZ.dJdK„ Z/e/Z0eZ1eZ2dLdM„ Z3e3Z4e3Z5dNdO„ Z6dPdQ„ Z7e7Z8dRdS„ Z9e9Z:dTdU„ Z;e;Z<dVdW„ Z=e=Z>dXdY„ Z?e?Z@dZd[„ ZAeAZBd\d]„ ZCeCZDd^d_„ ZEeE ZFZGd`da„ ZHeHZIdbdc„ ZJeZKddde„ ZLeLZMeLZNdfdg„ ZOdhdi„ ZPePZQdjdk„ ZReRZSdldm„ ZTd¥dndo„ZUdpdq„ ZVdrds„ ZWeZXeZYeZZdtdu„ Z[e[Z\dvdw„ Z]e]Z^dxdy„ Z_eZ`d¦d{d|„Zad}d~„ ZbeZcdd€„ ZdeZedd‚„ Zfdƒd„„ Zgd…d†„ Zhd‡dˆ„ Zid‰dŠ„ Zjd‹dŒ„ ZkddŽddd‘d’gZld“d”„ Zmenfd•d–„Zod—d˜„ ZpepZqd™dš„ Zrd›dœ„ Zsddž„ ZtdŸd „ Zud¡d¢„ ZvdS )§r
   NÚtabFTc       
   	   C   sJ  t jj| |d tj | |||¡ |r,d| _d| _i | _i | _d| _	d| _
i | _ydd l}| d¡ W n tk
rz   Y nX d| _|| _g | _|r(dtjkrìtjd }y.ttj |d¡ƒ}	| j |	¡ W d Q R X W n tk
rê   Y nX y$tdƒ}	| j |	¡ W d Q R X W n tk
r&   Y nX i | _i | _i | _d| _d | _d S )	N)Úskipr   z(Pdb) Ú Fz 	
`@#$%^&*()=+[{]}\|;:'",<>?ÚHOMEz.pdbrc)ÚbdbÚBdbÚ__init__ÚcmdÚCmdZuse_rawinputÚpromptÚaliasesÚ
displayingÚ
mainpyfileÚ_wait_for_mainpyfileÚ	tb_linenoÚreadlineZset_completer_delimsÚImportErrorÚallow_kbdintÚnosigintÚrcLinesÚosÚenvironr   ÚpathÚjoinÚextendr   ÚcommandsÚcommands_dopromptÚcommands_silentÚcommands_definingÚcommands_bnum)
r-   ÚcompletekeyÚstdinÚstdoutr0   rA   Zreadrcr>   ZenvHomeZrcFiler   r   r   r5   Œ   sH    


zPdb.__init__c             C   s*   | j r
t‚|  d¡ |  ¡  |  |¡ d S )Nz-
Program interrupted. (Use 'cont' to resume).)r@   ÚKeyboardInterruptÚmessageÚset_stepr   )r-   ZsignumÚframer   r   r   Úsigint_handler¼   s
    
zPdb.sigint_handlerc             C   s   t j | ¡ |  ¡  d S )N)r3   r4   ÚresetÚforget)r-   r   r   r   rU   Ã   s    z	Pdb.resetc             C   s&   d | _ g | _d| _d | _| j ¡  d S )Nr   )r   ÚstackÚcurindexÚcurframer=   Úclear)r-   r   r   r   rV   Ç   s
    z
Pdb.forgetc             C   sl   |   ¡  |  ||¡\| _| _x*|rFt|jj|jƒ}|| j|j< |j	}qW | j| j d | _
| j
j| _|  ¡ S )Nr   )rV   Z	get_stackrW   rX   r+   Útb_frameÚf_codeÚtb_lastir=   Útb_nextrY   r"   Úcurframe_localsÚexecRcLines)r-   ÚfÚtbr   r   r   r   ÚsetupÎ   s    

z	Pdb.setupc             C   sh   | j s
d S | j }| ¡  g | _ xD|rb| ¡  ¡ }|r |d dkr |  |¡r |  j t|ƒ7  _ dS q W d S )Nr   ú#T)rB   r(   ÚpopÚstripÚonecmdÚreversed)r-   rB   r   r   r   r   r`   à   s    
zPdb.execRcLinesc             C   s.   | j r
d S |  |¡r*|  d¡ |  |d ¡ d S )Nz--Call--)r<   Z	stop_hererQ   Úinteraction)r-   rS   Zargument_listr   r   r   Ú	user_callô   s
    

zPdb.user_callc             C   sH   | j r.| j|  |jj¡ks$|jdkr(d S d| _ |  |¡rD|  |d ¡ d S )Nr   F)r<   r;   Úcanonicr\   Úco_filenameÚf_linenoÚbp_commandsri   )r-   rS   r   r   r   Ú	user_lineý   s    

zPdb.user_linec             C   s˜   t | ddƒr”| j| jkr”| j}d| _| j}|  |d ¡ x| j| D ]}|  |¡ qBW || _| j| sv|  | j| j	 ¡ | j
| rˆ|  ¡  |  ¡  d S dS )NÚ	currentbpFr   r   )Úgetattrrp   rH   Úlastcmdrc   rg   rJ   Úprint_stack_entryrW   rX   rI   Ú_cmdlooprV   )r-   rS   rp   Zlastcmd_backr   r   r   r   rn     s     

zPdb.bp_commandsc             C   s.   | j r
d S ||jd< |  d¡ |  |d ¡ d S )NÚ
__return__z
--Return--)r<   r"   rQ   ri   )r-   rS   Zreturn_valuer   r   r   Úuser_return  s
    

zPdb.user_returnc             C   sh   | j r
d S |\}}}||f|jd< |s2|tkr2dnd}|  d|t ||¡d  ¡ f ¡ |  ||¡ d S )NZ__exception__z	Internal r1   z%s%séÿÿÿÿ)r<   r"   ÚStopIterationrQ   Ú	tracebackÚformat_exception_onlyrf   ri   )r-   rS   Úexc_infoÚexc_typeÚ	exc_valueÚexc_tracebackÚprefixr   r   r   Úuser_exception'  s    
zPdb.user_exceptionc             C   sD   x>yd| _ |  ¡  d| _ P W q tk
r:   |  d¡ Y qX qW d S )NTFz--KeyboardInterrupt--)r@   ÚcmdlooprP   rQ   )r-   r   r   r   rt   ;  s    zPdb._cmdloopc             C   sb   | j  | j¡}|r^xJ| ¡ D ]>\}}|  |¡}||k	r||kr|||< |  d|||f ¡ qW d S )Nzdisplay %s: %r  [old: %r])r:   ÚgetrY   ÚitemsÚ_getval_exceptrQ   )r-   r:   ÚexprZoldvalueZnewvaluer   r   r   ÚpreloopH  s    
zPdb.preloopc             C   sZ   t jrt tjt j¡ d t _|  ||¡r4|  ¡  d S |  | j| j ¡ |  	¡  |  ¡  d S )N)
r
   Ú_previous_sigint_handlerÚsignalÚSIGINTrc   rV   rs   rW   rX   rt   )r-   rS   ry   r   r   r   ri   U  s    zPdb.interactionc             C   s   |d k	r|   t|ƒ¡ d S )N)rQ   Úrepr)r-   r#   r   r   r   Údisplayhookc  s    zPdb.displayhookc       	      C   sÈ   |d d… dkr|dd … }| j }| jj}ydt|d ddƒ}tj}tj}tj}z(| jt_| jt_| jt_t|||ƒ W d |t_|t_|t_X W n4   t 	¡ d d… }|  
tj|Ž d  ¡ ¡ Y nX d S )Nr   ú!Ú
z<stdin>Zsingleé   rw   )r_   rY   r!   r   ÚsysrO   rN   r‹   Úexecr{   Úerrorry   rz   rf   )	r-   r   ÚlocalsÚglobalsr)   Zsave_stdoutZ
save_stdinZsave_displayhookr{   r   r   r   Údefaultk  s(     zPdb.defaultc             C   sà   |  ¡ s|S | ¡ }xx|d | jkrŒ| j|d  }d}x0|dd … D ] }| dt|ƒ |¡}|d7 }qDW | dd |dd … ¡¡}| ¡ }qW |d dkrÜ| d¡}|dkrÜ||d d …  ¡ }| j 	|¡ |d |…  
¡ }|S )	Nr   r   ú%z%*ú Úaliasz;;rŽ   )rf   Úsplitr9   ÚreplaceÚstrrF   ÚfindÚlstripÚcmdqueueÚappendÚrstrip)r-   r   ÚargsÚiiZtmpArgZmarkerÚnextr   r   r   Úprecmd  s&    
z
Pdb.precmdc             C   s"   | j stj | |¡S |  |¡S d S )N)rK   r6   r7   rg   Úhandle_command_def)r-   r   r   r   r   rg   š  s    z
Pdb.onecmdc             C   sÄ   |   |¡\}}}|sd S |dkr0d| j| j< d S |dkrBg | _dS | j| j }|rf| |d | ¡ n
| |¡ yt| d| ƒ}W n tk
rœ   | j}Y nX |j	| j
krÀd| j| j< g | _dS d S )NZsilentTÚendr   r–   Údo_F)Z	parselinerJ   rL   r   rH   rž   rq   ÚAttributeErrorr”   r   Úcommands_resumingrI   )r-   r   r6   ÚargZcmdlistÚfuncr   r   r   r¤   ¦  s,    
zPdb.handle_command_defc             C   s   t || jd d S )N)Úfile)ÚprintrO   )r-   Úmsgr   r   r   rQ   Ä  s    zPdb.messagec             C   s   t d|| jd d S )Nz***)r«   )r¬   rO   )r-   r­   r   r   r   r‘   Ç  s    z	Pdb.errorc             C   s¤   |  ¡  d¡rg S y|  ||||¡}W n tk
r>   g }Y nX t |d ¡}xP|D ]H}tj |¡rt| |d ¡ qTtj 	|¡rT| 
¡  d¡rT| |d ¡ qTW |S )N)ú:ú,Ú*ú/)z.pyz.pywr®   )rf   ÚendswithÚ_complete_expressionÚ	ExceptionÚglobrC   rE   Úisdirrž   ÚisfileÚlower)r-   Útextr   ÚbegidxÚendidxÚretÚglobsÚfnr   r   r   Ú_complete_locationÍ  s    

zPdb._complete_locationc                s   ‡ fdd„t tjjƒD ƒS )Nc                s.   g | ]&\}}|d k	rt |ƒ ˆ ¡rt |ƒ‘qS )N)rš   Ú
startswith)Ú.0r*   Úbp)r¹   r   r   ú
<listcomp>ä  s    z*Pdb._complete_bpnumber.<locals>.<listcomp>)r   r3   Ú
BreakpointÚ
bpbynumber)r-   r¹   r   rº   r»   r   )r¹   r   Ú_complete_bpnumberà  s    zPdb._complete_bpnumberc          	      sÆ   | j s
g S | j j ¡ }| | j¡ dˆkr¬ˆ d¡‰ y0|ˆ d  }xˆ dd… D ]}t||ƒ}qPW W n ttfk
r|   g S X d 	ˆ d d… ¡d ‰‡ ‡fdd„t
|ƒD ƒS ‡fdd„| ¡ D ƒS d S )NÚ.r   r   rw   c                s"   g | ]}|  ˆ d  ¡rˆ| ‘qS )rw   )rÀ   )rÁ   Ún)Údottedr   r   r   rÃ   ü  s    z,Pdb._complete_expression.<locals>.<listcomp>c                s   g | ]}|  ˆ ¡r|‘qS r   )rÀ   )rÁ   rÈ   )r¹   r   r   rÃ   ÿ  s    )rY   r!   ÚcopyÚupdater_   r˜   rq   ÚKeyErrorr§   rF   ÚdirÚkeys)r-   r¹   r   rº   r»   Únsr#   Úpartr   )rÉ   r   r¹   r   r³   ç  s    
zPdb._complete_expressionc             C   s(  |st tjjƒd }n"yt|ƒ}W n   |  d¡ d S || _|| jkrf| j| | j| | j	| f}nd }g | j|< d| j|< d| j	|< | j
}d| _
d| _zzy|  ¡  W nh tk
r   |rê|d | j|< |d | j|< |d | j	|< n| j|= | j|= | j	|= |  d¡ Y nX W d d| _|| _
X d S )	Nr   z.Usage: commands [bnum]
        ...
        endTFz(com) r   rŽ   z1command definition aborted, old commands restored)Úlenr3   rÄ   rÅ   Úintr‘   rL   rH   rI   rJ   r8   rK   r   rP   )r-   r©   ZbnumZold_command_defsZprompt_backr   r   r   Údo_commands  s@    %




zPdb.do_commandsr   c          
   C   s@  |s<| j r8|  d¡ x"tjjD ]}|r|  | ¡ ¡ qW d S d }d }d }| d¡}|dkr~||d d …  ¡ }|d |…  ¡ }| 	d¡}d }	|dkr|d |…  ¡ }|  
|¡}
|
sÆ|  d| ¡ d S |
}||d d …  ¡ }yt|ƒ}W n$ tk
r   |  d| ¡ d S X n¼yt|ƒ}W n® tk
rÌ   yt|| jj| jƒ}W n   |}Y nX y.t|dƒrl|j}|j}|j}	|j}|j}W n@   |  |¡\}}}|s¶|  d	| ¡ d S |}	t|ƒ}Y nX Y nX |sÜ|  ¡ }|  ||¡}|r<|  |||||	¡}|r|  |¡ n*|  ||¡d
 }|  d|j|j|jf ¡ d S )Nz!Num Type         Disp Enb   Wherer¯   r   r   r®   z%r not found from sys.pathzBad lineno: %sÚ__func__zJThe specified object %r is not a function or was not found along sys.path.rw   zBreakpoint %d at %s:%d) ÚbreaksrQ   r3   rÄ   rÅ   Zbpformatr›   rœ   rŸ   ÚrfindÚlookupmoduler‘   rÒ   Ú
ValueErrorÚevalrY   r!   r_   ÚhasattrrÔ   Ú__code__Úco_nameÚco_firstlinenorl   ÚlineinfoÚdefaultFileÚ	checklineZ	set_breakÚ
get_breaksÚnumberr«   r   )r-   r©   Z	temporaryrÂ   r   r   ÚcondZcommaZcolonr   ra   rª   r)   ÚokZlnr   Úerrr   r   r   Údo_breakT  s~    






zPdb.do_breakc             C   s"   | j jj}|dkr| jr| j}|S )Nz<string>)rY   r\   rl   r;   )r-   r   r   r   r   rß   ±  s    
zPdb.defaultFilec             C   s   |   |d¡ d S )Nr   )ræ   )r-   r©   r   r   r   Ú	do_tbreak½  s    zPdb.do_tbreakc       
      C   sÌ   d}|  d¡}t|ƒdkr(|d  ¡ }nt|ƒdkrB|d  ¡ }n|S |dkrR|S |  d¡}|d dkr~|d= t|ƒdkr~|S |  ¡ }t|ƒdkrœ|d }n|  |d ¡}|r²|}|d }t||ƒ}	|	pÊ|S )	N)NNNú'r   r   é   r1   rÇ   r-   )r˜   rÑ   rf   rß   r×   r   )
r-   Z
identifierZfailedZidstringÚidÚpartsZfnameÚitemra   Zanswerr   r   r   rÞ   Æ  s.    
 


zPdb.lineinfoc             C   s€   t | dƒr| jjnd }t |||¡}|s6|  d¡ dS | ¡ }|rn|d dksn|d d… dksn|d d… dkr||  d¡ dS |S )	NrY   zEnd of filer   rd   ré   z"""z'''zBlank or comment)rÚ   rY   r!   Ú	linecacheÚgetlinerQ   rf   r‘   )r-   r   r   r½   r   r   r   r   rà   ç  s    
 
zPdb.checklinec             C   sl   |  ¡ }x^|D ]V}y|  |¡}W n, tk
rL } z|  |¡ W d d }~X Y qX | ¡  |  d| ¡ qW d S )Nz
Enabled %s)r˜   Úget_bpbynumberrØ   r‘   ÚenablerQ   )r-   r©   r    r*   rÂ   rå   r   r   r   Ú	do_enableü  s    
zPdb.do_enablec             C   sl   |  ¡ }x^|D ]V}y|  |¡}W n, tk
rL } z|  |¡ W d d }~X Y qX | ¡  |  d| ¡ qW d S )NzDisabled %s)r˜   rï   rØ   r‘   ÚdisablerQ   )r-   r©   r    r*   rÂ   rå   r   r   r   Ú
do_disable  s    
zPdb.do_disablec          
   C   sÂ   |  dd¡}y|d }W n tk
r0   d }Y nX y|  |d  ¡ ¡}W nH tk
rf   |  d¡ Y nX tk
r } z|  |¡ W d d }~X Y n.X ||_|s®|  d|j ¡ n|  d|j ¡ d S )Nr–   r   r   zBreakpoint number expectedz#Breakpoint %d is now unconditional.z$New condition set for breakpoint %d.)	r˜   Ú
IndexErrorrï   rf   r‘   rØ   rã   rQ   râ   )r-   r©   r    rã   rÂ   rå   r   r   r   Údo_condition!  s    
zPdb.do_conditionc          
   C   sÜ   |  ¡ }yt|d  ¡ ƒ}W n   d}Y nX y|  |d  ¡ ¡}W nH tk
rb   |  d¡ Y nv tk
rŒ } z|  |¡ W d d }~X Y nLX ||_|dkrÈ|dkr®d| }nd}|  d||j	f ¡ n|  d|j	 ¡ d S )Nr   r   zBreakpoint number expectedz%d crossingsz
1 crossingz%Will ignore next %s of breakpoint %d.z-Will stop next time breakpoint %d is reached.)
r˜   rÒ   rf   rï   rô   r‘   rØ   ÚignorerQ   râ   )r-   r©   r    ÚcountrÂ   rå   Zcountstrr   r   r   Ú	do_ignore<  s(    	

zPdb.do_ignorec       
      C   sŽ  |sxyt dƒ}W n tk
r(   d}Y nX | ¡  ¡ }|dkrtdd„ tjjD ƒ}|  ¡  x|D ]}|  d| ¡ q^W d S d|kr| 	d¡}|d |… }||d d … }yt
|ƒ}W n tk
rÐ   d	| }Y nX |  ||¡}|  ||¡}|rú|  |¡ nx|D ]}|  d| ¡ q W d S | ¡ }	xd|	D ]\}y|  |¡}W n. tk
rj } z|  |¡ W d d }~X Y nX |  |¡ |  d| ¡ q*W d S )
NzClear all breaks? Úno)ÚyZyesc             S   s   g | ]}|r|‘qS r   r   )rÁ   rÂ   r   r   r   rÃ   m  s    z Pdb.do_clear.<locals>.<listcomp>z
Deleted %sr®   r   zInvalid line number (%s))ÚinputÚEOFErrorrf   r¸   r3   rÄ   rÅ   Zclear_all_breaksrQ   rÖ   rÒ   rØ   rá   Zclear_breakr‘   r˜   rï   Zclear_bpbynumber)
r-   r©   ZreplyZbplistrÂ   r*   r   r   rå   Z
numberlistr   r   r   Údo_clear_  sF    






zPdb.do_clearc             C   s   |   ¡  d S )N)Úprint_stack_trace)r-   r©   r   r   r   Údo_where’  s    zPdb.do_wherec             C   s>   || _ | j| j  d | _| jj| _|  | j| j  ¡ d | _d S )Nr   )rX   rW   rY   r"   r_   rs   r   )r-   râ   r   r   r   Ú_select_frameœ  s
    
zPdb._select_framec             C   sx   | j dkr|  d¡ d S yt|p"dƒ}W n" tk
rJ   |  d| ¡ d S X |dk rZd}ntd| j | ƒ}|  |¡ d S )Nr   zOldest framer   zInvalid frame count (%s))rX   r‘   rÒ   rØ   Úmaxr   )r-   r©   r÷   Únewframer   r   r   Údo_up¤  s    

z	Pdb.do_upc             C   s–   | j d t| jƒkr"|  d¡ d S yt|p,dƒ}W n" tk
rT   |  d| ¡ d S X |dk rnt| jƒd }ntt| jƒd | j | ƒ}|  |¡ d S )Nr   zNewest framezInvalid frame count (%s)r   )rX   rÑ   rW   r‘   rÒ   rØ   Úminr   )r-   r©   r÷   r  r   r   r   Údo_down¸  s    
zPdb.do_downc             C   sf   |rPyt |ƒ}W n" tk
r2   |  d| ¡ d S X || jjkrT|  d¡ d S nd }|  | j|¡ dS )NzError in argument: %rz7"until" line number is smaller than current line numberr   )rÒ   rØ   r‘   rY   rm   Z	set_until)r-   r©   r   r   r   r   Údo_untilÌ  s    
zPdb.do_untilc             C   s   |   ¡  dS )Nr   )rR   )r-   r©   r   r   r   Údo_stepä  s    zPdb.do_stepc             C   s   |   | j¡ dS )Nr   )Zset_nextrY   )r-   r©   r   r   r   Údo_nextî  s    zPdb.do_nextc             C   s<   |r4dd l }tjdd… }| |¡t_|tjd d…< t‚d S )Nr   r   )Úshlexr   Úargvr˜   r   )r-   r©   r	  Zargv0r   r   r   Údo_run÷  s    z
Pdb.do_runc             C   s   |   | j¡ dS )Nr   )Z
set_returnrY   )r-   r©   r   r   r   Ú	do_return  s    zPdb.do_returnc             C   s>   | j s2yt tj| j¡t_W n tk
r0   Y nX |  ¡  dS )Nr   )rA   rˆ   r‰   rT   r
   r‡   rØ   Zset_continue)r-   r©   r   r   r   Údo_continue  s    zPdb.do_continuec          
   C   s¾   | j d t| jƒkr"|  d¡ d S yt|ƒ}W n tk
rL   |  d¡ Y nnX y:|| j_| j| j  d |f| j| j < |  | j| j  ¡ W n0 tk
r¸ } z|  d| ¡ W d d }~X Y nX d S )Nr   z)You can only jump within the bottom framez)The 'jump' command requires a line numberr   zJump failed: %s)	rX   rÑ   rW   r‘   rÒ   rØ   rY   rm   rs   )r-   r©   Úer   r   r   Údo_jump"  s    
zPdb.do_jumpc             C   s¼   t  d ¡ | jj}| j}t| j| j| jƒ}d| j	 
¡  |_	|  d¡ yt  |j|||f¡ W n< tk
r˜   t  ¡ d d… }|  tj|Ž d  
¡ ¡ Y nX |  d¡ t  | j¡ |j| _d S )Nz(%s) zENTERING RECURSIVE DEBUGGERrŽ   rw   zLEAVING RECURSIVE DEBUGGER)r   ÚsettracerY   r!   r_   r
   rM   rN   rO   r8   rf   rQ   Úcall_tracingr   r´   r{   r‘   ry   rz   Ztrace_dispatchrr   )r-   r©   r“   r’   Úpr{   r   r   r   Údo_debug?  s    


zPdb.do_debugc             C   s   d| _ |  ¡  dS )NTr   )Ú_user_requested_quitÚset_quit)r-   r©   r   r   r   Údo_quitV  s    zPdb.do_quitc             C   s   |   d¡ d| _|  ¡  dS )Nr1   Tr   )rQ   r  r  )r-   r©   r   r   r   Údo_EOFa  s    
z
Pdb.do_EOFc             C   s’   | j j}| j}|j|j }|jtj@ r.|d }|jtj@ rB|d }xJt	|ƒD ]>}|j
| }||krz|  d||| f ¡ qL|  d|f ¡ qLW d S )Nr   z%s = %rz%s = *** undefined ***)rY   r\   r_   Úco_argcountÚco_kwonlyargcountÚco_flagsr    Z
CO_VARARGSZCO_VARKEYWORDSÚrangeÚco_varnamesrQ   )r-   r©   ÚcoÚdictrÈ   r*   Únamer   r   r   Údo_argsj  s      
zPdb.do_argsc             C   s.   d| j kr |  t| j d ƒ¡ n
|  d¡ d S )Nru   zNot yet returned!)r_   rQ   rŠ   r‘   )r-   r©   r   r   r   Ú	do_retval{  s    
zPdb.do_retvalc             C   sN   yt || jj| jƒS    t ¡ d d… }|  tj|Ž d  	¡ ¡ ‚ Y nX d S )NrŽ   rw   )
rÙ   rY   r!   r_   r   r{   r‘   ry   rz   rf   )r-   r©   r{   r   r   r   Ú_getval…  s    zPdb._getvalc             C   sh   y.|d krt || jj| jƒS t ||j|jƒS W n4   t ¡ d d… }tj|Ž d  	¡ }t
d| ƒS d S )NrŽ   rw   z** raised %s **)rÙ   rY   r!   r_   r"   r   r{   ry   rz   rf   r,   )r-   r©   rS   r{   rå   r   r   r   r„     s    zPdb._getval_exceptc             C   s*   y|   t|  |¡ƒ¡ W n   Y nX d S )N)rQ   rŠ   r"  )r-   r©   r   r   r   Údo_p˜  s    zPdb.do_pc             C   s,   y|   t |  |¡¡¡ W n   Y nX d S )N)rQ   ÚpprintZpformatr"  )r-   r©   r   r   r   Údo_pp¡  s    z	Pdb.do_ppc             C   sd  d| _ d }|rš|dkršy^d|krX| d¡\}}t| ¡ ƒ}t| ¡ ƒ}||k rr|| }nt| ¡ ƒ}td|d ƒ}W qÊ tk
r–   |  d| ¡ d S X n0| jd ks¬|dkrÀtd| jj	d ƒ}n
| jd }|d krÚ|d }| jj
j}|  |¡}yZt || jj¡}|  ||d |… ||| j¡ t|t|ƒƒ| _t|ƒ|k rF|  d¡ W n tk
r^   Y nX d S )	Nr&   rÇ   r¯   r   é   zError in argument: %ré
   z[EOF])rr   r˜   rÒ   rf   r  rØ   r‘   r   rY   rm   r\   rl   Úget_file_breaksrí   Úgetlinesr!   Ú_print_linesr  rÑ   rQ   rP   )r-   r©   ZlastÚfirstr   Ú	breaklistr$   r   r   r   Údo_list®  s>    



zPdb.do_listc          
   C   sj   | j jj}|  |¡}yt| j ƒ\}}W n, tk
rR } z|  |¡ d S d }~X Y nX |  |||| j ¡ d S )N)rY   r\   rl   r(  r%   r   r‘   r*  )r-   r©   r   r,  r$   r   rå   r   r   r   Údo_longlistá  s    


zPdb.do_longlistc          
   C   sl   y|   |¡}W n
   d S yt|ƒ\}}W n0 ttfk
rZ } z|  |¡ d S d }~X Y nX |  ||¡ d S )N)r"  r%   r   Ú	TypeErrorr‘   r*  )r-   r©   r#   r$   r   rå   r   r   r   Ú	do_sourceï  s    
zPdb.do_sourcer   c       
      C   s²   |r|j }| j |d¡}nd }}xŠt||ƒD ]|\}}t|ƒ d¡}	t|	ƒdk rX|	d7 }	||krj|	d7 }	n|	d7 }	||kr„|	d7 }	n||kr”|	d7 }	|  |	d | ¡  ¡ q.W d S )	Nrw   ré   é   r–   ÚBz->z>>ú	)	rm   r=   r‚   r   rš   ÚrjustrÑ   rQ   rŸ   )
r-   r$   r   rÕ   rS   Zcurrent_linenoZ
exc_linenor   r   Úsr   r   r   r*     s     

zPdb._print_linesc             C   sÆ   y|   |¡}W n
   d S d }y
|j}W n tk
r<   Y nX |rV|  d|j ¡ d S y|jj}W n tk
rv   Y nX |r|  d|j ¡ d S |jtkr´|  d|j|j	f ¡ d S |  t|ƒ¡ d S )NzFunction %sz	Method %szClass %s.%s)
r"  rÛ   r´   rQ   rÜ   rÔ   Ú	__class__Útyper   r   )r-   r©   Úvaluer)   r   r   r   Ú	do_whatis  s.    

zPdb.do_whatisc             C   sp   |s<|   d¡ x\| j | ji ¡ ¡ D ]}|   d| ¡ q$W n0|  |¡}|| j | ji ¡|< |   d||f ¡ d S )NzCurrently displaying:z%s: %rzdisplay %s: %r)rQ   r:   r‚   rY   rƒ   r„   Ú
setdefault)r-   r©   rì   Úvalr   r   r   Ú
do_display8  s    

zPdb.do_displayc             C   sT   |r@y| j  | ji ¡|= W qP tk
r<   |  d| ¡ Y qPX n| j  | jd ¡ d S )Nznot displaying %s)r:   r‚   rY   rÌ   r‘   re   )r-   r©   r   r   r   Údo_undisplayK  s    zPdb.do_undisplayc                s   ‡ fdd„| j  | ji ¡D ƒS )Nc                s   g | ]}|  ˆ ¡r|‘qS r   )rÀ   )rÁ   r  )r¹   r   r   rÃ   [  s    z*Pdb.complete_undisplay.<locals>.<listcomp>)r:   r‚   rY   )r-   r¹   r   rº   r»   r   )r¹   r   Úcomplete_undisplayZ  s    zPdb.complete_undisplayc             C   s*   | j j ¡ }| | j¡ tjd|d d S )Nz*interactive*)Zlocal)rY   r!   rÊ   rË   r_   r)   Úinteract)r-   r©   rÏ   r   r   r   Údo_interact^  s    zPdb.do_interactc             C   s¨   |  ¡ }t|ƒdkrLt| j ¡ ƒ}x$|D ]}|  d|| j| f ¡ q(W d S |d | jkrˆt|ƒdkrˆ|  d|d | j|d  f ¡ nd |dd … ¡| j|d < d S )Nr   z%s = %sr   r–   )r˜   rÑ   Úsortedr9   rÎ   rQ   rF   )r-   r©   r    rÎ   r—   r   r   r   Údo_aliash  s    
"zPdb.do_aliasc             C   s6   |  ¡ }t|ƒdkrd S |d | jkr2| j|d = d S )Nr   )r˜   rÑ   r9   )r-   r©   r    r   r   r   Ú
do_unalias‹  s
     zPdb.do_unaliasc                s   ‡ fdd„| j D ƒS )Nc                s   g | ]}|  ˆ ¡r|‘qS r   )rÀ   )rÁ   Úa)r¹   r   r   rÃ   •  s    z(Pdb.complete_unalias.<locals>.<listcomp>)r9   )r-   r¹   r   rº   r»   r   )r¹   r   Úcomplete_unalias”  s    zPdb.complete_unaliasr  r  r  r  r  r  c             C   s8   yx| j D ]}|  |¡ q
W W n tk
r2   Y nX d S )N)rW   rs   rP   )r-   Úframe_linenor   r   r   rþ   £  s
    zPdb.print_stack_tracec             C   s6   |\}}|| j krd}nd}|  ||  ||¡ ¡ d S )Nz> z  )rY   rQ   Zformat_stack_entry)r-   rF  Zprompt_prefixrS   r   r   r   r   r   rs   ª  s    
zPdb.print_stack_entryc             C   s¤   |st j | |¡S y<yt| d| ƒ}|ƒ S  tk
rJ   t| d| ƒ}Y nX W n" tk
rp   |  d| ¡ Y n0X tjjdkr|  d| ¡ d S |  	|j
 ¡ ¡ d S )NZhelp_r¦   zNo help for %rrŽ   zJNo help for %r; please do not run Python with -OO if you need command help)r6   r7   Údo_helprq   r§   r‘   r   ÚflagsÚoptimizerQ   Ú__doc__rŸ   )r-   r©   ZtopicZcommandr   r   r   rG  µ  s    zPdb.do_helpc             C   s   |   | jjpd ¡ ¡ d S )Nr1   )rQ   Ú	help_execrJ  rf   )r-   r   r   r   rK  Ï  s    
zPdb.help_execc             C   s
   t ƒ  d S )N)r   )r-   r   r   r   Úhelp_pdbÛ  s    zPdb.help_pdbc             C   sÎ   t j |¡rt j |¡r|S t j tjd |¡}t j |¡rP|  |¡| jkrP|S t j |¡\}}|dkrp|d }t j |¡r€|S xHtjD ]>}xt j 	|¡r¦t  
|¡}qŽW t j ||¡}t j |¡rˆ|S qˆW d S )Nr   r1   z.py)rC   rE   ÚisabsÚexistsrF   r   rk   r;   ÚsplitextÚislinkÚreadlink)r-   r   ra   ÚrootZextÚdirnameÚfullnamer   r   r   r×   à  s"    zPdb.lookupmodulec          	   C   sr   d| _ d| _dd l}| |¡\}}}|  |j¡| _dd l}|j 	¡  |j 
d| j|j|j|tdœ¡ |  |¡ d S )NTFr   Ú__main__)r   Ú__file__Ú__package__Ú
__loader__Ú__spec__Ú__builtins__)r<   r  ÚrunpyZ_get_module_detailsrk   rl   r;   rU  Ú__dict__rZ   rË   ÚparentÚloaderrZ  r   )r-   Zmodule_namer[  Zmod_nameZmod_specr)   rU  r   r   r   Ú
_runmoduleø  s    

zPdb._runmodulec          	   C   st   dd l }|j ¡  |j d|tdœ¡ d| _|  |¡| _d| _t	|dƒ}d| 
¡ | jf }W d Q R X |  |¡ d S )Nr   rU  )r   rV  rZ  TFÚrbzexec(compile(%r, %r, 'exec')))rU  r\  rZ   rË   rZ  r<   rk   r;   r  r   Úreadr   )r-   r   rU  r   Ú	statementr   r   r   Ú
_runscript
  s    

zPdb._runscript)r/   NNNFT)r   )N)r   N)wr   r   r   r‡   r5   rT   rU   rV   rc   r`   rj   ro   rn   rv   r€   rt   r†   ri   r‹   r”   r£   rg   r¤   rQ   r‘   r¿   rÆ   r³   rÓ   Zcomplete_commandsræ   rß   Zdo_bZcomplete_breakZ
complete_brç   Zcomplete_tbreakrÞ   rà   rñ   Zcomplete_enableró   Zcomplete_disablerõ   Zcomplete_conditionrø   Zcomplete_ignorerý   Zdo_clZcomplete_clearZcomplete_clrÿ   Zdo_wZdo_btr   r  Zdo_ur  Zdo_dr  Zdo_untr  Zdo_sr  Zdo_nr  Z
do_restartr  Zdo_rr  Zdo_cZdo_contr  Zdo_jr  Zcomplete_debugr  Zdo_qZdo_exitr  r   Zdo_ar!  Zdo_rvr"  r„   r#  r%  Zcomplete_printZ
complete_pZcomplete_ppr-  Zdo_lr.  Zdo_llr0  Zcomplete_sourcer*  r9  Zcomplete_whatisr<  Zcomplete_displayr=  r>  r@  rB  rC  rE  r¨   rþ   Úline_prefixrs   rG  Zdo_hrK  rL  r×   r_  rc  r   r   r   r   r
   ˆ   sè    
/	
M
]!!.	
		1
!
#	
ÚwhereZdownZupÚbreakZtbreakrZ   rò   rð   rö   Z	conditionrH   Ústepr¢   ZuntilZjumpÚreturnZretvalÚcontinuer&   Zlonglistr    r  ÚppZwhatisÚsourceZdisplayZ	undisplayr?  r—   ZunaliasÚdebugÚquitr¦   z

c             C   s   t ƒ  | ||¡ d S )N)r
   r   )rb  r“   r’   r   r   r   r   9  s    c             C   s   t ƒ  | ||¡S )N)r
   r   )Z
expressionr“   r’   r   r   r   r   <  s    c             C   s   t | ||ƒ d S )N)r   )rb  r“   r’   r   r   r   r   ?  s    c              O   s   t ƒ j| |ŽS )N)r
   r   )r    Úkwdsr   r   r   r   C  s    )Úheaderc             C   s,   t ƒ }| d k	r| | ¡ | t ¡ j¡ d S )N)r
   rQ   r   r   Ú	_getframeÚf_back)ro  Úpdbr   r   r   r   F  s    
c             C   sB   | d krt  ¡ d } | d kr$tdƒ‚tƒ }| ¡  | d | ¡ d S )NrŽ   zAA valid traceback must be passed if no exception is being handled)r   r{   rØ   r
   rU   ri   )Útr  r   r   r   r   N  s    c               C   s   t tjƒ d S )N)r   r   Úlast_tracebackr   r   r   r   r	   \  s    zimport x; x.main()c               C   s   t tƒ d S )N)r   ÚTESTCMDr   r   r   r   Útestd  s    rv  c              C   s   dd l } |  t¡ d S )Nr   )ÚpydocZpagerrJ  )rw  r   r   r   r   h  s    a  usage: pdb.py [-c command] ... [-m module | pyfile] [arg] ...

Debug the Python program given by pyfile. Alternatively,
an executable module or package to debug can be specified using
the -m switch.

Initial commands are read from .pdbrc files in your home directory
and in the current directory, if they exist.  Commands supplied with
-c are executed after commands from .pdbrc files.

To let the script run until an exception occurs, use "-c continue".
To let the script run up to a given line X in the debugged file, use
"-c 'until X'".c        
      C   s
  dd l } |   tjdd … dddg¡\}}|s>ttƒ t d¡ g }d}xJ|D ]B\}}|dkrnttƒ t ¡  qL|d	kr‚| |¡ qL|d
krLd}qLW |d }|sÀtj 	|¡sÀtd|dƒ t d¡ |tjd d …< |sätj 
|¡tjd< tƒ }|j |¡ xy2|r| |¡ n
| |¡ |jr"P tdƒ W qú tk
r`   td|dƒ tdd |¡ ƒ Y qú tk
r   tddd tt ¡ d ƒ Y qú tk
r¶   t ¡  t d¡ Y qú   t ¡  tdƒ tdƒ t ¡ d }	| d |	¡ td| d ƒ Y qúX qúW d S )Nr   r   zmhc:z--helpz
--command=rŽ   F)z-hz--help)z-cz	--command)z-mTzError:zdoes not existz*The program finished and will be restartedZ
Restartingzwith arguments:r3  r–   z/The program exited via sys.exit(). Exit status:)r¥   z2Uncaught exception. Entering post mortem debuggingz1Running 'cont' or 'step' will restart the programz#Post mortem debugger finished. The z will be restarted)Úgetoptr   r
  r¬   Ú_usageÚexitrž   rC   rE   rN  rS  r
   rB   rG   r_  rc  r  r   rF   Ú
SystemExitr{   ÚSyntaxErrorry   Ú	print_excri   )
rx  Zoptsr    rH   Zrun_as_moduleÚoptZoptargr;   rr  rs  r   r   r   Úmain{  sb     



r  rU  )NN)NN)N)-rC   r   r   r6   r3   r'   r)   rµ   r$  rˆ   r    ry   rí   r´   r   Ú__all__r   r%   r+   rš   r,   rd  r4   r7   r
   rJ  Z_help_orderZ_commandrq   rf   rK  r   r   r   r   r   r   r	   ru  rv  r   ry  r  r   rr  r   r   r   r   Ú<module>F   sr   		           )

"


C
