a
    ãze÷  ã                   @   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d dlZd dlZG dd„ deƒZg d¢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urg d¢ZeD ] Zeeede ƒj ¡ d 7 Zqèeej j7 Z[[d+dd„Z!d,dd„Z"dd„ Z#dd„ Z$ddœdd„Z%d-dd„Z&d d!„ Z'd"Z(d#d$„ Z)d%d&„ Z*d'Z+d(d)„ Z,e-d*kr˜d dl.Z.e. ,¡  dS ).é    Nc                   @   s   e Zd ZdS )ÚRestartN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú/usr/lib/python3.9/pdb.pyr   W   s   r   )	ÚrunÚpmÚPdbÚrunevalÚrunctxÚruncallÚ	set_traceÚpost_mortemÚhelpc                 C   sœ   t  dt  | ¡ ¡}zt |¡}W n ty6   Y d S 0 |L t|ddD ].\}}| |¡rJ| ||f  W  d   ƒ S qJW d   ƒ n1 sŽ0    Y  d S )Nzdef\s+%s\s*[(]é   )Ústart)ÚreÚcompileÚescapeÚtokenizeÚopenÚOSErrorÚ	enumerateÚmatch)ÚfuncnameÚfilenameZcreÚfpÚlinenoÚliner   r   r   Úfind_function^   s    
<r    c                 C   sX   t  | ¡\}}t  | ¡r,| j| ju 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   Úgetsourcelinesk   s    
r'   c                 C   s8   t t | ¡ƒ}| ¡  |D ]\}}||kr|  S qdS ©Nr   )ÚlistÚdisZfindlinestartsÚreverse)ÚcodeZlastiZ
linestartsÚir   r   r   r   Úlasti2linenot   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   r3   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„ ZWdtdu„ ZXdvdw„ ZYeZZeZ[eZ\dxdy„ Z]e]Z^dzd{„ Z_e_Z`d|d}„ ZaeZbd¥dd€„Zcdd‚„ ZdeZedƒd„„ ZfeZgd…d†„ Zhd‡dˆ„ Zid‰dŠ„ Zjd‹dŒ„ ZkddŽ„ Zldd„ Zmg d‘¢Znd’d“„ Zoepfd”d•„Zqd–d—„ ZrerZsd˜d™„ Ztdšd›„ Zudœd„ ZvdždŸ„ Zwd d¡„ ZxdS )¦r
   NÚtabFTc           	      C   sb  t jj| |d tj | |||¡ t d¡ |r6d| _d| _i | _	i | _
d| _d| _i | _zdd l}| d¡ W n ty‚   Y n0 d| _|| _g | _|r@z@ttj d¡ƒ}| j |¡ W d   ƒ n1 sÐ0    Y  W n tyî   Y n0 z:td	ƒ}| j |¡ W d   ƒ n1 s0    Y  W n ty>   Y n0 i | _i | _i | _d| _d | _d S )
N)Úskipzpdb.Pdbr   z(Pdb) Ú Fz 	
`@#$%^&*()=+[{]}\|;:'",<>?z~/.pdbrcz.pdbrc)ÚbdbÚBdbÚ__init__ÚcmdÚCmdÚsysÚauditZuse_rawinputÚpromptÚaliasesÚ
displayingÚ
mainpyfileÚ_wait_for_mainpyfileÚ	tb_linenoÚreadlineZset_completer_delimsÚImportErrorÚallow_kbdintÚnosigintÚrcLinesr   ÚosÚpathÚ
expanduserÚextendr   ÚcommandsÚcommands_dopromptÚcommands_silentÚcommands_definingÚcommands_bnum)	r2   ÚcompletekeyÚstdinÚstdoutr5   rG   ZreadrcrD   ZrcFiler   r   r   r9   Ž   sF    
.
0zPdb.__init__c                 C   s*   | j r
t‚|  d¡ |  ¡  |  |¡ d S )Nz-
Program interrupted. (Use 'cont' to resume).)rF   ÚKeyboardInterruptÚmessageÚset_stepr   )r2   ÚsignumÚframer   r   r   Úsigint_handler½   s
    
