
    fc                         d 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
mZ ddlmZ dZdZdd	lmZ d
Zd Zdd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y)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__`

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 who's parent
frames value of ``__debuggerskip__`` is ``True`` will 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.

    N)get_ipython)
PyColorize)	coloransi	py3compat)exception_colorsTzipdb> )Pdb__debuggerskip__c                 0    | dk\  rd| dz
  z  dz   S | dk(  ryy)z<generate the leading arrow in front of traceback or debugger   ->    >  )pads    P/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/core/debugger.py
make_arrowr      s)    
axCE{T!!	    c                     t        d      )zException hook which handles `BdbQuit` exceptions.

    All other exceptions are processed using the `excepthook`
    parameter.
    z4`BdbQuit_excepthook` is deprecated since version 5.1)
ValueError)etevtb
excepthooks       r   BdbQuit_excepthookr      s     > r   c                 &    t        dt        d      )Nz<`BdbQuit_IPython_excepthook` is deprecated since version 5.1r   )
stacklevel)r   DeprecationWarning)selfr   r   r   	tb_offsets        r   BdbQuit_IPython_excepthookr"      s    
Fq* *r   z
(?<=\n)\s+c                 .    t         j                  d|       S )Nr   )RGX_EXTRA_INDENTsub)multiline_strings    r   strip_indentationr'      s    $455r   c                 d      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 Nr   )argskwnew_fns     r   wrapperz%decorate_fn_with_doc.<locals>.wrapper   s    t"r""r   )__doc__r'   )r-   old_fnadditional_textr.   s   `   r   decorate_fn_with_docr2      s)    
#~~+FNN;oMNr   c                   V    e Zd ZdZdddddZd(dZd Zd) fd	Zd Zd	 Z	d
 Z
 fdZd Zd Z eeej                         xZZd Zd)dZ	 	 d*dZd Zd+dZd,dZd Zd Zd Zd ZeZd Zd ZeZd Z d Z!d Z"d Z#d Z$d Z%d  Z&d! Z'e'Z( fd"Z)d# Z* fd$Z+d% Z,d& Z-e-Z.e,Z/d' Z0 xZ1S )-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.

    TF)tbhidereadonlyipython_internaldebuggerskipc                    	 t        |      | _        | j                  dk  rt        d      	 t	        j
                  | |||fi | t               | _        | j                  At        j                  d   }ddl
