
    MhN                    Z   d Z ddlm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	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 erddlmZ dZdZdZ ej!        dk     Z"ddZ# ej$        d          Z%d Z&ddZ' G d de          Z G d de          Z(ddZ)dS )a  
Pdb debugger class.


This is an extension to PDB which adds a number of new features.
Note that there is also the `IPython.terminal.debugger` class which provides UI
improvements.

We also strongly recommend to use this via the `ipdb` package, which provides
extra configuration options.

Among other things, this subclass of PDB:
 - supports many IPython magics like pdef/psource
 - hide frames in tracebacks based on `__tracebackhide__`
 - allows to skip frames based on `__debuggerskip__`


Global Configuration
--------------------

The IPython debugger will by read the global ``~/.pdbrc`` file.
That is to say you can list all commands supported by ipdb in your `~/.pdbrc`
configuration file, to globally configure pdb.

Example::

   # ~/.pdbrc
   skip_predicates debuggerskip false
   skip_hidden false
   context 25

Features
--------

The IPython debugger can hide and skip frames when printing or moving through
the stack. This can have a performance impact, so can be configures.

The skipping and hiding frames are configurable via the `skip_predicates`
command.

By default, frames from readonly files will be hidden, frames containing
``__tracebackhide__ = True`` will be hidden.

Frames containing ``__debuggerskip__`` will be stepped over, frames whose parent
frames value of ``__debuggerskip__`` is ``True`` will also be skipped.

    >>> def helpers_helper():
    ...     pass
    ...
    ... def helper_1():
    ...     print("don't step in me")
    ...     helpers_helpers() # will be stepped over unless breakpoint set.
    ...
    ...
    ... def helper_2():
    ...     print("in me neither")
    ...

One can define a decorator that wraps a function between the two helpers:

    >>> def pdb_skipped_decorator(function):
    ...
    ...
    ...     def wrapped_fn(*args, **kwargs):
    ...         __debuggerskip__ = True
    ...         helper_1()
    ...         __debuggerskip__ = False
    ...         result = function(*args, **kwargs)
    ...         __debuggerskip__ = True
    ...         helper_2()
    ...         # setting __debuggerskip__ to False again is not necessary
    ...         return result
    ...
    ...     return wrapped_fn

When decorating a function, ipdb will directly step into ``bar()`` by
default:

    >>> @foo_decorator
    ... def bar(x, y):
    ...     return x * y


You can toggle the behavior with

    ipdb> skip_predicates debuggerskip false

or configure it in your ``.pdbrc``



License
-------

Modified from the standard pdb.Pdb class to avoid including readline, so that
the command line completion of other programs which include this isn't
damaged.

In the future, this class will be expanded with improvements over the standard
pdb.

The original code in this file is mainly lifted out of cmd.py in Python 2.2,
with minor changes. Licensing should therefore be under the standard Python
terms.  For details on the PSF (Python Software Foundation) standard license,
see:

https://docs.python.org/2/license.html


All the changes since then are under the same license as IPython.

    )annotationsN)contextmanager)	lru_cache)get_ipython)
PyColorize)TokenStream)TYPE_CHECKING)	FrameType)Pdb)Token)InteractiveShellTzipdb> __debuggerskip__)      c                     t          d          )zException hook which handles `BdbQuit` exceptions.

    All other exceptions are processed using the `excepthook`
    parameter.
    zs`BdbQuit_excepthook` is deprecated since version 5.1. It is still around only because it is still imported by ipdb.)
ValueError)etevtb
excepthooks       U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/debugger.pyBdbQuit_excepthookr      s     }      z
(?<=\n)\s+c                8    t                               d|           S )N )RGX_EXTRA_INDENTsub)multiline_strings    r   strip_indentationr      s    $4555r   r   c                X      fd}|j         rt          |j                   |z   |_         |S )zMake new_fn have old_fn's doc string. This is particularly useful
    for the ``do_...`` commands that hook into the help system.
    Adapted from from a comp.lang.python posting
    by Duncan Booth.c                      | i |S N )argskwnew_fns     r   wrapperz%decorate_fn_with_doc.<locals>.wrapper   s    vt"r"""r   )__doc__r   )r&   old_fnadditional_textr'   s   `   r   decorate_fn_with_docr+      sD    # # # # # ~ N+FN;;oMNr   c                  h    e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   erdZdddddZ	 	 	 	 dQdRdZe	dSd            Z
