
    ^hؗ                     *   S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  SSK
JrJr  SSKJr  SrS	rSS
KJr  Sr\R,                  S:  rS rSS jrSS jr\R6                  " S5      rS rSS jr " S S\5      r " S S\5      rSS jr g)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)contextmanager)
PyColorize)	coloransi	py3compat)exception_colorsTzipdb> )Pdb__debuggerskip__)      c                 4    U S:  a  SU S-
  -  S-   $ U S:X  a  gg)z<generate the leading arrow in front of traceback or debugger   ->    >  )pads    O/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/debugger.py
make_arrowr      s)    
axCE{T!!	    c                     [        S5      e)zyException 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                      [        S[        SS9e)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                 .    [         R                  SU 5      $ )Nr   )RGX_EXTRA_INDENTsub)multiline_strings    r   strip_indentationr*      s    $455r   c                 p   ^  U 4S jnUR                   (       a  [        UR                   5      U-   Ul         U$ )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                     > T" U 0 UD6$ Nr   )argskwnew_fns     r   wrapper%decorate_fn_with_doc.<locals>.wrapper   s    t"r""r   )__doc__r*   )r0   old_fnadditional_textr1   s   `   r   decorate_fn_with_docr6      s)    
#~~+FNN;oMNr   c                     ^  \ rS rSrSr\(       a  SrSSSSS.rS.S jrS r	S/U 4S	 jjr
S
 rS r\(       a  S r\S 5       rS rS rU 4S jrS rS r\" \\R.                  5      =rrS rS/S jr  S0S jrS rS1S jrS2S jrS rS r S r!S r"\"r#S r$S r%\%r&S r'S  r(S! r)S" r*S# r+S$ r,S% r-S& r.\.r/U 4S' jr0S( r1U 4S) jr2S* r3S+ r4\4r5\3r6S, r7S-r8U =r9$ )3r	      a4  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.

i  TF)tbhidereadonlyipython_internaldebuggerskipc                     [        U5      U l        U R                  S::  a  [        S5      e [        R
                  " XX#40 UD6  [        5       U l        U R                  cA  [        R                  S   nSSK
Jn  UR                  5       U l        U[        R                  S'   U R                  R                  n	0 U l        [        5       U l        ["        R$                  n
U R                   nU
R&                  US   R                  l        U
R&                  US   R                  l        U
R&                  US   R                  l        U
R.                  US   R                  l        U
R0                  US   R                  l        U
R2                  US   R                  l        U
R4                  US   R                  l        U
R0                  US   R                  l        U
R2                  US   R                  l        U
R4                  US	   R                  l        U
R0                  US	   R                  l        U
R2                  US	   R                  l        [6        R8                  " U	S
9U l        U R=                  U	5        [(        U l        SU l        SU l         U RB                  U l"        [F        (       a  [I        5       U l%        SU l&        gg! [        [        4 a  n[        S5      UeSnAff = f)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   
TermColorsrA   promptbreakpoint_enabledbreakpoint_disabledGreenLightRedRedBluer   Parserparser
set_colorsskip_hiddenreport_skippeddefault_predicates_predicatesCHAIN_EXCEPTIONStuple_chained_exceptions_chained_exception_index)r#   completekeystdinstdoutrG   kwargse	save_mainr@   color_schemeCcsts               r   rJ   Pdb.__init__   s`   0	Nw<DL||q  !EFF ! 	5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',wD$,-D) { :& 	N !EFAM	Ns   +K
 