zPdb.sigint_handlerc                 C   s   t j | ¡ |  ¡  d S r0   )r7   r8   ÚresetÚforgetr1   r   r   r   r[   Ä   s    z	Pdb.resetc                 C   s&   d | _ g | _d| _d | _| j ¡  d S r(   )r   ÚstackÚcurindexÚcurframerC   Úclearr1   r   r   r   r\   È   s
    z
Pdb.forgetc                 C   sh   |   ¡  |  ||¡\| _| _|rDt|jj|jƒ}|| j|j< |j	}q| j| j d | _
| j
j| _|  ¡ S r(   )r\   Z	get_stackr]   r^   r.   Útb_frameÚf_codeÚtb_lastirC   Útb_nextr_   r$   Úcurframe_localsÚexecRcLines)r2   ÚfÚtbr   r   r   r   ÚsetupÏ   s    
z	Pdb.setupc                 C   sd   | j s
d S | j }| ¡  g | _ |r`| ¡  ¡ }|r|d dkr|  |¡r|  j t|ƒ7  _ dS qd S )Nr   ú#T)rH   r+   ÚpopÚstripÚonecmdÚreversed)r2   rH   r   r   r   r   rf   á   s    
zPdb.execRcLinesc                 C   s.   | j r
d S |  |¡r*|  d¡ |  |d ¡ d S )Nz--Call--)rB   Z	stop_hererV   Úinteraction)r2   rY   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)rB   rA   Úcanonicrb   Úco_filenameÚf_linenoÚbp_commandsro   )r2   rY   r   r   r   Ú	user_lineþ   s    ÿ
zPdb.user_linec                 C   s”   t | ddƒr| j| jv r| j}d| _| j}|  |d ¡ | j| D ]}|  |¡ q@|| _| j| sr|  | j| j	 ¡ | j
| r„|  ¡  |  ¡  d S dS )NÚ	currentbpFr   r   )Úgetattrrv   rM   Úlastcmdri   rm   rO   Úprint_stack_entryr]   r^   rN   Ú_cmdloopr\   )r2   rY   rv   Zlastcmd_backr   r   r   r   rt     s"    
ÿ

zPdb.bp_commandsc                 C   s.   | j r
d S ||jd< |  d¡ |  |d ¡ d S )NÚ
__return__z
--Return--)rB   r$   rV   ro   )r2   rY   Zreturn_valuer   r   r   Úuser_return   s
    

zPdb.user_returnc                 C   sh   | j r
d S |\}}}||f|jd< |s2|tu r2dnd}|  d|t ||¡d  ¡ f ¡ |  ||¡ d S )NZ__exception__z	Internal r6   z%s%séÿÿÿÿ)rB   r$   ÚStopIterationrV   Ú	tracebackÚformat_exception_onlyrl   ro   )r2   rY   Úexc_infoÚexc_typeÚ	exc_valueÚexc_tracebackÚprefixr   r   r   Úuser_exception(  s    
ÿÿÿzPdb.user_exceptionc                 C   s@   zd| _ |  ¡  d| _ W q<W q  ty8   |  d¡ Y q 0 q d S )NTFz--KeyboardInterrupt--)rF   ÚcmdlooprU   rV   r1   r   r   r   rz   <  s    zPdb._cmdloopc                 C   s^   | j  | j¡}|rZ| ¡ D ]>\}}|  |¡}||ur||kr|||< |  d|||f ¡ qd S )Nzdisplay %s: %r  [old: %r])r@   Úgetr_   ÚitemsÚ_getval_exceptrV   )r2   r@   ÚexprZoldvalueZnewvaluer   r   r   ÚpreloopI  s    
ÿzPdb.preloopc                 C   sr   t jr4zt tjt j¡ W n ty,   Y n0 d t _|  ||¡rL|  ¡  d S |  | j| j	 ¡ |  
¡  |  ¡  d S r0   )r
   Ú_previous_sigint_handlerÚsignalÚSIGINTÚ
ValueErrorri   r\   ry   r]   r^   rz   )r2   rY   r   r   r   r   ro   V  s    zPdb.interactionc                 C   s   |d ur|   t|ƒ¡ d S r0   )rV   Úrepr)r2   r%   r   r   r   Údisplayhookh  s    zPdb.displayhookc                 C   sº   |d d… dkr|dd … }| j }| jj}zvt|d ddƒ}tj}tj}tj}z:| jt_| jt_| jt_t|||ƒ W |t_|t_|t_n|t_|t_|t_0 W n   |  	¡  Y n0 d S )Nr   ú!Ú
z<stdin>Zsingle)
re   r_   r#   r   r<   rT   rS   r’   ÚexecÚ
_error_exc)r2   r   ÚlocalsÚglobalsr,   Zsave_stdoutZ
save_stdinZsave_displayhookr   r   r   Údefaultp  s*    þzPdb.defaultc                 C   sØ   |  ¡ s|S | ¡ }|d | jv r†| j|d  }d}|dd … D ] }| dt|ƒ |¡}|d7 }q@| dd |dd … ¡¡}| ¡ }q|d dkrÔ| d¡}|dkrÔ||d d …  ¡ }| j 	|¡ |d |…  
¡ }|S )	Nr   r   ú%z%*ú Úaliasz;;é   )rl   Úsplitr?   ÚreplaceÚstrÚjoinÚfindÚlstripÚcmdqueueÚappendÚrstrip)r2   r   ÚargsÚiiZtmpArgZmarkerÚnextr   r   r   Úprecmd…  s(    ÿ


z
Pdb.precmdc                 C   s"   | j stj | |¡S |  |¡S d S r0   )rP   r:   r;   rm   Úhandle_command_def)r2   r   r   r   r   rm   ž  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
| |¡ zt| d| ƒ}W n tyš   | j}Y n0 |j	| j
v r¾d| j| j< g | _dS d S )NZsilentTÚendr   r›   Údo_F)Z	parselinerO   rQ   r¤   rM   r¥   rw   ÚAttributeErrorr™   r   Úcommands_resumingrN   )r2   r   r:   ÚargZcmdlistÚfuncr   r   r   r«   ª  s,    
zPdb.handle_command_defc                 C   s   t || jd d S )N©Úfile©ÚprintrT   ©r2   Úmsgr   r   r   rV   È  s    zPdb.messagec                 C   s   t d|| jd d S )Nz***r²   r´   r¶   r   r   r   ÚerrorË  s    z	Pdb.errorc                 C   s¤   |  ¡  d¡rg S z|  ||||¡}W n ty<   g }Y n0 t t |¡d ¡}|D ]H}tj |¡rv| 	|d ¡ qVtj 
|¡rV| ¡  d¡rV| 	|d ¡ qV|S )N)ú:ú,Ú*ú/)ú.pyz.pywr¹   )rl   ÚendswithÚ_complete_expressionÚ	ExceptionÚglobr   rI   rJ   Úisdirr¥   ÚisfileÚlower)r2   Ú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 urt |ƒ ˆ ¡rt |ƒ‘qS r0   )r    Ú
startswith)Ú.0r-   Úbp©rÅ   r   r   Ú
<listcomp>è  s   ÿz*Pdb._complete_bpnumber.<locals>.<listcomp>)r   r7   Ú
BreakpointÚ
bpbynumber©r2   rÅ   r   rÆ   rÇ   r   rÏ   r   Ú_complete_bpnumberä  s    zPdb._complete_bpnumberc              	      s¾   | j s
g S i | j j¥| j¥}dˆv r¤ˆ d¡‰ z,|ˆ d  }ˆ dd… D ]}t||ƒ}qHW n ttfyt   g  Y S 0 d ˆ d d… ¡d ‰‡ ‡fdd„t|ƒD ƒS ‡fdd„| 	¡ D ƒS d S )NÚ.r   r   r}   c                    s"   g | ]}|  ˆ d  ¡rˆ| ‘qS )r}   ©rÌ   ©rÍ   Ún)Údottedr…   r   r   rÐ   ÿ  ó    z,Pdb._complete_expression.<locals>.<listcomp>c                    s   g | ]}|  ˆ ¡r|‘qS r   rÖ   r×   rÏ   r   r   rÐ     rÚ   )
r_   r#   re   rž   rw   ÚKeyErrorr®   r¡   ÚdirÚkeys)r2   rÅ   r   rÆ   rÇ   Únsr%   Úpartr   )rÙ   r…   rÅ   r   r¿   ë  s    

zPdb._complete_expressionc                 C   s6  |st tjjƒd }n&zt|ƒ}W n   |  d¡ Y d S 0 || _|| jv rj| j| | j| | j	| f}nd }g | j|< d| j|< d| j	|< | j
}d| _
d| _z„z|  ¡  W nf ty   |rì|d | j|< |d | j|< |d | j	|< n| j|= | j|= | j	|= |  d¡ Y n0 W d| _|| _
nd| _|| _
0 d S )	Nr   z.Usage: commands [bnum]
        ...
        endTFz(com) r   r   z1command definition aborted, old commands restored)Úlenr7   rÑ   rÒ   Úintr¸   rQ   rM   rN   rO   r>   rP   r‡   rU   )r2   r°   ZbnumZold_command_defsZprompt_backr   r   r   Údo_commands  sF    %

þ


ÿzPdb.do_commandsr   c              
   C   s>  |s8| j r4|  d¡ tjjD ]}|r|  | ¡ ¡ qd S d }d }d }| d¡}|dkrz||d d …  ¡ }|d |…  ¡ }| 	d¡}d }	|dkr|d |…  ¡ }|  
|¡}
|
sÂ|  d| ¡ d S |
}||d d …  ¡ }zt|ƒ}W n$ ty
   |  d| ¡ Y d S 0 n¾zt|ƒ}W n° tyÊ   zt|| jj| jƒ}W n   |}Y n0 z.t|dƒrf|j}|j}|j}	|j}|j}W nD   |  |¡\}}}|s´|  d	| ¡ Y Y d S |}	t|ƒ}Y n0 Y n0 |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.r}   zBreakpoint %d at %s:%d) ÚbreaksrV   r7   rÑ   rÒ   Zbpformatr¢   r£   r¦   ÚrfindÚlookupmoduler¸   rá   r   Úevalr_   r#   re   Úhasattrrã   Ú__code__Úco_nameÚco_firstlinenorr   ÚlineinfoÚdefaultFileÚ	checklineZ	set_breakÚ
get_breaksÚnumberr³   r   )r2   r°   Z	temporaryrÎ   r   r   ÚcondZcommaÚcolonr   rg   r±   r,   ÚokZlnr   Úerrr   r   r   Údo_breakW  s„    





þ

ÿÿzPdb.do_breakc                 C   s"   | j jj}|dkr| jr| j}|S )Nz<string>)r_   rb   rr   rA   )r2   r   r   r   r   rí   ´  s    
zPdb.defaultFilec                 C   s   |   |d¡ d S r!   )rõ   ©r2   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   é   r6   rÕ   r2   )rž   rà   rl   rí   ræ   r    )
r2   Z
identifierZfailedZidstringÚidÚpartsZfnameÚitemrg   Zanswerr   r   r   rì   É  s,    



zPdb.lineinfoc                 C   s„   t | dd ƒ}|r|jnd }t |||¡}|s:|  d¡ dS | ¡ }|rr|d dksr|d d… dksr|d d… dkr€|  d¡ dS |S )	Nr_   zEnd of filer   rj   rù   z"""z'''zBlank or comment)rw   r#   Ú	linecacheÚgetlinerV   rl   r¸   )r2   r   r   rY   rÉ   r   r   r   r   rî   ê  s    
ÿÿ
zPdb.checklinec                 C   sj   |  ¡ }|D ]X}z|  |¡}W n. tyL } z|  |¡ W Y d }~qd }~0 0 | ¡  |  d| ¡ qd S )Nz
Enabled %s)rž   Úget_bpbynumberr   r¸   ÚenablerV   ©r2   r°   r§   r-   rÎ   rô   r   r   r   Ú	do_enable   s     zPdb.do_enablec                 C   sj   |  ¡ }|D ]X}z|  |¡}W n. tyL } z|  |¡ W Y d }~qd }~0 0 | ¡  |  d| ¡ qd S )NzDisabled %s)rž   rÿ   r   r¸   ÚdisablerV   r  r   r   r   Ú
do_disable  s     zPdb.do_disablec              
   C   sÀ   |  dd¡}z|d }W n ty.   d }Y n0 z|  |d  ¡ ¡}W nH tyb   |  d¡ Y nZ tyŽ } z|  |¡ W Y d }~n6d }~0 0 ||_|s¬|  d|j ¡ n|  d|j ¡ d S )Nr›   r   r   úBreakpoint number expectedz#Breakpoint %d is now unconditional.z$New condition set for breakpoint %d.)	rž   Ú
IndexErrorrÿ   rl   r¸   r   rñ   rV   rð   )r2   r°   r§   rñ   rÎ   rô   r   r   r   Údo_condition%  s    
 zPdb.do_conditionc              
   C   sÜ   |  ¡ }zt|d  ¡ ƒ}W n   d}Y n0 z|  |d  ¡ ¡}W nH ty`   |  d¡ Y nx tyŒ } z|  |¡ W Y d }~nTd }~0 0 ||_|dkrÈ|dkr®d| }nd}|  d||j	f ¡ n|  d|j	 ¡ d S )Nr   r   r  z%d crossingsz
