o
    û›hÂ  ã                   @   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r’d 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   úOc:\Users\shubh\Videos\agent\nova\Lib\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 s¹t! "¡ ˆ_#t$di |¤Žˆ_%dS dS )zäInitialize 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:    

 
	÷