m} |j                         | _        |t        j                  d<   | j                  j                  }	i | _        t               | _        t"        j$                  }
| j                   }|
j&                  |d   j                  _        |
j&                  |d   j                  _        |
j&                  |d   j                  _        |
j.                  |d   j                  _        |
j0                  |d   j                  _        |
j2                  |d   j                  _        |
j4                  |d   j                  _        |
j0                  |d   j                  _        |
j2                  |d   j                  _        |
j4                  |d	   j                  _        |
j0                  |d	   j                  _        |
j2                  |d	   j                  _        t7        j8                  |	
      | _        | j=                  |	       t(        | _        d| _        d| _         | jB                  | _"        y# t        t        f$ r}t        d      |d}~ww xY w)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.
        r   "Context must be a positive integerN__main__)TerminalInteractiveShellNoColorLinuxLightBGNeutral)styleT)#intcontextr   	TypeErrorOldPdb__init__r   shellsysmodules!IPython.terminal.interactiveshellr;   instancecolorsaliasesr   color_scheme_tabler   
TermColorsr<   promptbreakpoint_enabledbreakpoint_disabledGreenLightRedRedBluer   Parserparser
set_colorsskip_hiddenreport_skippeddefault_predicates_predicates)r    completekeystdinstdoutrB   kwargse	save_mainr;   color_schemeCcsts               r   rE   zPdb.__init__   sG   0	Nw<DL||q  !EFF ! 	k5&CFC !]
::J/I)1::<DJ '0CKK
# zz(( #3"4   %%'(yyI$3499I045III1%&WWG"12G.23%%G/'(vvI$34::I045EEI1'(vvI$34::I045EEI1 !''l;% "  22w :& 	N !EFAM	Ns   *J) )K	8KK	c                 \    | j                   j                  |       || j                  _        y)z;Shorthand access to the color table scheme selector method.N)rM   set_active_schemerW   r@   )r    schemes     r   rX   zPdb.set_colors  s"    11&9"r   c                 p    |t        j                         j                  }|| _        t        |   |      S r*   )rG   	_getframef_backinitial_framesuper	set_trace)r    frame	__class__s     r   rn   zPdb.set_trace"  s1    =MMO**E"w ''r   c                 b   | j                   d   rZ|j                  j                  }t        j                  j                  |      r%t        j                  |t        j                        sy| j                   d   r7|| j                  t        | dd      fv ry| j                  |      }d|vry|d   S y)zX
        Given a frame return whether it it should be hidden or not by IPython.
        r5   Tr4   rl   NF__tracebackhide__)r\   f_codeco_filenameospathisfileaccessW_OKcurframegetattr_get_frame_locals)r    ro   fnameframe_localss       r   _hidden_predicatezPdb._hidden_predicate(  s    
 J'LL,,E ww~~e$RYYubgg-FH%ot(LMM11%8L",6 344r   c                     |D cg c]  }| j                  |d          }}t        |      D cg c]  \  }}|dk(  s| }}}|r6| j                  d   r't        |      D cg c]  \  }}||d   kD  r|nd }}}|S c c}w c c}}w c c}}w )z
        Given an index in the stack return whether it should be skipped.

        This is used in up/down and where to skip frames.
        r   __ipython_bottom__r6   T)r   	enumerater\   )r    stacksip_hideiip_starths          r   hidden_frameszPdb.hidden_frames=  s     :??A4))!A$/??"+G"4R$!Q=Q8QARR(();<DMgDVW&1aAOq5WGW	 @RWs   A?BB$B
c                     	 t        j                  | ||       y # t        $ r9 | j                  j	                  d| j
                  j                         z          Y y w xY w)N
)rD   interactionKeyboardInterruptr_   writerF   get_exception_only)r    ro   	tracebacks      r   r   zPdb.interactionM  sO    	FtUI6  	FKKdTZZ%B%B%DDE	Fs    ?AAc                     |j                  d      r	d|dd z   }n|j                  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 )endswithrm   precmd)r    linerp   s     r   r   z
Pdb.precmdS  sP     ==tCRy(D]]3d3Bi'Dw~d#r   c                 0    t        j                  | |       y r*   )rD   do_framer    args     r   new_do_framezPdb.new_do_frame_  s    c"r   c                     t        | d      r%| j                  | j                  j                  _        t        j                  | |      S )Nold_all_completions)hasattrr   rF   	Completerall_completionsrD   do_quitr   s     r   new_do_quitzPdb.new_do_quitb  s6    4./373K3KDJJ  0~~dC((r   c                 F    | j                  d       | j                  |      S )z\Restart command. In the context of ipython this is exactly the same
        thing as 'quit'.z6Restart doesn't make sense here. Using 'quit' instead.)msgr   r   s     r   new_do_restartzPdb.new_do_restartk  s      	IJ||C  r   c           	      J   | j                   j                  }|j                  }|| j                  }	 t	        |      }|dk  rt        d      	 	 d}t        | j                  | j                        | j                        D ]N  \  }}|r| j                  r|dz  }|r t        |j                   d| d| d       d}| j                  ||       P |rt        |j                   d| d| d       y y # t        t
        f$ r}t        d      |d }~ww xY w# t        $ r Y y w xY w)Nr   r9   r   z    [... skipping  hidden frame(s)]r   )rB   )rM   active_colorsNormalrB   rA   r   rC   zipr   r   rY   printexcNameprint_stack_entryr   )r    rB   ColorsColorsNormalra   skippedhiddenframe_linenos           r   print_stack_tracezPdb.print_stack_traceq  sS   ((66}}?llG	N'lG!| !EFF 	G(+D,>,>tzz,JDJJ(W 	F$d..qLG!>>**<WIEVWcVddfg  G&&|W&E	F ~~&&8	ARS_R``bc  :& 	N !EFAM	N$ ! 		s*   C3 B"D 3DDD	D"!D"c                 t   || j                   }	 t        |      }|dk  rt        d      	 t	        | j                  |d|      | j                         |\  }}|j                  j                  }| j                  j                  j                  ||d       y # t        t        f$ r}t        d      |d }~ww xY w)Nr   r9   r   file)rB   rA   r   rC   r   format_stack_entryr_   rs   rt   rF   hookssynchronize_with_editor)r    r   prompt_prefixrB   ra   ro   linenofilenames           r   r   zPdb.print_stack_entry  s    ?llG	N'lG!| !EFF  	d%%lB@t{{S %v<<++

