o
    Zh                     @   s(  d dl Z d dlZd dlZd dlmZ d dlmZ ddlmZ ddl	m
Z
 ddlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ  e !dZ"dej#v Z$G dd deZ%dddZ&e'dkrd dl(Z(e(jj)Z*e%e(_e*e(j_)e(+  dS dS )    N)Pdb)IPCompleter   )IPythonPTCompleter)create_ipython_shortcuts)embed)Path)Token)create_app_session)PromptSession)EditingModePygmentsTokens)InMemoryHistoryFileHistory)ThreadPoolExecutor)__version__z3.ZIPY_TEST_SIMPLE_PROMPTc                   @   sB   e Zd ZdZddddZdddZdd	 Zdd
dZdd ZdS )TerminalPdbzStandalone IPython debugger.N)pt_session_optionsc                O   s6   t j| g|R i | d | _| | td| _d S )Nr   )r   __init___ptcomppt_initr   thread_executor)selfr   argskwargs r   P/var/www/html/lang_env/lib/python3.10/site-packages/IPython/terminal/debugger.pyr       s   
zTerminalPdb.__init__c                    sv  |du ri }fdd j du r@tji i jd}dd tD fdd}d	dl}|||}|jd	| t|_ jj	du rmjj
durhtjj
 }| s\|  ttjt|_	n
t _	njj	_	t fd
dttjj tjj	j djjjjtjddjjd
}tsjj|d< || t st!" _#t$di |_%dS dS )zInitialize the prompt session and the prompt loop
        and store them in self.pt_app and self.pt_loop.

        Additional keyword arguments for the PromptSession class
        can be specified in pt_session_options.
        Nc                      s   t j jfgS N)r	   Promptpromptr   r   r   r   get_prompt_tokens0   s   z.TerminalPdb.pt_init.<locals>.get_prompt_tokens)shell	namespaceglobal_namespaceparentc                 S   s"   g | ]}| d r|dd qS )Zdo_   N
startswith.0mr   r   r   
<listcomp>8   s   " z'TerminalPdb.pt_init.<locals>.<listcomp>c                    s    fddD S )Nc                    s   g | ]	}|  r|qS r   r(   r*   textr   r   r-   ;   s    z9TerminalPdb.pt_init.<locals>.gen_comp.<locals>.<listcomp>r   )r   r/   )methods_namesr.   r   gen_comp:   s   z%TerminalPdb.pt_init.<locals>.gen_compr   c                      s
   t   S r   r   r   )r"   r   r   <lambda>P   s   
 z%TerminalPdb.pt_init.<locals>.<lambda>Tstyle)
messageediting_modeZkey_bindingshistoryZ	completerZenable_history_searchmouse_supportcomplete_styler3   color_depth	inputhookr   )&r   r   r#   dirtypes
MethodTypeZcustom_matchersinsertr   Zdebugger_historyZdebugger_history_filer   
expanduserexiststouchr   ospathstrr   dictgetattrr   r5   upperr   r7   Zpt_complete_styler9   PTK3r:   update_use_simple_promptasyncionew_event_loopZpt_loopr   pt_app)r   r   Zcomplr1   r<   Znewcomppoptionsr   )r"   r0   r   r   r   &   sP   






zTerminalPdb.pt_initc                 C   s4   t   | j W  d   S 1 sw   Y  dS )a  
        In case other prompt_toolkit apps have to run in parallel to this one (e.g. in madbg),
        create_app_session must be used to prevent mixing up between them. According to the prompt_toolkit docs:

        > If you need multiple applications running at the same time, you have to create a separate
        > `AppSession` using a `with create_app_session():` block.
        N)r
   rM   r    r!   r   r   r   _promptc   s   $zTerminalPdb._promptc                 C   s   | j std|   zc|dur|| _| jrt| j| jd d}|sh| jr,| jd}n*| j| j	j
_| jj| j	j
_tsRz| j| j }W n tyQ   d}Y nw td}| |}| |}| ||}|r"|   W dS  tyv    w )a  Repeatedly issue a prompt, accept input, parse an initial prefix
        off the received input, and dispatch to action methods, passing them
        the remainder of the line as argument.

        override the same methods from cmd.Cmd to provide prompt toolkit replacement.
        z.Sorry ipdb does not support use_rawinput=FalseN)filer   ZEOFzipdb> )Zuse_rawinput
ValueErrorZpreloopintroprintstdoutZcmdqueuepopcurframe_localsr   Zipy_completerr$   curframe	f_globalsr%   rJ   r   submitrP   resultEOFErrorinputZprecmdZonecmdZpostcmdZpostloop	Exception)r   rS   stopliner   r   r   cmdloopn   s:   

zTerminalPdb.cmdloopc                 C   s<   t j| jjddd}| jj}|tj|d d | j	d d S )Nz*interactive*z *exiting interactive console...*)configZbanner1Zexit_msg__name__)moduleZlocal_ns)
r   ZInteractiveShellEmbedr#   rb   rX   rY   sysmodulesgetrW   )r   argZipshell	global_nsr   r   r   do_interact   s   
zTerminalPdb.do_interactr   )	rc   
__module____qualname____doc__r   r   rP   ra   rj   r   r   r   r   r      s    
=
.r   c                 C   s   t  | p	t j dS )zm
    Start debugging from `frame`.

    If frame is not specified, debugging starts from caller's frame.
    N)r   	set_tracere   	_getframef_back)framer   r   r   rn      s   rn   __main__r   ),rK   rB   re   ZIPython.core.debuggerr   ZIPython.core.completerr   Zptutilsr   Z	shortcutsr    r   pathlibr   Zpygments.tokenr	   Zprompt_toolkit.applicationr
   Zprompt_toolkit.shortcuts.promptr   Zprompt_toolkit.enumsr   Zprompt_toolkit.formatted_textr   Zprompt_toolkit.historyr   r   concurrent.futuresr   Zprompt_toolkitr   Zptk_versionr)   rH   environrJ   r   rn   rc   pdbZtrace_dispatchZold_trace_dispatchmainr   r   r   r   <module>   s:    

 
	