1 crossingz%Will ignore next %s of breakpoint %d.z-Will stop next time breakpoint %d is reached.)
rž   rá   rl   rÿ   r  r¸   r   ÚignorerV   rð   )r2   r°   r§   ÚcountrÎ   rô   Zcountstrr   r   r   Ú	do_ignore@  s,    	
 
ÿÿzPdb.do_ignorec           
      C   s†  |srzt dƒ}W n ty&   d}Y n0 | ¡  ¡ }|dv rndd„ tjjD ƒ}|  ¡  |D ]}|  d| ¡ qZd S d|v r| 	d¡}|d |… }||d d … }zt
|ƒ}W n tyÈ   d	| }Y n"0 |  ||¡d d … }|  ||¡}|rú|  |¡ n|D ]}|  d| ¡ qþd S | ¡ }	|	D ]^}z|  |¡}W n0 tyd } z|  |¡ W Y d }~n"d }~0 0 |  |¡ |  d| ¡ q"d S )
NzClear all breaks? Úno)ÚyZyesc                 S   s   g | ]}|r|‘qS r   r   )rÍ   rÎ   r   r   r   rÐ   q  rÚ   z Pdb.do_clear.<locals>.<listcomp>z
Deleted %sr¹   r   zInvalid line number (%s))ÚinputÚEOFErrorrl   rÄ   r7   rÑ   rÒ   Zclear_all_breaksrV   rå   rá   r   rï   Zclear_breakr¸   rž   rÿ   Zclear_bpbynumber)
r2   r°   ZreplyZbplistrÎ   r-   r   r   rô   Z
numberlistr   r   r   Údo_clearc  sF    


 
zPdb.do_clearc                 C   s   |   ¡  d S r0   )Úprint_stack_tracerö   r   r   r   Údo_where–  s    zPdb.do_wherec                 C   s>   || _ | j| j  d | _| jj| _|  | j| j  ¡ d | _d S r(   )r^   r]   r_   r$   re   ry   r   )r2   rð   r   r   r   Ú_select_frame   s
    