K+K&&K+c                 Z    U R                   R                  U5        XR                  l        g)z;Shorthand access to the color table scheme selector method.N)rR   set_active_schemer\   rE   )r#   schemes     r   r]   Pdb.set_colors*  s     11&9"r   c                 r   > Uc  [         R                  " 5       R                  nXl        [        TU ]  U5      $ r-   )rL   	_getframef_backinitial_framesuper	set_trace)r#   frame	__class__s     r   ry   Pdb.set_trace/  s/    =MMO**E"w ''r   c                    U R                   S   (       ae  UR                  R                  n[        R                  R                  U5      (       a+  [        R                  " U[        R                  5      (       d  gU R                   S   (       a:  XR                  [        U SS5      4;   a  gU R                  U5      nSU;  a  gUS   $ g)zH
Given a frame return whether it it should be hidden or not by IPython.
r:   Tr9   rw   NF__tracebackhide__)ra   f_codeco_filenameospathisfileaccessW_OKcurframegetattr_get_frame_locals)r#   rz   fnameframe_localss       r   _hidden_predicatePdb._hidden_predicate5  s    
 J'LL,,E ww~~e$$RYYubgg-F-FH%ot(LMM11%8L",6 344r   c                 D   U Vs/ s H  o R                  US   5      PM     nn[        U5       VVs/ s H  u  pBUS:X  d  M  UPM     nnnU(       a=  U R                  S   (       a)  [        U5       VVs/ s H  u  pFXES   :  a  UOSPM     nnnU$ s  snf s  snnf s  snnf )zu
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__r;   T)r   	enumeratera   )r#   stacksip_hideiip_starths          r   hidden_framesPdb.hidden_framesJ  s     :??A))!A$/?"+G"4R"4$!=Q8QA"4R(();<DMgDVWDV&1AOq5DVGW	 @RWs   BBB4Bc                    / n[        U[        5      (       a  UR                  UpCUb  XB;   a  OUR                  U5        UR                  b  UR                  nO*UR
                  b  UR                  (       d  UR
                  n[        U5      U R                  :  a   U R                  SU R                   S35        OUb  M  OUn[        [        U5      5      U4$ )a  
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.
z
More than zQ chained exceptions found, not all exceptionswill be browsable with `exceptions`.)
isinstanceBaseException__traceback__append	__cause____context____suppress_context__lenMAX_CHAINED_EXCEPTION_DEPTHmessagerc   reversed)r#   	tb_or_exc_exceptions	tracebackcurrents        r   _get_tb_and_exceptionsPdb._get_tb_and_exceptions\  s     K)]33%.%<%<i7)-&&w/((4")"3"3++7 ' < <")"5"5;'4+K+KK()I)I(JCC
 % )( &	+./::r   c              #      #     Xl         [        U5      S-
  U l        Sv   [        5       U l         SU l        g! [        5       U l         SU l        f = f7f)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
r   Nr   )rd   r   re   rc   )r#   
exceptionss     r   _hold_exceptionsPdb._hold_exceptions  sM     2+5(03J!0C- ,17(01- ,17(01-s   A8 AAAc                 <   U R                   (       d  U R                  S5        gU(       d  [        U R                   5       Hs  u  p#X R                  :X  a  SOSn[	        U5      n[        U5      S:  a  USS S-   nU R                   U   R                  c  SOUS	 nU R                  U SU SU 35        Mu     g [        U5      nSUs=::  a  [        U R                   5      :  a  O  OU R                   U   R                  c  U R                  S5        gXpl        U R                  SU R                   U   R                  5        U R                  U R                  U R                     5        gU R                  S5        g! [         a    U R                  S
5         gf = f)a/  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.Nr    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)rd   r   r   re   reprr   r   rF   r   errorsetupprint_stack_entryr   curindex)r#   argixexcrT   rep	indicatornumbers           r   do_exceptionsPdb.do_exceptions  s~    ++7
 ()A)ABGB$&*G*G$GSSFs)C3x"}!#2h.  33B7EEM  "2w 
 LLF81YKq!>?  C XF >T%=%=!>>//7EEM

Y 4:1JJtT%=%=f%E%S%ST**4::dmm+DEJJ>? " JJ<=s   9E= =FFc                     [         (       ad  U R                  U5      u  p4[        U[        5      (       a
  Uc   S5       eU R	                  U5         [
        R                  " XU5        S S S 5        g [
        R                  " X[        5        g ! , (       d  f       g = f! [         a9    U R                  R                  SU R                  R                  5       -   5         g f = f)Nz$main exception must have a traceback
)rb   r   r   r   r   rI   interactionr   KeyboardInterruptrh   writerK   get_exception_only)r#   rz   r   rd   r   s        r   r   Pdb.interaction  s    	F*.*E*Ei*P'#i77>Q+QQ>**+>?&&tB7 @? ""4	: @?
 ! 	FKKdTZZ%B%B%DDE	Fs7   AB B(B 1B 
BB B A C! C!c                    > UR                  S5      (       a	  SUSS -   nOUR                  S5      (       a  SUSS -   n[        TU ]	  U5      nU$ )z<Perform useful escapes on the command before it is executed.z??zpinfo2 N?zpinfo )endswithrx   precmd)r#   liner{   s     r   r   
Pdb.precmd  sV     ==tCRy(D]]3d3Bi'Dw~d#r   c                 0    [         R                  " X5        g r-   )rI   do_framer#   r   s     r   new_do_framePdb.new_do_frame  s    "r   c                     [        U S5      (       a%  U R                  U R                  R                  l        [
        R                  " X5      $ )Nold_all_completions)hasattrr   rK   	Completerall_completionsrI   do_quitr   s     r   new_do_quitPdb.new_do_quit  s7    4.//373K3KDJJ  0~~d((r   c                 F    U R                  S5        U R                  U5      $ )zTRestart 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_restartPdb.new_do_restart  s      	IJ||C  r   c           	      v   U R                   R                  nUR                  nUc  U R                  n [	        U5      nUS::  a  [        S5      e  Sn[        U R                  U R                  5      U R                  5       HZ  u  pgU(       a  U R                  (       a  US-  nM$  U(       a   [        UR                   SU SU S35        SnU R                  XqS9  M\     U(       a  [        UR                   SU SU S35        g g ! [        [
        4 a  n[        S5      UeS nAff = f! [         a     g f = f)Nr   r>   r   z    [... skipping  hidden frame(s)]r   )rG   )rR   active_colorsNormalrG   rF   r   rH   zipr   r   r^   printexcNamer   r   )r#   rG   ColorsColorsNormalrj   skippedhiddenframe_linenos           r   print_stack_tracePdb.print_stack_trace  sI   ((66}}?llG	N'lG!| !EFF 	G(+D,>,>tzz,JDJJ(W$d..qLG!>>**<WIEVWcVddfg  G&&|&E )X ~~&&8	ARS_R``bc  :& 	N !EFAM	N$ ! 		s*   D B4D+ D(D##D(+