e
j        dTd            Z
d Ze	d             Zd ZdU fd	Zd Zd Zerd  Zed!             Zd" Zd# Z fd$Zd% Z eeej                  xZZdUdVd'Z	 dWdXd,Zd- Z	 dYdZd0Z 	 d[d\d6Z!d]d9Z"d: Z#d; Z$d< Z%e%Z&d= Z'd> Z(e(Z)d? Z*d@ Z+dA Z,dB Z-dC Z.dD Z/dE Z0d^dGZ1e1Z2 fdHZ3dI Z4 e5dJ          dK             Z6 e5dJ          dL             Z7 fdMZ8dN Z9dO Z:e:Z;e9Z<d_dPZ= xZ>S )`r   aL  Modified Pdb class, does not load readline.

    for a standalone version that uses prompt_toolkit, see
    `IPython.terminal.debugger.TerminalPdb` and
    `IPython.terminal.debugger.set_trace()`


    This debugger can hide and skip frames that are tagged according to some predicates.
    See the `skip_predicates` commands.

    r   shellstr_theme_nameint_contextztuple[Exception, ...]_chained_exceptions_chained_exception_indexi  TF)tbhidereadonlyipython_internaldebuggerskipN   contextint | None | strc                   |d}t          |t                    rt          |          }|| _        t	          j        | |||fi | t                      | _        | j        @t          j	        d         }ddl
m} |                                | _        |t          j	        d<   i | _        | j        j        }t          |t                    sJ |                                |k    sJ t!          j        |          | _        |                     |           t(          | _        d| _        d| _        | j        | _        t2          rt5                      | _        d| _        dS dS )a>  Create a new IPython debugger.

        Parameters
        ----------
        completekey : default None
            Passed to pdb.Pdb.
        stdin : default None
            Passed to pdb.Pdb.
        stdout : default None
            Passed to pdb.Pdb.
        context : int
            Number of lines of source code context to show when
            displaying stacktrace information.
        **kwargs
            Passed to pdb.Pdb.

        Notes
        -----
        The possibilities are python version dependent, see the python
        docs for more info.
        Nr8   __main__r   )TerminalInteractiveShell)
theme_nameT)
isinstancer.   r0   r9   OldPdb__init__r   r-   sysmodules!IPython.terminal.interactiveshellr=   instancealiasescolorslowerr   Parserparserset_theme_namepromptskip_hiddenreport_skippeddefault_predicates_predicatesCHAIN_EXCEPTIONStupler2   r3   )	selfcompletekeystdinstdoutr9   kwargs	save_mainr=   r>   s	            r   rA   zPdb.__init__   sg   < ?Ggs## 	#'llG 	k5&CCFCCC !]]
:J/IRRRRRR1::<<DJ '0CK
#Z&
*c*****!!Z//// !':>>>J''' "  2 	.',wwD$,-D)))	. 	.r   returnc                    | j         S r"   )r1   rS   s    r   r9   zPdb.context1  s
    }r   value	int | strNonec                    t          |t                    st          |          }t          |t                    sJ |dk    sJ || _        d S )Nr   )r?   r0   r1   )rS   r\   s     r   r9   zPdb.context5  sO     %%% 	JJE%%%%%%zzzzr   c                    |                                 |k    sJ t          |t                    sJ || _        || j        _        d S r"   )rH   r?   r.   r/   rJ   r>   )rS   names     r   rK   zPdb.set_theme_name>  sI    zz||t####$$$$$$!%r   c                0    t           j        | j                 S r"   )r   theme_tabler/   r[   s    r   themez	Pdb.themeD  s    %d&677r   c                    t          j        dt          d           ||                                k    sJ |                                | _        |                                | j        _        dS )z;Shorthand access to the color table scheme selector method.zFset_colors is deprecated since IPython 9.0, use set_theme_name instead   )
stacklevelN)warningswarnDeprecationWarningrH   r/   rJ   r>   )rS   schemes     r   
set_colorszPdb.set_colorsI  sg    T	
 	
 	
 	

 ''''!<<>>!'r   c                    |t          j                    j        }|| _        t	                                          |          S r"   )rB   	_getframef_backinitial_framesuper	set_trace)rS   frame	__class__s     r   rr   zPdb.set_traceT  s6    =MOO*E"ww  '''r   c                P   | j         d         rL|j        j        }t          j                            |          r!t          j        |t          j                  sdS | j         d         r?|| j        t          | dd          fv rdS | 
                    |          }d|vrdS |d         S dS )zX
        Given a frame return whether it it should be hidden or not by IPython.
        r5   Tr4   rp   NF__tracebackhide__)rP   f_codeco_filenameospathisfileaccessW_OKcurframegetattr_get_frame_locals)rS   rs   fnameframe_localss       r   _hidden_predicatezPdb._hidden_predicateZ  s    
 J' 	L,E w~~e$$ RYubg-F-F tH% 	5ot(L(LMMMu11%88L",66u 344ur   c                      fd|D             }d t          |          D             r( j        d         rfdt          |          D             }|S )z
        Given an index in the stack return whether it should be skipped.

        This is used in up/down and where to skip frames.
        c                F    g | ]}                     |d                    S )r   )r   ).0srS   s     r   
