a
    ze/                     @   s   d dl Z d dlZd dlmZ d ZdadZi Zi Zi Z	i Z
dd Zdd ZG d	d
 d
ZG dd dZdd ZG dd dZG dd dZG dd dZG dd dZG dd dZdd Zdd Zdd Zdd  Zed!krd d"lmZ ed#d$d%d& dS )'    N)debuggeridb_adapterZgui_adapterc                 C   s   t | }| t|< |S N)id
frametable)framefid r	   (/usr/lib/python3.9/idlelib/debugger_r.py
wrap_frame(   s    r   c                 C   s>   | d u rd S | d }t |}|t|< | d | d |f}|S d S )N   r      )r   tracebacktable)info	tracebackZtraceback_idmodified_infor	   r	   r
   	wrap_info-   s    r   c                   @   s   e Zd Zdd ZdddZdS )GUIProxyc                 C   s   || _ || _d S r   )connoid)selfr   gui_adap_oidr	   r	   r
   __init__;   s    zGUIProxy.__init__Nc                 C   s&   | j | jd|t|t|fi  d S )Ninteraction)r   
remotecallr   r   r   )r   messager   r   r	   r	   r
   r   ?   s    zGUIProxy.interaction)N__name__
__module____qualname__r   r   r	   r	   r	   r
   r   9   s   r   c                   @   s   e Z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)S )*
IdbAdapterc                 C   s
   || _ d S r   )idb)r   r!   r	   r	   r
   r   H   s    zIdbAdapter.__init__c                 C   s   | j   d S r   )r!   set_stepr   r	   r	   r
   r"   M   s    zIdbAdapter.set_stepc                 C   s   | j   d S r   )r!   set_quitr#   r	   r	   r
   r$   P   s    zIdbAdapter.set_quitc                 C   s   | j   d S r   )r!   set_continuer#   r	   r	   r
   r%   S   s    zIdbAdapter.set_continuec                 C   s   t | }| j| d S r   )r   r!   set_nextr   r   r   r	   r	   r
   r&   V   s    zIdbAdapter.set_nextc                 C   s   t | }| j| d S r   )r   r!   
set_returnr'   r	   r	   r
   r(   Z   s    zIdbAdapter.set_returnc                 C   sF   t | }|d u rd }nt| }| j||\}}dd |D }||fS )Nc                 S   s   g | ]\}}t ||fqS r	   )r   ).0Zframe2kr	   r	   r
   
<listcomp>e       z(IdbAdapter.get_stack.<locals>.<listcomp>)r   r   r!   	get_stack)r   r   tbidr   tbstackir	   r	   r
   r-   ^   s    zIdbAdapter.get_stackc                 C   s   dd l }| j||j d S )Nr   )__main__r!   run__dict__)r   cmdr2   r	   r	   r
   r3   h   s    zIdbAdapter.runc                 C   s   | j ||}|S r   )r!   	set_breakr   filenamelinenomsgr	   r	   r
   r6   l   s    zIdbAdapter.set_breakc                 C   s   | j ||}|S r   )r!   clear_breakr7   r	   r	   r
   r;   p   s    zIdbAdapter.clear_breakc                 C   s   | j |}|S r   )r!   clear_all_file_breaksr   r8   r:   r	   r	   r
   r<   t   s    z IdbAdapter.clear_all_file_breaksc                 C   s   t | }t||S r   )r   getattr)r   r   namer   r	   r	   r
   
frame_attrz   s    zIdbAdapter.frame_attrc                 C   s"   t | }|j}t|}|t|< |S r   )r   	f_globalsr   	dicttabler   r   r   dictdidr	   r	   r
   frame_globals~   s
    zIdbAdapter.frame_globalsc                 C   s"   t | }|j}t|}|t|< |S r   )r   f_localsr   rB   rC   r	   r	   r
   frame_locals   s
    zIdbAdapter.frame_localsc                 C   s"   t | }|j}t|}|t|< |S r   )r   f_coder   	codetable)r   r   r   codecidr	   r	   r
   