0061E :& 	N !EFAM	Ns   B B7&B22B7c                 N    || j                   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

        )rz   curframe_localsf_locals)r    ro   s     r   r|   zPdb._get_frame_locals  s&    " DMM!'''>>!r   c           
         || j                   }	 t        |      }|dk  rt        d| j                         dd l}g }| j                  j                  }|j                  }|j                  d|}|j                  d|j                  d|}	d|j                  d|d}
d|j                  d|j                  d|}|\  }}d}| j!                  |      }d|v r|d   }||j#                  |      dz   z  }|j%                  |       | j'                  |j(                  j*                        }|t-        j.                  |      z  }|j(                  j0                  r|j(                  j0                  }nd	}d}|d
k7  r"d|v r|j#                  |d         }nd}|	||fz  }|| j2                  u r|j%                  d       n|j%                  d       |j%                  |d|d|d       |dz
  |dz  z
  }t5        j6                  |      }t9        |t;        |      |z
        }t=        |d      }||||z    }t?        |      D ]U  \  }}|dz   |z   |k(  }|| j2                  u xs |xr |xs |
}|j%                  | jA                  |||dz   |z   ||             W djC                  |      S # t        t
        f$ r t        d| j                         Y w xY w)Nr   r9   r   %s%s r   
__return__r   z<lambda>r   __args__z()r   z  ()r   r   arrow)"rB   rA   r   r_   rC   r   reprlibrM   r   r   
filenameEmvNamevalEmr   linenoEmr   r|   reprappendcanonicrs   rt   r   cast_unicodeco_namerz   	linecachegetlinesminlenmaxr   _Pdb__format_linejoin)r    r   lprefixrB   r   retr   r   tpl_linktpl_calltpl_linetpl_line_emro   r   return_value	loc_framervr   linkfunccallr+   startlinesr   r   
show_arrowlinetpls                               r   r   zPdb.format_stack_entry  s   ?llG	N'lG!|:M 	((66}} & 1 1<@%+\\6<<N'-}}lC,2OOV[[,W$v**51	9$<(BGLL,t33L

<  << 8 89)00::<<<<''DD3;Y&||Ij$9:tTl*D DMM!JJtJJt

467
WaZ'""8,E3u:/0E1eego. ' 	GAtQ&0J-;LXPXGJJ""Xuqy1}d* # 	 wws| :& 	N:MM	Ns   'J) )&KKc                    d}d}| j                   j                  |d      \  }}	|	s|}d }
|| j                  |      v r| j                  ||      }|d   }
|
rO| j                  j
                  }t        |
j                        }|j                  }|
j                  s|j                  }d}|r<|t        t        |            z
  t        |      z
  }t        |      t        |      }nd|t        |      z
  t        |      fz  }|||z   ||fz  S )Nr   strr      z%*s)rW   format2get_file_breaks
get_breaksrM   r   r   numberrP   enabledrQ   r   r   )r    r   r   r   r   r   bp_markbp_mark_colornew_lineerrbpbpsr   numbers_widthr   nums                   r   __format_linezPdb.__format_line  s   ++D%8#DT))(33//(F3CRB,,::F"))nG"55M:: & : :#c&k"22S\AC&sOS[9C=3w<7VEEC=72C>>>r   c                 n   	 | j                   j                  }|j                  }d|j                  d|d}d|j                  d|j
                  d|}g }|dk(  rt        | d      r| j                  }t        ||dz         D ]z  }	t        j                  ||	      }