zPdb._select_framec                 C   sx   | j dkr|  d¡ d S zt|p"dƒ}W n" tyJ   |  d| ¡ Y d S 0 |dk rZd}ntd| j | ƒ}|  |¡ d S )Nr   zOldest framer   úInvalid frame count (%s))r^   r¸   rá   r   Úmaxr  ©r2   r°   r	  Znewframer   r   r   Údo_up¨  s    

z	Pdb.do_upc                 C   s–   | j d t| jƒkr"|  d¡ d S zt|p,dƒ}W n" tyT   |  d| ¡ Y d S 0 |dk rnt| jƒd }ntt| jƒd | j | ƒ}|  |¡ d S )Nr   zNewest framer  r   )r^   rà   r]   r¸   rá   r   Úminr  r  r   r   r   Údo_down¼  s    
zPdb.do_downc                 C   sf   |rPzt |ƒ}W n" ty2   |  d| ¡ Y d S 0 || jjkrT|  d¡ d S nd }|  | j|¡ dS )NúError in argument: %rz7"until" line number is smaller than current line numberr   )rá   r   r¸   r_   rs   Z	set_until)r2   r°   r   r   r   r   Údo_untilÐ  s    
zPdb.do_untilc                 C   s   |   ¡  dS r!   )rW   rö   r   r   r   Údo_stepè  s    zPdb.do_stepc                 C   s   |   | j¡ dS r!   )Zset_nextr_   rö   r   r   r   Údo_nextò  s    zPdb.do_nextc              
   C   sz   |rrdd l }tjdd… }z| |¡t_W n8 tyb } z |  d||f ¡ W Y d }~d S d }~0 0 |tjd d…< t‚d S )Nr   r   zCannot run %s: %s)Úshlexr<   Úargvrž   r   r¸   r   )r2   r°   r  Zargv0Úer   r   r   Údo_runû  s    z