<listcomp>z%Pdb.hidden_frames.<locals>.<listcomp>y  s+    ???A4))!A$//???r   c                $    g | ]\  }}|d k    |S )__ipython_bottom__r#   )r   ir   s      r   r   z%Pdb.hidden_frames.<locals>.<listcomp>z  s'    RRR$!Q=Q8Q8QA8Q8Q8Qr   r6   c                6    g | ]\  }}|d          k    r|ndS )r   Tr#   )r   r   hip_starts      r   r   z%Pdb.hidden_frames.<locals>.<listcomp>|  s-    WWW&1aAOOqqWWWr   )	enumeraterP   )rS   stackip_hider   s   `  @r   hidden_frameszPdb.hidden_frameso  s{     @??????RR)G"4"4RRR 	X();< 	XWWWWIgDVDVWWWGr   c                v   g }t          |t                    r|j        |}}|w||v rnr|                    |           |j        |j        }n|j        |j        s|j        }t          |          | j        k    r| 	                    d| j         d           n|wn|}t          t          |                    |fS )ae  
            Given a tracecack or an exception, return a tuple of chained exceptions
            and current traceback to inspect.
            This will deal with selecting the right ``__cause__`` or ``__context__``
            as well as handling cycles, and return a flattened list of exceptions we
            can jump to with do_exceptions.
            Nz
More than zQ chained exceptions found, not all exceptionswill be browsable with `exceptions`.)r?   BaseException__traceback__append	__cause____context____suppress_context__lenMAX_CHAINED_EXCEPTION_DEPTHmessagerR   reversed)rS   	tb_or_exc_exceptions	tracebackcurrents        r   _get_tb_and_exceptionszPdb._get_tb_and_exceptions  s     K)]33 &%.%<i7	)+--&&w///(4")"3+7 ' < 8 #*"5;''4+KKKC)I C C C  
 % )( &	+..//::r   c              #     K   	 || _         t          |          dz
  | _        dV  t                      | _         d| _        dS # t                      | _         d| _        w xY w)a>  
            Context manager to ensure proper cleaning of exceptions references
            When given a chained exception instead of a traceback,
            pdb may hold references to many objects which may leak memory.
            We use this context manager to make sure everything is properly cleaned
               Nr   )r2   r   r3   rR   )rS   
exceptionss     r   _hold_exceptionszPdb._hold_exceptions  sn      2+5(03J!0C- ,177(01--- ,177(01-1111s   "A Ac                :   | j         s|                     d           dS |st          | j                   D ]x\  }}|| j        k    rdnd}t	          |          }t          |          dk    r|dd         dz   }| j         |         j        dn|d	}|                     | d| d|            ydS 	 t          |          }n&# t          $ r | 	                    d
           Y dS w xY wd|cxk    rt          | j                   k     rn n}| j         |         j        | 	                    d           dS || _        | 
                    d| j         |         j                   |                     | j        | j                            dS | 	                    d           dS )aw  exceptions [number]
            List or change current exception in an exception chain.
            Without arguments, list all the current exception in the exception
            chain. Exceptions will be numbered, with the current exception indicated
            with an arrow.
            If given an integer as argument, switch to the exception at that index.
            zDid not find chained exceptions. To move between exceptions, pdb/post_mortem must be given an exception object rather than a traceback.N> P   M   z...z  -z>3zArgument must be an integerr   z;This exception does not have a traceback, cannot jump to itzNo exception with that number)r2   r   r   r3   reprr   r   r0   r   errorsetupprint_stack_entryr   curindex)rS   argixexcrL   rep	indicatornumbers           r   do_exceptionszPdb.do_exceptions  s    + 7  
  @()ABB 
@ 
@GB$&$*G$G$GSSSFs))C3xx"}}!#2#h.  3B7EM  "ZZ 
 LLF!>!>Y!>!>!>!>????
@ 
@ XXFF!   JJ<===FF >>>>T%=!>!>>>>>>/7EM