|
s n`|	| j                  j                  k(  r| j                  |||	|
d      }
n| j                  |||	|
d      }
|j                  |
       |	| _        | t        d	j!                  |      | j"                  
       y# t$        $ r Y yw xY w)zIThe printing (as opposed to the parsing part of a 'list'
        command.r   r   z<string>_exec_filenamer   Tr   Fr   r   N)rM   r   r   r   r   r   r   r   ranger   getlinerz   f_linenor   r   r   r   r_   r   )r    r   firstlastr   r   r   r   srcr   r   s              r   print_list_lineszPdb.print_list_lines  s*   	,,::F!==L+1==,GH06l[KC:%'$8H*I..tAv. % ((6:T]]333--#Xvt4 . D  -- (FD . D 

4 $%" "''#,T[[1  		s   D%D( (	D43D4c                    |j                         s<t        d       | j                  j                         D ]  \  }}t        d|d|        y|j                         j	                  d      }t        |      dk7  r0t        dt        | j                  j                                       y|\  }}|| j                  vr2t        |dt        | j                  j                                       y|j                         d	vrt        |d
       y|j                         dv | j                  |<   t        | j                  j                               st        d       yy)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   :N r   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   r\   itemssplitr   setkeysloweranyvalues)r    r+   pv
type_valuetype_values          r   do_skip_predicateszPdb.do_skip_predicates?  sD   " zz|'(((..0 (1eQQ'(ZZ\'',
z?aLSQUQaQaQfQfQhMiLjk !u(((UIXc$*:*:*?*?*A&B%CDE;;= HH)\] "'++-3G"G4##**,-] .r   c                 T   |j                         st        d| j                   d       nO|j                         j                         dv rd| _        n'|j                         j                         dv rd| _        t	        | j
                  j                               st        d       yy)	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)r  r  Fr  N)r  r   rY   r  r  r\   r  r   s     r   do_skip_hiddenzPdb.do_skip_hiddenl  s    
 yy{ !1!1 22ab YY[ O3#DYY[ O3$D4##**,-] .r   c                    d| _         d}|rd	 t        |i i       }t        |      t        d      k(  r&|\  }}t        |      }t        |      }||k  r||z   }nt	        dt        |      dz
        }n?| j                  $t	        d| j                  j                  dz
        }n| j                  dz   }||dz   }| j                  | j                  j                  j                  ||       |}| j                  j                  j                  }| j                  j                  j!                  ||d	       y#  t        dt        |      | j                         Y yxY w)
z9Print lines of code from the current stack frame
        listNr   r      z*** Error in argument:r   
   r   )lastcmdevaltyperA   r   r   r   r_   r   rz   r   r  rs   rt   rF   r   r   )r    r   r  xr  r   r   s          r   do_listzPdb.do_list~  s1    b"%7d2h&"#KE4JEt9De|$t|3q6A:.E [[ 4==11A56EKK!OE<2:Ddmm22>>tL ==''33

0061E.S	Ls   A"D1 1#Ec                 
   t        j                  |      \  }}t        j                  |      r!|j                  | 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)r    objr   r   s       r   getsourcelineszPdb.getsourcelines  sx    **3/v??3CMMT5K5KC5P$P!8Oc"!8Ofg/99r   c                    d| _         	 | j                  | j                        \  }}|t        |      z   }| j                  | j                  j                  j                  ||       y# t        $ r}| j	                  |       Y d}~yd}~ww xY w)zfPrint lines of code from the current stack frame.

        Shows more lines than 'list' does.
        longlistN)	r#  r0  rz   OSErrorerrorr   r  rs   rt   )r    r   r   r   r   r  s         r   do_longlistzPdb.do_longlist  sz    
 "	 //>ME6 E
"dmm22>>M	  	JJsO	s   A' '	B0BBc                 :   t        j                         }t        j                  d       | j                  j                  }| j
                  }| j                  | j                  | j                  | j                        }| j                  |_
        d| j                  j                         z  |_        | j                  d       t        j                  |j                  |||f       | j                  d       t        j                  |       |j                   | _        y)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)r]   r^   r_   z(%s) zENTERING RECURSIVE DEBUGGERzLEAVING RECURSIVE DEBUGGER)rG   gettracesettracerz   r,  r   rp   r]   r^   r_   use_rawinputrO   r  messagecall_tracingrunr#  )r    r   trace_functionglobalslocalsr  s         r   do_debugzPdb.do_debug  s     T--))%%NNt'7'7!%DKK  A**T[[..0023gv 6712^$yyr   c                     d| j                   fd| j                  j                  fg} | j                  j	                  d      ||       y)zZPrint the call signature for any callable object.

        The debugger interface to %pdefLocalsGlobalspdef
namespacesNr   rz   r,  rF   find_line_magicr    r   rF  s      r   do_pdefzPdb.do_pdef  H    
 t++,//0

 	+

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

        The debugger interface to %pdoc.rB  rC  pdocrE  NrG  rI  s      r   do_pdoczPdb.do_pdoc  rK  r   c                     d| j                   fd| j                  j                  fg} | j                  j	                  d      ||       y)zuPrint (or run through pager) the file where an object is defined.

        The debugger interface to %pfile.
        rB  rC  pfilerE  NrG  rI  s      r   do_pfilezPdb.do_pfile  sH     t++,//0

 	,

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

        The debugger interface to %pinfo, i.e., obj?.rB  rC  pinforE  NrG  rI  s      r   do_pinfozPdb.do_pinfo  sH    
 t++,//0

 	,

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

        The debugger interface to %pinfo2, i.e., obj??.rB  rC  pinfo2rE  NrG  rI  s      r   	do_pinfo2zPdb.do_pinfo2  sH    
 t++,//0

 	-

""8,SZHr   c                     d| j                   fd| j                  j                  fg} | j                  j	                  d      ||       y)z;Print (or run through pager) the source code for an object.rB  rC  psourcerE  NrG  rI  s      r   
do_psourcezPdb.do_psource  sH     t++,//0

 	.

""9-cjIr   c                     |r	 t        |      }| j                  |       y| j                          y# t        $ r}| j                  |       Y d}~yd}~ww xY w)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)rA   r   r4  r   )r    r   rB   r   s       r   do_wherezPdb.do_where	  sQ     c( ""7+""$  

3s   2 	AAAc                     t         |   |      }|r|S | j                  d   rXt        |j                  j
                  v ry|j                  r/| j                  |j                        j                  t              ryy)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)	rm   break_anywherer\   DEBUGGERSKIPrs   co_varnamesrk   r|   get)r    ro   suprp   s      r   r^  zPdb.break_anywhere  sh     g$U+JN+u||777|| 6 6u|| D H H Vr   c                     | j                   d   syt        |j                  j                  v ry|}t	        |dd      r?|j
                  }| j                  |      j                  t              ryt	        |dd      r?y)z]
        Utility to tell us whether we are in a decorator internal and should stop.

        r7   FTrk   N)r\   r_  rs   r`  r{   rk   r|   ra  )r    ro   cframes      r   )_is_in_decorator_internal_and_should_skipz-Pdb._is_in_decorator_internal_and_should_skip0  sw     / 5<<333 fh-]]F%%f-11,? fh-
 r   c                    | j                  |      du ryd}| j                  r| j                  |      }|rI| j                  r=| j                  j
                  }|j                  }t        |j                   d| d       t        | )  |      S )NTFz     [... skipped 1 hidden frame]r   )re  rY   r   rZ   rM   r   r   r   r   rm   	stop_here)r    ro   r   r   r   rp   s        r   rg  zPdb.stop_hereH  s    99%@DH++E2F""00>>%}}~~&&F|nTVW w ''r   c                 N   | j                   dk(  r| j                  d       y	 t        |xs d      }d}|dk  rd}nd}| j	                  | j
                        }t        | j                   dz
  dd      D ]%  }||   r| j                  r|dz  }|dz  }||k\  s% n | j                  d       y| j                  j                  }|j                  }	|}| j                  |       |rt        j                   d| d		 d
       yy# t        $ r | j                  d|z         Y yw xY w)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   )curindexr4  rA   r   r   r   r   rY   rM   r   r   _select_framer   r   )