Pdb.do_runc                 C   s   |   | j¡ dS r!   )Z
set_returnr_   rö   r   r   r   Ú	do_return  s    zPdb.do_returnc                 C   s<   | j s0zt tj| j¡t_W n ty.   Y n0 |  ¡  dS r!   )rG   rŽ   r   rZ   r
   r   r   Zset_continuerö   r   r   r   Údo_continue  s    ÿzPdb.do_continuec              
   C   s¾   | j d t| jƒkr"|  d¡ d S zt|ƒ}W n tyJ   |  d¡ Y np0 z:|| j_| j| j  d |f| j| j < |  | j| j  ¡ W n2 ty¸ } z|  d| ¡ W Y d }~n
d }~0 0 d S )Nr   z)You can only jump within the bottom framez)The 'jump' command requires a line numberr   zJump failed: %s)	r^   rà   r]   r¸   rá   r   r_   rs   ry   )r2   r°   r  r   r   r   Údo_jump*  s    
zPdb.do_jumpc                 C   sš   t  d ¡ | jj}| j}t| j| j| jƒ}d| j	 
¡  |_	|  d¡ zt  |j|||f¡ W n tyv   |  ¡  Y n0 |  d¡ t  | j¡ |j| _d S )Nz(%s) zENTERING RECURSIVE DEBUGGERzLEAVING RECURSIVE DEBUGGER)r<   Úsettracer_   r#   re   r
   rR   rS   rT   r>   rl   rV   Úcall_tracingr   rÀ   r–   Ztrace_dispatchrx   )r2   r°   r˜   r—   Úpr   r   r   Údo_debugG  s    