frame_code   s
    zIdbAdapter.frame_codec                 C   s   t | }|jS r   )rJ   co_namer   rL   rK   r	   r	   r
   	code_name   s    zIdbAdapter.code_namec                 C   s   t | }|jS r   )rJ   co_filenamerO   r	   r	   r
   code_filename   s    zIdbAdapter.code_filenamec                 C   s   t dd S )Nz"dict_keys not public or pickleable)NotImplementedErrorr   rE   r	   r	   r
   	dict_keys   s    zIdbAdapter.dict_keysc                 C   s   t | }t| S r   )rB   listkeys)r   rE   rD   r	   r	   r
   dict_keys_list   s    zIdbAdapter.dict_keys_listc                 C   s   t | }|| }t|}|S r   )rB   reprlibrepr)r   rE   keyrD   valuer	   r	   r
   	dict_item   s    
zIdbAdapter.dict_itemN)r   r   r   r   r"   r$   r%   r&   r(   r-   r3   r6   r;   r<   r@   rF   rH   rM   rP   rR   rU   rX   r]   r	   r	   r	   r
   r    F   s(   
	r    c                 C   s,   t | |}t|}t|}| t| tS r   )r   r   ZIdbr    registeridb_adap_oid)Z
rpchandlerr   Z	gui_proxyr!   Zidb_adapr	   r	   r
   start_debugger   s
    