r    r   countr   	_newframecounterr   r   r   r   s
             r   do_upz	Pdb.do_upX  sE    ==AJJ~&	qME 19IG ..tzz:M4==1,b"5  #(8(8qLG1e# 

] ,,::F!==LI9%>>""3G9<Ml^[]^ 7  	JJ1C78	s   D D$#D$c                    | j                   dz   t        | j                        k(  r| j                  d       y	 t	        |xs d      }|dk  rt        | j                        dz
  }nd}d}| j                  | j                        }t        | j                   dz   t        | j                              D ]%  }||   r| j                  r|dz  }|dz  }||k\  s% n | j                  d       y| j                  j                  }|j                  }	|rt        |j                   d| d|	 d	       |}| j                  |       y# t
        $ r | j                  d|z         Y yw xY w)
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 frameNri  r   zGall frames below hidden, use `skip_hidden False` to get get into those.rj  r   r   )rk  r   r   r4  rA   r   r   r   rY   rM   r   r   r   r   rl  )
r    r   rm  rn  ro  r   r   r   r   r   s
             r   do_downzPdb.do_down  sd    ==1DJJ/JJ~&	qME 19DJJ!+IGG ..tzz:M4==1,c$**o>  #(8(8qLG1e# 

] ,,::F!==L~~&&7y@QR^Q__ab I9%=  	JJ1C78	s   E E! E!c                     	 t        |      }|dk  r
t               || _        y# t        $ r | j                  d       Y yw xY w)zcontext number_of_lines
        Set the number of lines of source code to show when displaying
        stacktrace information.
        r   z;The 'context' command requires a positive integer argument.N)rA   r   rB   r4  )r    rB   new_contexts      r   