zPdb.do_debugc                 C   s   d| _ |  ¡  dS )NTr   )Ú_user_requested_quitÚset_quitrö   r   r   r   Údo_quit]  s    zPdb.do_quitc                 C   s   |   d¡ d| _|  ¡  dS )Nr6   Tr   )rV   r(  r)  rö   r   r   r   Údo_EOFh  s    
z
Pdb.do_EOFc                 C   sŽ   | j j}| j}|j|j }|jtj@ r.|d }|jtj@ rB|d }t	|ƒD ]>}|j
| }||v rx|  d||| f ¡ qJ|  d|f ¡ qJd S )Nr   z%s = %rz%s = *** undefined ***)r_   rb   re   Úco_argcountÚco_kwonlyargcountÚco_flagsr"   Z
CO_VARARGSZCO_VARKEYWORDSÚrangeÚco_varnamesrV   )r2   r°   ÚcoÚdictrØ   r-   Únamer   r   r   Údo_argsq  s    
zPdb.do_argsc                 C   s.   d| j v r |  t| j d ƒ¡ n
|  d¡ d S )Nr{   zNot yet returned!)re   rV   r‘   r¸   rö   r   r   r   Ú	do_retval‚  s    
zPdb.do_retvalc                 C   s0   zt || jj| jƒW S    |  ¡  ‚ Y n0 d S r0   )rç   r_   r#   re   r–   rö   r   r   r   Ú_getvalŒ  s
    zPdb._getvalc                 C   sr   z2|d u rt || jj| jƒW S t ||j|jƒW S W n:   t ¡ d d… }tj|Ž d  	¡ }t
d| ƒ Y S 0 d S )Nr   r}   z** raised %s **)rç   r_   r#   re   r$   r<   r   r   r€   rl   r/   )r2   r°   rY   r   rô   r   r   r   rŠ   “  s    zPdb._getval_exceptc                 C   s,   t  ¡ d d… }|  tj|Ž d  ¡ ¡ d S )Nr   r}   )r<   r   r¸   r   r€   rl   )r2   r   r   r   r   r–   ž  s    zPdb._error_excc                 C   sJ   z|   |¡}W n   Y d S 0 z|  ||ƒ¡ W n   |  ¡  Y n0 d S r0   )r6  rV   r–   )r2   r°   r±   Úvalr   r   r   Ú_msg_val_func¢  s    zPdb._msg_val_funcc                 C   s   |   |t¡ d S r0   )r8  r‘   rö   r   r   r   Údo_p¬  s    zPdb.do_pc                 C   s   |   |tj¡ d S r0   )r8  ÚpprintZpformatrö   r   r   r   Údo_pp²  s    z	Pdb.do_ppc                 C   sb  d| _ d }|rš|dkršz^d|v rX| d¡\}}t| ¡ ƒ}t| ¡ ƒ}||k rr|| }nt| ¡ ƒ}td|d ƒ}W qÊ ty–   |  d| ¡ Y d S 0 n0| jd u s¬|dkrÀtd| jj	d ƒ}n
| jd }|d u rÚ|d }| jj
j}|  |¡}zZt || jj¡}|  ||d |… ||| j¡ t|t|ƒƒ| _t|ƒ|k rF|  d¡ W n ty\   Y n0 d S )	Nr)   rÕ   rº   r   é   r  é
   z[EOF])rx   rž   rá   rl   r  r   r¸   r   r_   rs   rb   rr   Úget_file_breaksrý   Úgetlinesr#   Ú_print_linesr  rà   rV   rU   )r2   r°   ZlastÚfirstr   Ú	breaklistr&   r   r   r   Údo_list¼  s@    




ÿzPdb.do_listc              
   C   sn   | j jj}|  |¡}zt| j ƒ\}}W n0 tyV } z|  |¡ W Y d }~d S d }~0 0 |  |||| j ¡ d S r0   )r_   rb   rr   r>  r'   r   r¸   r@  )r2   r°   r   rB  r&   r   rô   r   r   r   Údo_longlistï  s    


zPdb.do_longlistc              
   C   st   z|   |¡}W n   Y d S 0 zt|ƒ\}}W n4 ttfyb } z|  |¡ W Y d }~d S d }~0 0 |  ||¡ d S r0   )r6  r'   r   Ú	TypeErrorr¸   r@  )r2   r°   r%   r&   r   rô   r   r   r   Ú	do_sourceý  s    
zPdb.do_sourcer   c           
      C   s®   |r|j }| j |d¡}nd }}t||ƒD ]|\}}t|ƒ d¡}	t|	ƒdk rV|	d7 }	||v rh|	d7 }	n|	d7 }	||kr‚|	d7 }	n||kr’|	d7 }	|  |	d | ¡  ¡ q,d S )	Nr}   rù   é   r›   ÚBz->z>>ú	)	rs   rC   rˆ   r   r    Úrjustrà   rV   r¦   )
r2   r&   r   rä   rY   Zcurrent_linenoZ
exc_linenor   r   Úsr   r   r   r@    s     