r`   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )
FrameProxyc                 C   s   || _ || _d| _i | _d S )Nr   )_conn_fid_oid
_dictcache)r   r   r   r	   r	   r
   r      s    zFrameProxy.__init__c                 C   sb   |d d dkrt ||dkr(|  S |dkr8|  S |dkrH|  S | j| jd| j|fi S )Nr   _rI   rA   rG   r@   )AttributeError_get_f_code_get_f_globals_get_f_localsrb   r   rd   rc   r   r?   r	   r	   r
   __getattr__   s    
zFrameProxy.__getattr__c                 C   s(   | j | jd| jfi }t| j | j|S )NrM   )rb   r   rd   rc   	CodeProxy)r   rL   r	   r	   r
   rh      s    zFrameProxy._get_f_codec                 C   s"   | j | jd| jfi }| |S )NrF   rb   r   rd   rc   _get_dict_proxyrT   r	   r	   r
   ri      s    zFrameProxy._get_f_globalsc                 C   s"   | j | jd| jfi }| |S )NrH   rn   rT   r	   r	   r
   rj      s    zFrameProxy._get_f_localsc                 C   s2   || j v r| j | S t| j| j|}|| j |< |S r   )re   	DictProxyrb   rd   )r   rE   Zdpr	   r	   r
   ro      s
    


zFrameProxy._get_dict_proxyN)	r   r   r   r   rl   rh   ri   rj   ro   r	   r	   r	   r
   ra      s   ra   c                   @   s   e Zd Zdd Zdd ZdS )rm   c                 C   s   || _ || _|| _d S r   )rb   rd   _cid)r   r   r   rL   r	   r	   r
   r      s    zCodeProxy.__init__c                 C   sD   |dkr | j | jd| jfi S |dkr@| j | jd| jfi S d S )NrN   rP   rQ   rR   )rb   r   rd   rq   rk   r	   r	   r
   rl      s    zCodeProxy.__getattr__N)r   r   r   r   rl   r	   r	   r	   r
   rm      s   rm   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
rp   c                 C   s   || _ || _|| _d S r   )rb   rd   _did)r   r   r   rE   r	   r	   r
   r     s    zDictProxy.__init__c                 C   s   | j | jd| jfi S )NrX   rb   r   rd   rr   r#   r	   r	   r
   rW     s    

zDictProxy.keysc                 C   s   | j | jd| j|fi S )Nr]   rs   )r   r[   r	   r	   r
   __getitem__  s    
zDictProxy.__getitem__c                 C   s   t |d S r   )rg   rk   r	   r	   r
   rl     s    zDictProxy.__getattr__N)r   r   r   r   rW   rt   rl   r	   r	   r	   r
   rp     s   	rp   c                   @   s   e Zd Zdd Zdd ZdS )
GUIAdapterc                 C   s   || _ || _d S r   )r   gui)r   r   rv   r	   r	   r
   r     s    zGUIAdapter.__init__c                 C   s    t | j|}| j||| d S r   )ra   r   rv   r   )r   r   r   r   r   r	   r	   r
   r   !  s    zGUIAdapter.interactionNr   r	   r	   r	   r
   ru     s   ru   c                   @   sl   e Z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S )IdbProxyc                 C   s   || _ || _|| _d S r   )r   r   shell)r   r   rx   r   r	   r	   r
   r   )  s    zIdbProxy.__init__c                O   s   | j | j|||}|S r   )r   r   r   )r   Z
methodnameargskwargsr\   r	   r	   r
   call.  s    zIdbProxy.callc                 C   s$   | j | jd|fi }|| jj_d S )Nr3   )r   Z
asyncqueuer   rx   ZinterpZ
active_seq)r   r5   localsseqr	   r	   r
   r3   4  s    zIdbProxy.runc                    s.     d|j|\}} fdd|D }||fS )Nr-   c                    s    g | ]\}}t  j||fqS r	   )ra   r   )r)   r   r*   r#   r	   r
   r+   <  r,   z&IdbProxy.get_stack.<locals>.<listcomp>r{   rc   )r   r   r.   r0   r1   r	   r#   r
   r-   9  s    zIdbProxy.get_stackc                 C   s   |  d d S )Nr%   r{   r#   r	   r	   r
   r%   ?  s    zIdbProxy.set_continuec                 C   s   |  d d S )Nr"   r   r#   r	   r	   r
   r"   B  s    zIdbProxy.set_stepc                 C   s   |  d|j d S )Nr&   r~   r   r   r	   r	   r
   r&   E  s    zIdbProxy.set_nextc                 C   s   |  d|j d S )Nr(   r~   r   r	   r	   r
   r(   H  s    zIdbProxy.set_returnc                 C   s   |  d d S )Nr$   r   r#   r	   r	   r
   r$   K  s    zIdbProxy.set_quitc                 C   s   |  d||}|S )Nr6   r   r7   r	   r	   r
   r6   N  s    zIdbProxy.set_breakc                 C   s   |  d||}|S )Nr;   r   r7   r	   r	   r
   r;   R  s    zIdbProxy.clear_breakc                 C   s   |  d|}|S )Nr<   r   r=   r	   r	   r
   r<   V  s    zIdbProxy.clear_all_file_breaksN)r   r   r   r   r{   r3   r-   r%   r"   r&   r(   r$   r6   r;   r<   r	   r	   r	   r
   rw   '  s   rw   c                 C   sD   |  ddtfi at| |t}t||}t| |}| t| |S NexecZstart_the_debugger)r   r   r_   rw   r   ZDebuggerru   r^   )rpccltZpyshellZ	idb_proxyrv   Zgui_adapr	   r	   r
   start_remote_debuggerZ  s    
r   c                 C   s   t |  | t d S r   )close_subprocess_debugger
unregisterr   r   r	   r	   r
   close_remote_debuggerr  s    	r   c                 C   s   |  ddtfi  d S )Nr   Zstop_the_debugger)r   r_   r   r	   r	   r
   r   ~  s    r   c                 C   s   |  ddtfi }d S r   )r   r   )r   Zidb_adap_oid_retr	   r	   r
   restart_subprocess_debugger  s    r   r2   )mainz!idlelib.idle_test.test_debugger_rr   F)	verbosityexit)rY   typesZidlelibr   Z	debuggingr_   r   r   rB   rJ   r   r   r   r   r    r`   ra   rm   rp   ru   rw   r   r   r   r   r   Zunittestr   r	   r	   r	   r
   <module>   s4   m*3