do_contextzPdb.do_context  sF    
	Vg,Ka l"&DL 	VJJTU	Vs   !$ A A)NNNr!  r*   )z
-> N)z: N)F)2__name__
__module____qualname__r/   r[   rE   rX   rn   r   r   r   r   r   r   r2   rD   r   do_qr   r   r   r|   r   r   r  r  r  r'  do_lr0  r5  do_llr@  rJ  rN  rQ  rT  rW  rZ  r\  do_wr^  re  rg  rp  rr  do_ddo_uru  __classcell__)rp   s   @r   r   r      s"   
  	W3t#
(* F
#) *+v~~FFD7!< =D"&F$",FP?< D+Z$FD D:N E!(GG	HHIJ%$ D&0( ,\*&X DDVr   r   c                       e Zd ZdZddZd Zy)InterruptiblePdbzJVersion of debugger where KeyboardInterrupt exits the debugger altogether.Nc                     	 t        j                  | |      S # t        $ r7 d | _        | j	                  d       t        j                  d       d| _         w xY w)z>Wrap cmdloop() such that KeyboardInterrupt stops the debugger.)introc                      y)NFr   ro   s    r   <lambda>z*InterruptiblePdb.cmdloop.<locals>.<lambda>  s    r   r   NF)rD   cmdloopr   rg  r   rG   r8  quitting)r    r  s     r   r  zInterruptiblePdb.cmdloop  sP    	>>$e44  	0DNLLLL!DM	s
    A Ac                     	 	 d| _         | j                          d| _         y # t        $ r | j                  d        w xY w)NTFz--KeyboardInterrupt--)allow_kbdintr  r   r:  )r    s    r   _cmdloopzInterruptiblePdb._cmdloop  sG    	 %)!$)!$ 45s   " >r*   )rv  rw  rx  r/   r  r  r   r   r   r  r    s    T	r   r  c                 v    t               j                  | xs t        j                         j                         y)zm
    Start debugging from `frame`.

    If frame is not specified, debugging starts from caller's frame.
    N)r   rn   rG   rj   rk   r  s    r   rn   rn     s#     EOOE3S]]_334r   r*   )r   )r/   r)  r   rG   reru   IPythonr   IPython.utilsr   r   r   IPython.core.excolorsr   __skip_doctest__rO   pdbr   rD   r_  r   r   r"   compiler$   r'   r2   r  rn   r   r   r   <module>r     s   ZL   
 	 	  $ . 2  	  "* 2::m, 6	QV& QVhs 85r   