Y   4:D1JJtT%=f%E%STTT**4:dm+DEEEEEJJ>?????s   1C C$#C$c                   	 t           r|                     |          \  }}t          |t                    r|
J d            |                     |          5  t          j        | ||           d d d            d S # 1 swxY w Y   d S t          j        | ||           d S # t          $ r8 | j        	                    d| j
                                        z              Y d S w xY w)Nz$main exception must have a traceback
)rQ   r   r?   r   r   r@   interactionKeyboardInterruptrV   writer-   get_exception_only)rS   rs   r   r2   r   s        r   r   zPdb.interaction  sH   	F ;*.*E*Ei*P*P'#Ri77 R>>+Q>>>**+>?? 8 8&tUB7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 "4	:::::  	F 	F 	FKdTZ%B%B%D%DDEEEEEE	Fs<   AB  A;.B  ;A??B  A?B  B   >C"!C"c                    |                     d          rd|dd         z   }n"|                     d          rd|dd         z   }t                                          |          }|S )z<Perform useful escapes on the command before it is executed.z??zpinfo2 N?zpinfo )endswithrq   precmd)rS   linert   s     r   r   z
Pdb.precmd  sm     == 	(tCRCy(DD]]3 	(d3B3i'Dww~~d##r   c                ,    t          j        | |          S r"   )r@   do_quitrS   r   s     r   new_do_quitzPdb.new_do_quit  s    ~dC(((r   
int | Nonec                   || j         }	 d}d}t          |                     | j                  | j                  D ]f\  }}|r| j        r|dz  }|r8|| j                            t          j        d| dft          dfg          z  }d}|| 	                    |          z  }g|r6|| j                            t          j        d| dft          dfg          z  }t          || j                   d S # t          $ r Y d S w xY w)Nr   r   r   z    [... skipping  hidden frame(s)]r   file)r9   zipr   r   rM   rd   formatr   ExcNameformat_stack_entryprintrV   r   )rS   r9   skippedto_printhiddenframe_linenos         r   print_stack_tracezPdb.print_stack_trace  si   ?lG 	GH(+D,>,>tz,J,JDJ(W(W B B$ d. qLG  
 1 1 !& OW O O O #DM! ! H  GD33LAAA 	DJ-- "MKKKK    (------  	 	 	DD	s   C&C3 3
D D
-> r   tuple[FrameType, int]prompt_prefixc                    t          |                     |d          | j                   |\  }}|j        j        }| j        j                            ||d           dS )zC
        Overwrite print_stack_entry from superclass (PDB)
        r   r   r   N)r   r   rV   rw   rx   r-   hookssynchronize_with_editor)rS   r   r   rs   linenofilenames         r   r   zPdb.print_stack_entry)  s_     	d%%lB77dkJJJJ$v<+
0061EEEEEr   c                D    |t          | dd          u r| j        S |j        S )aj   "
        Accessing f_local of current frame reset the namespace, so we want to avoid
        that or the following can happen

        ipdb> foo
        "old"
        ipdb> foo = "new"
        ipdb> foo
        "new"
        ipdb> where
        ipdb> foo
        "old"

        So if frame is self.current_frame we instead return self.curframe_locals

        r~   N)r   curframe_localsf_localsrS   rs   s     r   r   zPdb._get_frame_locals5  s,    " GD*d3333''>!r   : lprefixc                @   | j         }	 t          |          }|dk    rt          d| j                   n-# t          t
          f$ r t          d| j                   Y nw xY wddl}g }|\  }}d}|                     |          }	d|	v r@|	d         }
||                    |
          dz   z  }|	                    t          |fg           |                     |j        j                  }t          j        |f}|j        j        r|j        j        }nd}g }|d	k    r>d
|	v r|                    |	d
                   }nd}t          j        |ft          j        |fg}|| j        u r:|                    t          j        | j                            d          f           n|                    t          df           |	                    |t          dft          j        t1          |          ft          dfg|t          df           |dz
  |dz  z
  }t3          j        |          }t7          |t9          |          |z
            }t;          |d          }||||z            }t=          |          D ]\  }}|dz   |z   |k    }|                     ||dz   |z   ||          \  }}}|| j        u s|r!|t          j         |ft          dft          |fg}n%|t          j        |ft          dft          j!        |fg}|	                    |           | j        "                    |          S )z;
        overwrite from super class so must -> str
        r   z"Context must be a positive integerr   Nr   
__return__r   z<lambda>r   __args__z()rf   z  ()r   arrowr   )#r9   r0   r   rV   	TypeErrorr   reprlibr   r   extendr   canonicrw   rx   
FilenameEmco_nameVNameValEmr~   r   CurrentFramerd   
make_arrowLinenor.   	linecachegetlinesminr   maxr   _Pdb__line_contentLinenoEmLiner   )rS   r   r   r9   r   ret_tokrs   r   return_value	loc_framervr   link_tokfunc	call_toksr$   startlinesr   r   
show_arrowbpnumcolored_linerlts                            r   r   zPdb.format_stack_entryK  s    ,	J'llG!||:MMMM:& 	J 	J 	J6T[IIIIII	J 	$v**511	9$$<(BGLL,,t33LNNUL12333 << 899$h/< 	<'DDD	3;;Y&&||Ij$9::+t,u{D.ABI DM!!NNE.
0E0Ea0H0HIJJJJNNE4=)))s6{{+	
  		
 		
 		
 
W\)"8,,E3u::/00E1eego-. '' 	  	 GAtQ&0J$($7$7	A 	 %8 % %!B\ %%%^S)CL
 L)	 \3'CL
 Z.	 NN3z  )))s   +5 'AAr   r   r   r   boolc                f   d}t           j        }| j                            |d          \  }}|s|}d }	||                     |          v r|                     ||          }