D87D8c                 p   Uc  U R                   n [        U5      nUS::  a  [        S5      e [	        U R                  USU5      U R                  S9  Uu  pVUR                  R                  nU R                  R                  R                  XvS5        g ! [        [        4 a  n[        S5      UeS nAff = f)Nr   r>   r   file)rG   rF   r   rH   r   format_stack_entryrh   r   r   rK   hookssynchronize_with_editor)r#   r   prompt_prefixrG   rj   rz   linenofilenames           r   r   Pdb.print_stack_entry
  s    ?llG	N'lG!| !EFF  	d%%lB@t{{S %<<++

001E :& 	N !EFAM	Ns   B B5$B00B5c                 N    XR                   L a  U R                  $ UR                  $ )a	  "
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   curframe_localsf_locals)r#   rz   s     r   r   Pdb._get_frame_locals  s$    " MM!'''>>!r   c                    Uc  U R                   n [        U5      nUS::  a  [        SU R                  S9  SS Kn/ nU R                  R                  nUR                  nUR                  < SU< 3nUR                  < SUR                  < SU< 3n	SUR                  < SU< S3n
SUR                  < SUR                  < SU< 3nUu  pSnU R!                  U5      nSU;   a  US   nXR#                  U5      S-   -  nUR%                  U5        U R'                  UR(                  R*                  5      nU[,        R.                  " U5      -  nUR(                  R0                  (       a  UR(                  R0                  nOS	nSnUS
:w  a$  SU;   a  UR#                  US   5      nOSnU	UU4-  nXR2                  L a  UR%                  S5        OUR%                  S5        UR%                  U< SU< SU< S35        US-
  US-  -
  n[4        R6                  " U5      n[9        U[;        U5      U-
  5      n[=        US5      nUUUU-    n[?        U5       Ha  u  nnUS-   U-   U:H  nXR2                  L =(       d    U=(       a    U=(       d    U
nUR%                  U RA                  UUUS-   U-   UUS95        Mc     SRC                  U5      $ ! [        [
        4 a    [        SU R                  S9   GNf = f)Nr   r>   r   %s%s r   
__return__r   z<lambda>r   __args__z()r   z  ()r   r   arrow)"rG   rF   r   rh   rH   r   reprlibrR   r   r   
filenameEmvNamevalEmr   linenoEmr   r   r   r   canonicr   r   r   cast_unicodeco_namer   	linecachegetlinesminr   maxr   _Pdb__format_linejoin)r#   r   lprefixrG   r  retr   r   tpl_linktpl_calltpl_linetpl_line_emrz   r   return_value	loc_framervr   linkfunccallr.   startlinesr   r   
show_arrowlinetpls                               r   r   Pdb.format_stack_entry2  s   ?llG	N'lG!|:M 	((66}} & 1 1<@%+\\6<<N'-}}lC,2OOV[[,W$**51	9$<(BLL,t33L

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

467
WaZ'""8,E3u:/0E1eego. 'GAtQ&0J-;LXPXGJJ""Xuqy1}d* #  ( wws| :& 	N:M	Ns   %K $K43K4c                 >   SnSnU R                   R                  US5      u  pU	(       d  UnS n
X0R                  U5      ;   a  U R                  X#5      nUS   n
U
(       aT  U R                  R
                  n[        U
R                  5      nUR                  nU
R                  (       d  UR                  nSnU(       a>  U[        [        U5      5      -
  [        U5      -
  n[        U5      < [        U5      < 3nOSU[        U5      -
  [        U5      4-  nXU-   X4-  $ )Nr   strr      z%*s)r\   format2get_file_breaks
get_breaksrR   r   r$  r   rU   enabledrV   r   r   )r#   r  r   r   r   r  bp_markbp_mark_colornew_lineerrbpbpsr   numbers_widthr   nums                   r   __format_linePdb.__format_linez  s    ++D%8D))(33//(3CRB,,::F"))nG"55M:: & : :#c&k"22S\AC&sOS[9C=3w<7VEEC72C>>>r   c           	      v    U R                   R                  nUR                  nSUR                  < SU< S3nSUR                  < SUR
                  < SU< 3n/ nUS:X  a  [        U S5      (       a  U R                  n[        X#S-   5       Hu  n	[        R                  " X5      n
U
(       d    OWXR                  R                  :X  a  U R                  XqXSS9n
OU R                  XaXSS9n
UR                  U
5        Xl        Mw     [        S	R!                  U5      U R"                  S
9  g! [$         a     gf = f)zAThe printing (as opposed to the parsing part of a 'list'
command.r   r   z<string>_exec_filenamer   Tr  Fr   r   N)rR   r   r   r   r  r   r   r5  ranger  getliner   f_linenor  r   r   r  rh   r   )r#   r   firstlastr   r   r  r  srcr   r   s              r   print_list_linesPdb.print_list_lines  s   	,,::F!==L+1==,GH06l[KC:%'$8H*I*I..Av. ((:]]333--#v4 . D  -- F . D 

4 $ /" "''#,T[[1  		s   D(D+ +
D87D8c                    UR                  5       (       d=  [        S5        U R                  R                  5        H  u  p#[        SUSU5        M     gUR                  5       R	                  S5      n[        U5      S:w  a0  [        S[        U R                  R                  5       5       35        gUu  pVXPR                  ;  a3  [        U< S[        U R                  R                  5       5       35        gUR                  5       S	;  a  [        U< S
35        gUR                  5       S;   U R                  U'   [        U R                  R                  5       5      (       d  [        S5        gg)a  
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   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@  rA  rB  KWarning, all predicates set to False, skip_hidden may not have any effects.)stripr   ra   itemssplitr   setkeysloweranyvalues)r#   r.   pv
type_valuetype_values          r   do_skip_predicatesPdb.do_skip_predicates  s>   " zz||'(((..0eQQ' 1ZZ\'',
z?aLSQUQaQaQfQfQhMiLjk !(((UIXc$*:*:*?*?*A&B%CDE;;= HH)\] "'++-3G"G4##**,--] .r   c                 p   UR                  5       (       d  [        SU R                   S35        OSUR                  5       R                  5       S;   a  SU l        O)UR                  5       R                  5       S;   a  SU l        [	        U R
                  R                  5       5      (       d  [        S5        gg)	zS
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@  rA  T)rD  rC  FrF  N)rG  r   r^   rL  rM  ra   rN  r   s     r   do_skip_hiddenPdb.do_skip_hidden  s    
 yy{{ !1!1 22ab YY[ O3#DYY[ O3$D4##**,--] .r   c                    SU l         SnU(       ai  US:w  ac   [        U0 0 5      n[        U5      [        S5      :X  a$  Uu  pB[        U5      n[        U5      nX$:  a  XB-   nO_[	        S[        U5      S-
  5      nOFU R                  b  US:X  a$  [	        SU R                  R                  S-
  5      nOU R                  S-   nUc  US	-   nU R                  U R                  R                  R                  XB5        UnU R                  R                  R                  nU R                  R                  R!                  XeS
5        g!   [        S[        U5      U R                  S9   g= f)z9Print lines of code from the current stack frame
        listN.r   r      z*** Error in argument:r   
   r   )lastcmdevaltyperF   r  r   r   rh   r   r   r8  r<  r   r   rK   r   r   )r#   r   r:  xr9  r   r   s          r   do_listPdb.do_list  s3    3#:b"%7d2h&"#KEJEt9D|$|3q6A:.E [[ C3J4==11A56EKK!OE<2:Ddmm22>>L ==''33

001E.S	Ls   AE !E  E#c                 $   [         R                  " U5      u  p#[         R                  " U5      (       a"  UR                  U R	                  U5      L a  US4$ [         R
                  " U5      (       a  US4$ [         R                  " X#S  5      US-   4$ )Nr   )inspect
findsourceisframe	f_globalsr   ismodulegetblock)r#   objr  r   s       r   getsourcelinesPdb.getsourcelines  sz    **3/??3CMMT5K5KC5P$P!8Oc""!8Og/99r   c                    SU l          U R                  U R                  5      u  p#U[        U5      -   nU R                  U R                  R                  R                  X55        g! [         a  nU R	                  U5         SnAgSnAff = f)zVPrint lines of code from the current stack frame.

Shows more lines than 'list' does.
longlistN)	r^  rl  r   OSErrorr   r   r<  r   r   )r#   r   r  r   r-  r:  s         r   do_longlistPdb.do_longlist&  sv    
 "	 //>ME E
"dmm22>>M	  	JJsO	s   A% %
B
/BB
c                 :   [         R                  " 5       n[         R                  " S5        U R                  R                  nU R
                  nU R                  U R                  U R                  U R                  S9nU R                  Ul
        SU R                  R                  5       -  Ul        U R                  S5        [         R                  " UR                  XU45        U R                  S5        [         R                  " U5        UR                   U l        g)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)rf   rg   rh   z(%s) zENTERING RECURSIVE DEBUGGERzLEAVING RECURSIVE DEBUGGER)rL   gettracesettracer   rh  r   r{   rf   rg   rh   use_rawinputrT   rG  r   call_tracingrunr^  )r#   r   trace_functionglobalslocalsrO  s         r   do_debugPdb.do_debug5  s     T--))%%NNt'7'7!%DKK  A**T[[..0023v 6712^$yyr   c                     SU R                   4SU R                  R                  4/nU R                  R	                  S5      " XS9  g)zRPrint the call signature for any callable object.

The debugger interface to %pdefLocalsGlobalspdef
namespacesNr   r   rh  rK   find_line_magicr#   r   r  s      r   do_pdefPdb.do_pdefI  D    
 t++,//0

 	

""6*3Fr   c                     SU R                   4SU R                  R                  4/nU R                  R	                  S5      " XS9  g)zDPrint the docstring for an object.

The debugger interface to %pdoc.r  r  pdocr  Nr  r  s      r   do_pdocPdb.do_pdocS  r  r   c                     SU R                   4SU R                  R                  4/nU R                  R	                  S5      " XS9  g)zePrint (or run through pager) the file where an object is defined.

The debugger interface to %pfile.
r  r  pfiler  Nr  r  s      r   do_pfilePdb.do_pfile]  sD     t++,//0

 	

""7+CGr   c                     SU R                   4SU R                  R                  4/nU R                  R	                  S5      " XS9  g)z\Provide detailed information about an object.

The debugger interface to %pinfo, i.e., obj?.r  r  pinfor  Nr  r  s      r   do_pinfoPdb.do_pinfoh  sD    
 t++,//0

 	

""7+CGr   c                     SU R                   4SU R                  R                  4/nU R                  R	                  S5      " XS9  g)zdProvide extra detailed information about an object.

The debugger interface to %pinfo2, i.e., obj??.r  r  pinfo2r  Nr  r  s      r   	do_pinfo2Pdb.do_pinfo2r  sD    
 t++,//0

 	

""8,SHr   c                     SU R                   4SU R                  R                  4/nU R                  R	                  S5      " XS9  g)z;Print (or run through pager) the source code for an object.r  r  psourcer  Nr  r  s      r   
do_psourcePdb.do_psource|  sD     t++,//0

 	

""9-cIr   c                     U(       a   [        U5      nU R                  U5        gU R                  5         g! [         a  nU R                  U5         SnAgSnAff = f)a  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)rF   r   r   r   )r#   r   rG   r-  s       r   do_wherePdb.do_where  sQ     c( ""7+""$  

3s   7 
AAAc                 &  > [         TU ]  U5      nU(       a  U$ U R                  S   (       ad  [        UR                  R
                  ;   a  gUR                  (       a4  U R                  UR                  5      R                  [        5      (       a  gg)z
_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

r<   TF)	rx   break_anywherera   DEBUGGERSKIPr   co_varnamesrv   r   get)r#   rz   supr{   s      r   r  Pdb.break_anywhere  sk     g$U+JN+u||777|| 6 6u|| D H H V Vr   c                 (   U R                   S   (       d  g[        UR                  R                  ;   a  gUn[	        USS5      (       aJ  UR
                  nU R                  U5      R                  [        5      (       a  g[	        USS5      (       a  MJ  g)zM
Utility to tell us whether we are in a decorator internal and should stop.

r<   FTrv   N)ra   r  r   r  r   rv   r   r  )r#   rz   cframes      r   )_is_in_decorator_internal_and_should_skip-Pdb._is_in_decorator_internal_and_should_skip  s     / 5<<333 fh--]]F%%f-11,?? fh--
 r   c                 >  > U R                  U5      SL a  gSnU R                  (       a  U R                  U5      nU(       aN  U R                  (       a=  U R                  R
                  nUR                  n[        UR                   SU S35        [        TU ])  U5      $ )NTFz     [... skipped 1 hidden frame]r   )r  r^   r   r_   rR   r   r   r   r   rx   	stop_here)r#   rz   r   r   r   r{   s        r   r  Pdb.stop_here  s    99%@DH++E2F""00>>%}}~~&&F|nTVW w ''r   c                    U R                   S:X  a  U R                  S5        g [        U=(       d    S5      nSnUS:  a  SnOSnU R	                  U R
                  5      n[        U R                   S-
  SS5       H0  nXg   (       a  U R                  (       a  US-  nM$  US-  nXR:  d  M0    O   U R                  S5        gU R                  R                  nUR                  n	UnU R                  U5        U(       a  [        WR                   SU S	W	 S
35        gg! [         a    U R                  SU-  5         gf = f)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   rF   r   r   r   r6  r^   rR   r   r   _select_framer   r   )
r#   r   countr   	_newframecounterr   r   r   r   s
             r   do_up	Pdb.do_up  s<    ==AJJ~&	qME 19IG ..tzz:M4==1,b"5 #(8(8qLG1# 6 

] ,,::F!==LI9%>>""3G9<Ml^[]^ 7  	JJ1C78	s   D D=<D=c                    U R                   S-   [        U R                  5      :X  a  U R                  S5        g [	        U=(       d    S5      nUS:  a  [        U R                  5      S-
  nOSnSnU R                  U R                  5      n[        U R                   S-   [        U R                  5      5       H0  nXg   (       a  U R                  (       a  US-  nM$  US-  nXB:  d  M0    O   U R                  S5        gU R                  R                  nUR                  n	U(       a  [        UR                   SU SU	 S	35        UnU R                  U5        g! [
         a    U R                  SU-  5         gf = f)
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   rF   r   r   r6  r^   rR   r   r   r   r   r  )
r#   r   r  r  r  r   r   r   r   r   s
             r   do_downPdb.do_down  s[    ==1DJJ/JJ~&	qME 19DJJ!+IGG ..tzz:M4==1,c$**o> #(8(8qLG1# ? 

] ,,::F!==L~~&&7y@QR^Q__ab I9%=  	JJ1C78	s   E E:9E:c                      [        U5      nUS::  a
  [        5       eX l        g! [         a    U R                  S5         gf = f)zocontext 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)rF   r   rG   r   )r#   rG   new_contexts      r   
do_contextPdb.do_context0  sD    
	Vg,Ka l"&L 	VJJTU	Vs   !$ AA)re   rd   ra   rQ   rR   rG   rw   r^  r   r\   rT   r_   rK   r^   )NNNr\  r-   )z
-> N)z: N)F):__name__
__module____qualname____firstlineno__r3   rb   r   r`   rJ   r]   ry   r   r   r   r   r   r   r   r   r   r   r6   rI   r   do_qr   r   r   r   r   r  r<  rT  rW  rb  do_lrl  rq  do_llr|  r  r  r  r  r  r  r  do_wr  r  r  r  r  do_ddo_ur  __static_attributes____classcell__)r{   s   @r   r	   r	      sY   
 &)#  	[.|#
(*  !	;F 
	2 
	2",	@\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 Vr   r	   c                   (    \ rS rSrSrSS jrS rSrg)InterruptiblePdbi>  zJVersion of debugger where KeyboardInterrupt exits the debugger altogether.Nc                      [         R                  " XS9$ ! [         a8    S U l        U R	                  S5        [
        R                  " S5        SU l        e f = f)z>Wrap cmdloop() such that KeyboardInterrupt stops the debugger.)introc                     g)NFr   rz   s    r   <lambda>*InterruptiblePdb.cmdloop.<locals>.<lambda>F  s    5r   r   NF)rI   cmdloopr   r  r   rL   ru  quitting)r#   r  s     r   r  InterruptiblePdb.cmdloopA  sN    	>>$44  	0DNLLLL!DM	s
    AAc                       SU l         U R                  5         SU l         g ! [         a    U R                  S5        e f = f)NTFz--KeyboardInterrupt--)allow_kbdintr  r   r   )r#   s    r   _cmdloopInterruptiblePdb._cmdloopL  sG    	 %)!$)!$ 45s   " ?)r  r  r  r-   )r  r  r  r  r3   r  r  r  r   r   r   r  r  >  s    T	r   r  c                     [        5       R                  U =(       d    [        R                  " 5       R                  5        g)za
Start debugging from `frame`.

If frame is not specified, debugging starts from caller's frame.
N)r	   ry   rL   ru   rv   r  s    r   ry   ry   Z  s#     EOOE3S]]_334r   r-   )r   )!r3   re  r  rL   rer   IPythonr   
contextlibr   IPython.utilsr   r   r   IPython.core.excolorsr   __skip_doctest__rT   pdbr	   rI   r  version_inforb   r   r   r%   compiler'   r*   r6   r  ry   r   r   r   <module>r     s   ZL   
 	 	  % $ . 2  	  "
 ##g- * ::m, 6	FV& FVRs 85r   