zPdb._print_linesc                 C   sÆ   z|   |¡}W n   Y d S 0 d }z|jj}W n ty@   Y n0 |rZ|  d|j ¡ d S z
|j}W n tyv   Y n0 |r|  d|j ¡ d S |jtu r´|  d|j|j	f ¡ d S |  t|ƒ¡ d S )Nz	Method %szFunction %szClass %s.%s)
r6  rã   ré   rÀ   rV   rê   Ú	__class__Útyper   r   )r2   r°   Úvaluer,   r   r   r   Ú	do_whatis#  s.    

zPdb.do_whatisc                 C   sl   |s8|   d¡ | j | ji ¡ ¡ D ]}|   d| ¡ q"n0|  |¡}|| j | ji ¡|< |   d||f ¡ d S )NzCurrently displaying:z%s: %rzdisplay %s: %r)rV   r@   rˆ   r_   r‰   rŠ   Ú
setdefault)r2   r°   rü   r7  r   r   r   Ú
do_displayF  s    

zPdb.do_displayc                 C   sR   |r>z| j  | ji ¡|= W qN ty:   |  d| ¡ Y qN0 n| j  | jd ¡ d S )Nznot displaying %s)r@   rˆ   r_   rÛ   r¸   rk   rö   r   r   r   Údo_undisplayY  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Ð   i  s   
ÿz*Pdb.complete_undisplay.<locals>.<listcomp>)r@   rˆ   r_   rÓ   r   rÏ   r   Úcomplete_undisplayh  s    zPdb.complete_undisplayc                 C   s$   i | j j¥| j¥}tjd|d d S )Nz*interactive*)Úlocal)r_   r#   re   r,   Úinteract)r2   r°   rÞ   r   r   r   Údo_interactl  s    zPdb.do_interactc                 C   s¤   |  ¡ }t|ƒdkrHt| j ¡ ƒ}|D ]}|  d|| j| f ¡ q&d S |d | jv 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à   Úsortedr?   rÝ   rV   r¡   )r2   r°   r§   rÝ   rœ   r   r   r   Údo_aliasu  s    "zPdb.do_aliasc                 C   s6   |  ¡ }t|ƒdkrd S |d | jv r2| j|d = d S r(   )rž   rà   r?   )r2   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Í   ÚarÏ   r   r   rÐ   ¢  rÚ   z(Pdb.complete_unalias.<locals>.<listcomp>)r?   rÓ   r   rÏ   r   Úcomplete_unalias¡  s    zPdb.complete_unalias)r"  r  r  r!  r*  r#  c                 C   s2   z| j D ]}|  |¡ qW n ty,   Y n0 d S r0   )r]   ry   rU   )r2   Úframe_linenor   r   r   r  °  s
    
zPdb.print_stack_tracec                 C   s6   |\}}|| j u rd}nd}|  ||  ||¡ ¡ d S )Nz> z  )r_   rV   Zformat_stack_entry)r2   r\  Zprompt_prefixrY   r   r…   r   r   r   ry   ·  s    

ÿzPdb.print_stack_entryc                 C   sÀ   |st j | |¡S z>zt| d| ƒ}|ƒ W W S  tyL   t| d| ƒ}Y n0 W n  typ   |  d| ¡ Y nL0 tjjdkr|  d| ¡ d S |j	d u 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 helpz&No help for %r; __doc__ string missing)r:   r;   Údo_helprw   r®   r¸   r<   ÚflagsÚoptimizeÚ__doc__rV   r¦   )r2   r°   ZtopicZcommandr   r   r   r]  Â  s&    
ÿ
zPdb.do_helpc                 C   s   |   | jjpd ¡ ¡ d S )Nr6   )rV   Ú	help_execr`  rl   r1   r   r   r   ra  ß  s    
zPdb.help_execc                 C   s
   t ƒ  d S r0   )r   r1   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 tjD ]>}t j 	|¡r¢t  
|¡}qŠt j ||¡}t j |¡r†|  S q†d S )Nr   r6   r½   )rI   rJ   ÚisabsÚexistsr¡   r<   rq   rA   ÚsplitextÚislinkÚreadlink)r2   r   rg   ÚrootÚ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__)rB   r(  ÚrunpyÚ_get_module_detailsrq   rr   rA   rl  Ú__dict__r`   ÚupdateÚparentÚloaderrq  r   )r2   Úmodule_namerr  Zmod_nameZmod_specr,   rl  r   r   r   Ú
_runmodule  s     
úzPdb._runmodulec                 C   sˆ   dd l }|j ¡  |j d|tdœ¡ d| _|  |¡| _d| _t	 
|¡"}d| ¡ | jf }W d   ƒ n1 sp0    Y  |  |¡ d S )Nr   rl  )r   rm  rq  TFzexec(compile(%r, %r, 'exec')))rl  rt  r`   ru  rq  rB   rq   rA   r(  ÚioÚ	open_codeÚreadr   )r2   r   rl  r   Ú	statementr   r   r   Ú
_runscript  s    
þ
ÿ"zPdb._runscript)r4   NNNFT)r   )N)r   N)yr   r   r   r   r9   rZ   r[   r\   ri   rf   rp   ru   rt   r|   r†   rz   rŒ   ro   r’   r™   rª   rm   r«   rV   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+  r4  Zdo_ar5  Zdo_rvr6  rŠ   r–   r8  r9  r;  Zcomplete_printZ
complete_pZcomplete_pprC  Zdo_lrD  Zdo_llrF  Zcomplete_sourcer@  rO  Zcomplete_whatisrQ  Zcomplete_displayrR  rS  rV  rX  rY  r[  r¯   r  Úline_prefixry   r]  Zdo_hra  rb  ræ   ry  r~  r   r   r   r   r
   Š   sì     ÿ