|
d         }	|	r=t          |	j                  }t           j        j        }|	j	        st           j        j
        }d}|r[|t          t          |                    z
  t          |          z
  }| j                            |          t          |          }n$d|t          |          z
  t          |          fz  }||f}|||fS )Nr   r.   r      z%*s)r   
BreakpointrJ   format2get_file_breaks
get_breaksr.   r   EnabledenabledDisabledr   rd   r   )rS   r   r   r   r   bp_markBreakpointTokennew_lineerrr	  bpsnumbers_widthpadr
  bp_strs                  r   __line_contentzPdb.__line_content  s7    *++D%88# 	DT))(3333//(F33CRB 	<")nnG#.6O: <"'"2"; 	F#c&kk"2"22S\\AC J11#666FDCC=3w<<7VEEC!7+T""r   firstlastc                   g }	 |dk    rt          | d          r| j        }t          ||dz             D ]}t          j        ||          }|s n| j        J || j        j        k    rQ|                     |||d          \  }}}	|                    |t          j
        |ft          dft          |	fg           nP|                     |||d          \  }}}	|                    |t          j        |ft          dft          |	fg           || _        t          | j                            |          | j        	           dS # t"          $ r Y dS w xY w)
zIThe printing (as opposed to the parsing part of a 'list'
        command.z<string>_exec_filenamer   NTr   r   Fr   )hasattrr#  ranger   getliner~   f_linenor   r   r   r   r   r   r   rd   r   rV   r   )
rS   r   r   r!  toksr   r   r	  r
  r  s
             r   print_list_lineszPdb.print_list_lines  s    *	:%%'$8H*I*I%.tax00 !% !% (6:: E}000T]333,0,?,? &$d -@ - -)B\ KK"^S1"CL"L1    -1,?,? &$e -@ - -)B\ KK"\3/"CL"L1	   %$*##D))<<<<<<  	 	 	DD	s   D;E 
EEc                $   |                                 sBt          d           | j                                        D ]\  }}t          d|d|           dS |                                                     d          }t          |          dk    r8t          dt          | j                                                              dS |\  }}|| j        vr:t          |dt          | j                                                              dS |                                d	vrt          |d
           dS |                                dv | j        |<   t          | j        
                                          st          d           dS dS )aA  
        Turn on/off individual predicates as to whether a frame should be hidden/skip.

        The global option to skip (or not) hidden frames is set with skip_hidden

        To change the value of a predicate

            skip_predicates key [true|false]

        Call without arguments to see the current values.

        To permanently change the value of an option add the corresponding
        command to your ``~/.pdbrc`` file. If you are programmatically using the
        Pdb instance you can also change the ``default_predicates`` class
        attribute.
        zcurrent predicates:z   :Nr   rf   z:Usage: skip_predicates <type> <value>, with <type> one of z not in )trueyes1nofalse0zA is invalid - use one of ('true', 'yes', '1', 'no', 'false', '0'))r,  r-  r.  KWarning, all predicates set to False, skip_hidden may not have any effects.)stripr   rP   itemssplitr   setkeysrH   anyvalues)rS   r$   pv
type_valuetype_r\   s          r   do_skip_predicateszPdb.do_skip_predicates  s   " zz|| 	'((((..00 ( (1eQQ''''FZZ\\'',,
z??akSQUQaQfQfQhQhMiMikk   F!u(((UDDc$*:*?*?*A*A&B&BDDEEEF;;== HHH]]]   F"'++--3G"G4#**,,-- 	]    	 	r   c                   |                                 st          d| j         d           n_|                                                                 dv rd| _        n/|                                                                 dv rd| _        t	          | j                                                  st          d           dS dS )	zk
        Change whether or not we should skip frames with the
        __tracebackhide__ attribute.
        zskip_hidden = z/, use 'yes','no', 'true', or 'false' to change.)r,  r-  T)r0  r/  Fr2  N)r3  r   rM   rH   r8  rP   r9  r   s     r   do_skip_hiddenzPdb.do_skip_hidden0  s    
 yy{{ 	%b!1bbb    YY[[  O33#DYY[[  O33$D4#**,,-- 	]    	 	r   c                   d| _         d}|r|dk    r	 t          |i i           }t          |          t          d          k    r/|\  }}t          |          }t          |          }||k     r||z   }n t	          dt          |          dz
            }nj#  t          dt          |          | j                   Y dS xY w| j        |dk    r'| j	        J t	          d| j	        j
        dz
            }n
| j        dz   }||d	z   }| j	        J |                     | j	        j        j        ||           |}| j	        j        j        }| j        j                            ||d
           dS )z0Print lines of code from the current stack framelistN.r#   r   r8   z*** Error in argument:r   
   r   )lastcmdevaltyper0   r   r   r   rV   r   r~   r'  r)  rw   rx   r-   r   r   )rS   r   r!  xr   r   r   s          r   do_listzPdb.do_listB  sz    	$3#::b"%%77d2hh&&"#KE4JJEt99De||$t|3q66A:..E.S		LLLL[ C3JJ=,,,4=1A566EEK!OE<2:D}(((dm2>tLLL='3
0061EEEEEs   B B &B=c                
   t          j        |          \  }}t          j        |          r |j        |                     |          u r|dfS t          j        |          r|dfS t          j        ||d                    |dz   fS )Nr   )inspect
findsourceisframe	f_globalsr   ismodulegetblock)rS   objr  r   s       r   getsourcelineszPdb.getsourcelinese  s    *3//v?3 	CMT5K5KC5P5P$P$P!8Oc"" 	!8Ofgg//!;;r   c                H   d| _         	 |                     | j                  \  }}n:# t          $ r-}|                     t          |                     Y d}~dS d}~ww xY w|t          |          z   }| j        J |                     | j        j        j	        ||           dS )zfPrint lines of code from the current stack frame.

        Shows more lines than 'list' does.
        longlistN)
rE  rR  r~   OSErrorr   r.   r   r)  rw   rx   )rS   r   r  r   r  r!  s         r   do_longlistzPdb.do_longlistn  s    
 "	 //>>ME66 	 	 	JJs3xx   FFFFF	 E

"}(((dm2>MMMMMs   ' 
A"AAc                   t          j                    }t          j        d           | j        J | j        j        }| j        }|                     | j        | j        | j	                  }| j
        |_
        d| j                                        z  |_        |                     d           t          j        |j        |||f           |                     d           t          j        |           |j        | _        dS )zdebug code
        Enter a recursive debugger that steps through the code
        argument (which is an arbitrary expression or statement to be
        executed in the current environment).
        N)rT   rU   rV   z(%s) zENTERING RECURSIVE DEBUGGERzLEAVING RECURSIVE DEBUGGER)rB   gettracesettracer~   rN  r   rt   rT   rU   rV   use_rawinputrL   r3  r   call_tracingrunrE  )rS   r   trace_functionglobalslocalsr:  s         r   do_debugzPdb.do_debug  s     T}(((-)%NN(
4;  
 
 *T[..0002333gv 67771222^$$$yr   c                    | j         J d| j        fd| j         j        fg} | j                            d          ||           dS )zZPrint the call signature for any callable object.

        The debugger interface to %pdefNLocalsGlobalspdef
namespacesr~   r   rN  r-   find_line_magicrS   r   rf  s      r   do_pdefzPdb.do_pdef  ^     }(((t+,/0

 	+
""6**3:FFFFFFr   c                    | j         J d| j        fd| j         j        fg} | j                            d          ||           dS )zLPrint the docstring for an object.

        The debugger interface to %pdoc.Nrb  rc  pdocre  rg  ri  s      r   do_pdoczPdb.do_pdoc  rk  r   c                    | j         J d| j        fd| j         j        fg} | j                            d          ||           dS )zuPrint (or run through pager) the file where an object is defined.

        The debugger interface to %pfile.
        Nrb  rc  pfilere  rg  ri  s      r   do_pfilezPdb.do_pfile  s^    
 }(((t+,/0

 	,
""7++CJGGGGGGr   c                    | j         J d| j        fd| j         j        fg} | j                            d          ||           dS )zdProvide detailed information about an object.

        The debugger interface to %pinfo, i.e., obj?.Nrb  rc  pinfore  rg  ri  s      r   do_pinfozPdb.do_pinfo  s^     }(((t+,/0

 	,
""7++CJGGGGGGr   c                    | j         J d| j        fd| j         j        fg} | j                            d          ||           dS )zlProvide extra detailed information about an object.

        The debugger interface to %pinfo2, i.e., obj??.Nrb  rc  pinfo2re  rg  ri  s      r   	do_pinfo2zPdb.do_pinfo2  s^     }(((t+,/0

 	-
""8,,SZHHHHHHr   c                    | j         J d| j        fd| j         j        fg} | j                            d          ||           dS )z;Print (or run through pager) the source code for an object.Nrb  rc  psourcere  rg  ri  s      r   
do_psourcezPdb.do_psource  s\    }(((t+,/0

 	.
""9--cjIIIIIIr   r   c                    |rb	 t          |          }n:# t          $ r-}|                     t          |                     Y d}~dS d}~ww xY w|                     |           dS |                                  dS )a4  w(here)
        Print a stack trace, with the most recent frame at the bottom.
        An arrow indicates the "current frame", which determines the
        context of most commands. 'bt' is an alias for this command.

        Take a number as argument as an (optional) number of context line to
        printN)r0   r   r   r.   r   )rS   r   r9   r  s       r   do_wherezPdb.do_where  s      	%c((   

3s88$$$ ""7+++++""$$$$$s    
A"AAc                   t                                          |          }|r|S | j        d         rPt          |j        j        v rdS |j        r4|                     |j                                      t                    rdS dS )a#  
        _stop_in_decorator_internals is overly restrictive, as we may still want
        to trace function calls, so we need to also update break_anywhere so
        that is we don't `stop_here`, because of debugger skip, we may still
        stop at any point inside the function

        r7   TF)	rq   break_anywhererP   DEBUGGERSKIPrw   co_varnamesro   r   get)rS   rs   suprt   s      r   r~  zPdb.break_anywhere  s     gg$$U++ 	JN+ 	u|777t|  6 6u| D D H H V V tur   c                J    | j         d         sdS |                     |          S )z]
        Utility to tell us whether we are in a decorator internal and should stop.

        r7   F)rP   _cachable_skipr   s     r   )_is_in_decorator_internal_and_should_skipz-Pdb._is_in_decorator_internal_and_should_skip  s-     / 	5""5)))r   i   c                    t          |dd          rG|j        }|                     |                              t                    rdS t          |dd          GdS )z
        Cache looking up for DEBUGGERSKIP on parent frame.

        This should speedup walking through deep frame when one of the highest
        one does have a debugger skip.

        This is likely to introduce fake positive though.
        ro   NT)r   ro   r   r  r  r   s     r   %_cached_one_parent_frame_debuggerskipz)Pdb._cached_one_parent_frame_debuggerskip  se     eXt,, 	LE%%e,,00>> t eXt,, 	 tr   c                ^    t           |j        j        v rdS |                     |          rdS dS )NTF)r  rw   r  r  r   s     r   r  zPdb._cachable_skip  s;     5<3334 55e<< 	4ur   c                >   |                      |          du rdS d}| j        r|                     |          }|rC| j        r<t	          | j                            t          j        dft          dfg                     t                      
                    |          S )NTFz#    [... skipped 1 hidden frame(s)]r   )r  rM   r   rN   r   rd   r   r   r   rq   	stop_here)rS   rs   r   rt   s      r   r  zPdb.stop_here$  s    99%@@DHH5 	3++E22F 	" J%% !& E #DM 
 
 
 ww  '''r   c                p   | j         dk    r|                     d           dS 	 t          |pd          }n)# t          $ r |                     d|z             Y dS w xY wd}|dk     rd}nsd}|                     | j                  }t          | j         dz
  dd          D ]$}||         r| j        r|dz  }|dz  }||k    r n%|                     d           dS |}|                     |           |rBt          | j
                            t          j        d| d	ft          d
fg                     dS dS )zu(p) [count]
        Move the current frame count (default one) levels up in the
        stack trace (to an older frame).

        Will skip hidden frames.
        r   zOldest frameNr   Invalid frame count (%s)r   zGall frames above hidden, use `skip_hidden False` to get get into those.    [... skipped r   r   )r   r   r0   r   r   r   r%  rM   _select_framer   rd   r   r   r   )rS   r   countr   	_newframecounterr   r   s           r   do_upz	Pdb.do_up:  s    =AJJ~&&&F	qMMEE 	 	 	JJ1C7888FF	 199IIG ..tz::M4=1,b"55   # (8 qLG1e##E $ 

]   I9%%% 	
!! "MJJJJ  
 
 
 
 
	 	s   6 "AAc                   | j         dz   t          | j                  k    r|                     d           dS 	 t	          |pd          }n)# t
          $ r |                     d|z             Y dS w xY w|dk     rt          | j                  dz
  }nd}d}|                     | j                  }t          | j         dz   t          | j                            D ]$}||         r| j        r|dz  }|dz  }||k    r n%|                     d           dS |r@t          | j
                            t          j        d| dft          d	fg                     |}|                     |           dS )
zd(own) [count]
        Move the current frame count (default one) levels down in the
        stack trace (to a newer frame).

        Will skip hidden frames.
        r   zNewest frameNr  r   zGall frames below hidden, use `skip_hidden False` to get get into those.r  r   r   )r   r   r   r   r0   r   r   r%  rM   r   rd   r   r   r   r  )rS   r   r  r  r  r   r   r   s           r   do_downzPdb.do_downn  s    =1DJ//JJ~&&&F	qMMEE 	 	 	JJ1C7888FF	 199DJ!+IIGG ..tz::M4=1,c$*oo>>   # (8 qLG1e##E $ 

]    J%% !& NG N N N #DM 
 
 
 I9%%%%%s   A "A10A1c                    	 t          |          }|dk    rt                      || _        dS # t          $ r" |                     d| j         d           Y dS w xY w)zcontext number_of_lines
        Set the number of lines of source code to show when displaying
        stacktrace information.
        r   zJThe 'context' command requires a positive integer argument (current value z).N)r0   r   r9   r   )rS   r9   new_contexts      r   
do_contextzPdb.do_context  s    
	g,,Ka ll"&DLLL 	 	 	JJm]a]immm     	s   *. (AA)NNNr8   )r9   r:   )rY   r0   )r\   r]   rY   r^   r"   )r9   r   )r   )r   r   r   r.   rY   r^   )r   )r   r   r   r.   rY   r.   )F)r   r.   r   r0   r   r.   r   r  )r   r.   r   r0   r!  r0   rY   r^   )r   r.   )r9   r.   )?__name__
__module____qualname__r(   __annotations__rQ   r   rO   rA   propertyr9   setterrK   rd   rl   rr   r   r   r   r   r   r   r   r   r   r+   r@   r   do_qr   r   r   r   r   r)  r>  r@  rI  do_lrR  rV  do_llr`  rj  rn  rq  rt  rw  rz  r|  do_wr~  r  r   r  r  r  r  r  do_ddo_ur  __classcell__)rt   s   @r   r   r      sw        
 
 MMM....!!!! *&)#  	  $%I. I. I. I. I.V    X ^   ^& & & 8 8 X8	0 	0 	0( ( ( ( ( (  *     c@!	; !	; !	;F 
	2 	2 
	2",	@ ,	@ ,	@\F F F
 
 
 
 
) ) ) *)+v~FFFD7# # # # #L IP
F 
F 
F 
F 
F" " "2 h* h* h* h* h*V DI# # # # #<. . . .`+ + +Z  $F F FB D< < <N N N E! ! !,	G 	G 	G	G 	G 	G
H 
H 
H	H 	H 	H	I 	I 	IJ J J% % % %$ D    &	* 	* 	* Yt__  _ Yt__	 	 _	( ( ( ( (,2 2 2h0& 0& 0&d DD       r   r   c                       e Zd ZdZddZd ZdS )InterruptiblePdbzJVersion of debugger where KeyboardInterrupt exits the debugger altogether.Nc                    	 t          j        | |          S # t          $ r: d | _        |                     d           t          j        d           d| _         w xY w)z>Wrap cmdloop() such that KeyboardInterrupt stops the debugger.)introc                    dS )NFr#   )rs   s    r   <lambda>z*InterruptiblePdb.cmdloop.<locals>.<lambda>  s    5 r   r   NF)r@   cmdloopr   r  r   rB   rY  quitting)rS   r  s     r   r  zInterruptiblePdb.cmdloop  sm    	>$e4444  	 	 	00DNLLL!DM	s
    AAc                    	 	 d| _         |                                  d| _         d S # t          $ r |                     d            w xY w)NTFz--KeyboardInterrupt--)allow_kbdintr  r   r   r[   s    r   _cmdloopzInterruptiblePdb._cmdloop  sa    
		 %)!$)!$   4555s	   "' !Ar"   )r  r  r  r(   r  r  r#   r   r   r  r    s=        TT	 	 	 	    r   r  c                    t                      }||                    |           |                    | pt          j                    j                   dS )zm
    Start debugging from `frame`.

    If frame is not specified, debugging starts from caller's frame.
    N)r   r   rr   rB   rn   ro   )rs   headerpdbs      r   rr   rr     sK     %%CFMM%13=??122222r   r"   )r   )NN)*r(   
__future__r   rK  r   ry   rerB   rh   
contextlibr   	functoolsr   IPythonr   IPython.utilsr   IPython.utils.PyColorizer   typingr	   typesr
   r  r   r@   pygments.tokenr   IPython.core.interactiveshellr   __skip_doctest__rL   r  version_inforQ   r   compiler   r   r+   r  rr   r#   r   r   <module>r     s  o ov # " " " " "      				 				 



  % % % % % %             $ $ $ $ $ $ 0 0 0 0 0 0                                     ?>>>>>>  	 "
 #g-     2:m,, 6 6 6   h h h h h& h h hV    s   8	3 	3 	3 	3 	3 	3r   