/	
M
]!!.	

1
!	#	r
   )"r   ÚwhereZdownZupÚbreakZtbreakr`   r  r   r  Z	conditionrM   Ústepr©   ZuntilZjumpÚreturnZretvalr   Úcontinuer)   Zlonglistr§   r&  ÚppZwhatisÚsourceZdisplayZ	undisplayrU  rœ   ZunaliasÚdebugÚquitr­   z

c                 C   s   t ƒ  | ||¡ d S r0   )r
   r   ©r}  r˜   r—   r   r   r   r   I  s    r   c                 C   s   t ƒ  | ||¡S r0   )r
   r   )Z
expressionr˜   r—   r   r   r   r   L  s    r   c                 C   s   t | ||ƒ d S r0   )r   r‰  r   r   r   r   O  s    r   c                  O   s   t ƒ j| i |¤ŽS r0   )r
   r   )r§   Úkwdsr   r   r   r   S  s    r   )Úheaderc                 C   s,   t ƒ }| d ur| | ¡ | t ¡ j¡ d S r0   )r
   rV   r   r<   Ú	_getframeÚf_back)r‹  Úpdbr   r   r   r   V  s    
r   c                 C   sB   | d u rt  ¡ d } | d u r$tdƒ‚tƒ }| ¡  | d | ¡ d S )Nr   zAA valid traceback must be passed if no exception is being handled)r<   r   r   r
   r[   ro   )Útr&  r   r   r   r   ^  s    r   c                   C   s   t tjƒ d S r0   )r   r<   Úlast_tracebackr   r   r   r   r	   l  s    r	   zimport x; x.main()c                   C   s   t tƒ d S r0   )r   ÚTESTCMDr   r   r   r   Útestt  s    r’  c                  C   s   dd l } |  t¡ d S r(   )ÚpydocZpagerr`  )r“  r   r   r   r   x  s    r   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   sX  dd l } |   tjdd … dddg¡\}}|s>ttƒ t d¡ g }d}|D ]B\}}|dv rlttƒ t ¡  qJ|d	v r€| |¡ qJ|d
v rJd}qJ|d }|s¼tj 	|¡s¼td|dƒ t d¡ |rüdd l
}z| |¡ W n$ tyú   t ¡  t d¡ Y n0 |tjd d …< |s.tj |¡}tj |¡tjd< tƒ }	|	j |¡ z6|rT|	 |¡ n
|	 |¡ |	jrlW qTtdƒ W nØ ty²   td|dƒ tdd tjdd … ¡ ƒ Y nž tyà   tddd tt ¡ d ƒ Y np ty   t ¡  t d¡ Y nL   t ¡  tdƒ tdƒ t ¡ d }
|	 d |
¡ td| d ƒ Y n0 q@d S )Nr   r   zmhc:r   z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:rI  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¥   rI   rJ   rd  rr  rs  rÀ   r   Ú	print_excÚrealpathrj  r
   rH   rL   ry  r~  r(  r   r¡   Ú
SystemExitr   ÚSyntaxErrorro   )r”  Zoptsr§   rM   Zrun_as_moduleÚoptZoptargrA   rr  rŽ  r  r   r   r   Úmain‹  sr     



 ÿrœ  rl  )NN)NN)N)/rI   rz  r   r<   r:   r7   r*   r,   rÁ   r:  rŽ   r"   r   r   rý   rÀ   r   Ú__all__r    r'   r.   r    r/   r  r8   r;   r
   r`  Z_help_orderZ_commandrw   rl   ra  r   r   r   r   r   r   r	   r‘  r’  r   r•  rœ  r   rŽ  r   r   r   r   Ú<module>F   sl   		           7



L
