
    Mh                        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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mZmZm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mZm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 dZ3dZ4 G d de*          Z5 e6            Z7dZ8 G d de*          Z9 G d de9e5          Z: G d de:          Z; G d de:          Z< G d de5          Z=dS ) aT  
Verbose and colourful traceback formatting.

**ColorTB**

I've always found it a bit hard to visually parse tracebacks in Python.  The
ColorTB class is a solution to that problem.  It colors the different parts of a
traceback in a manner similar to what you would expect from a syntax-highlighting
text editor.

Installation instructions for ColorTB::

    import sys,ultratb
    sys.excepthook = ultratb.ColorTB()

**VerboseTB**

I've also included a port of Ka-Ping Yee's "cgitb.py" that produces all kinds
of useful info when a traceback occurs.  Ping originally had it spit out HTML
and intended it for CGI programmers, but why should they have all the fun?  I
altered it to spit out colored text to the terminal.  It's a bit overwhelming,
but kind of neat, and maybe useful for long-running programs that you believe
are bug-free.  If a crash *does* occur in that type of program you want details.
Give it a shot--you'll love it or you'll hate it.

.. note::

  The Verbose mode prints the variables currently visible where the exception
  happened (shortening their strings if too long). This can potentially be
  very slow, if you happen to have a huge data structure whose string
  representation is complex to compute. Your computer may appear to freeze for
  a while with cpu usage at 100%. If this occurs, you can cancel the traceback
  with Ctrl-C (maybe hitting it more than once).

  If you encounter this kind of situation often, you may want to use the
  Verbose_novars mode instead of the regular Verbose, which avoids formatting
  variables (but otherwise includes the information and context given by
  Verbose).

.. note::

  The verbose mode print all variables in the stack, which means it can
  potentially leak sensitive information like access keys, or unencrypted
  password.

Installation instructions for VerboseTB::

    import sys,ultratb
    sys.excepthook = ultratb.VerboseTB()

Note:  Much of the code in this module was lifted verbatim from the standard
library module 'traceback.py' and Ka-Ping Yee's 'cgitb.py'.


Inheritance diagram:

.. inheritance-diagram:: IPython.core.ultratb
   :parts: 3
    N)Sequence)TracebackType)AnyCallableListOptionalTuple)Terminal256Formatter)Token)get_ipython)path)	py3compat)ParserThemeTokenStreamtheme_table)get_terminal_size   )DisplayTrap)DocTB)
	FrameInfoTBTools_format_traceback_lines_safe_string_simple_format_traceback_lines_tokens_filenameeqreprget_line_number_of_framenullrepr	text_repr   i'  c                   P   e Zd ZdZdee         dedz  dedz  ddfdZdedz  dej	        dz  fd	Z
	 	 	 ddedee         dee         dee         dedee         fdZdee         dee         fdZdee         dedz  dee         fdZd Zdedz  dedz  ddfdZdedefdZdS )ListTBaj  Print traceback information from a traceback list, with optional color.

    Calling requires 3 arguments: (etype, evalue, elist)
    as would be obtained by::

      etype, evalue, tb = sys.exc_info()
      if tb:
        elist = traceback.extract_tb(tb)
      else:
        elist = None

    It can thus be used by programs which need to process the traceback before
    printing (such as console replacements based on the code module from the
    standard library).

    Because they are meant to be called without a full traceback (only a
    list), instances of this class can't call the interactive pdb debugger.etypeevalueNetbreturnc                     | j                                          | j                             |                     |||                     | j                             d           d S N
)ostreamflushwritetextselfr$   r%   r&   s       T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/ultratb.py__call__zListTB.__call__   sZ     	499UFC889994         tbc                 2    |rt          j        |          S d S N)	traceback
extract_tb)r0   r4   s     r1   _extract_tbzListTB._extract_tb   s      	'+++4r3      	tb_offsetcontextc           
      0   t          |t                    r|\  }}nt                      }t          |t                    r|}n||                     |          }ng }|| j        n|}t          |t                    sJ g }|r|rt          |          |k    r
||d         }|                    t          | j
                                     t          dft          dft          j        dft          dft          dfg                     |                    |                     |                     d                    |                     ||                    }	|                    |	           ||                     |          }
|
rt'          |
d                   |vrz| |                     |j                  d	         ndg}|
\  }}}|                    t'          |
d                              d	}|                     ||||f||          }|}||z   |z   }|S )
a  Return a color formatted string with the traceback info.

        Parameters
        ----------
        etype : exception type
            Type of the exception raised.
        evalue : object
            Data stored in the exception
        etb : list | TracebackType | None
            If list: List of frames, see class docstring for details.
            If Traceback: Traceback of the exception.
        tb_offset : int, optional
            Number of frames in the traceback to skip.  If not given, the
            instance evalue is used (set in constructor).
        context : int, optional
            Number of lines of context information to print.

        Returns
        -------
        String with formatted exception.
        N	Traceback z(most recent call last):r*    r   r   )
isinstancetuplesetlistr9   r;   intlenappendr   _theme_nameformatr   NormalEmextend_format_listjoin_format_exception_onlyget_parts_of_chained_exceptionid!prepare_chained_exception_message	__cause__addstructured_traceback)r0   r$   r%   r&   r;   r<   chained_exc_idselistout_listlines	exceptionchained_exception_messagechained_exceptions_tb_offsetol1ol2s                  r1   rU   zListTB.structured_traceback   sN   > c5!! 	$#& C!eeOc4   	EE_$$S))EEE&/&7DNNY	)S)))))  	6 *SZZ)33ijj)OOD,-44,)BC 
 
 
 OOD--e4455533E6BBCC ?;;FCCI 0b1..oEE ) ::6;KLLQOO *
 &/"vs##By|$4$4555/0,///*0  09x/r3   extracted_listc           	      ~   g }t          |          D ]\  }\  }}}}|t          |          dz
  k    rdnd}t          | j                                     |rt
          j        nt
          j        dfgt          |||          z             }	|dk    rh|	t          | j                                     |rt
          j        nt
          j        df|rt
          j	        j
        nt
          j	        j        |fg          z  }	|	t          | j                                     |rt
          j        nt
          dfg          z  }	|rn|	t          | j                                     |rt
          j        nt
          d	f|rt
          j        nt
          |                                ft
          dfg          z  }	|                    |	           |S )
a   Format a list of traceback entry tuples for printing.

        Given a list of tuples as returned by extract_tb() or
        extract_stack(), return a list of strings ready for printing.
        Each string in the resulting list corresponds to the item with the
        same index in the argument list.  Each string ends in a newline;
        the strings may contain internal newlines as well, for those items
        whose source text line is not None.

        Lifted almost verbatim from traceback.py
        r   TF  lineno<module>z in r*       )	enumeraterG   r   rI   rJ   r   rK   Normalr   TBNameEmNameLinestriprH   )
r0   r_   output_listindfilenamerc   namelineemitems
             r1   rM   zListTB._format_list   s    3<^3L3L 	% 	%/C/(FD$N 3 3a 777UBt/077$&8%..EL$?@"2x???@ D z!!D$45<<+-?5<H,.AEHM4H   K 0188$&1%..E489  D  D$45<<')4uf=')4udjjllC   t$$$$r3   valuec                 ~   d}g }t           j        |j        fg}t          | j                                     |          }||                    |dz              nt          |t                    rt          |d          sJ t          |d          sJ t          |d          sJ t          |d          sJ t          |d          sJ d	}|j
        sd
|_
        |j        r'|j        }t          j        |j
        |j                  }nd}d}|                    t          | j                                     t           dfgt          d	|j
        |dk    rdn|          z   t           dfgz                        |dk    rt          j        |j        d          }|Zd}	|	t%          |          k     rL||	                                         r2|	dz  }	|	t%          |          k     r||	                                         2|                    t          | j                                     t           j        dft           j        |                                ft           dfg                     |j        d}
||	|j        dz
           D ]!}|                                r|
|z  }
|
dz  }
"|                    t          | j                                     t           j        |
dz   ft           dfg                     	 t          |d          sJ |j        }
n%# t2          $ r |                     |          }
Y nw xY w|
ra|                    t          | j                                     |t           j        dft           dft           |
ft           dfgz                        n|                    d|z             |                    d t9          |dg           D                        |r^t;                      }|N|J t          |d          sJ t          |d          sJ |j                            |j
        |j        d           |S )aT  Format the exception part of a traceback.

        The arguments are the exception type and value such as given by
        sys.exc_info()[:2]. The return value is a list of strings, each ending
        in a newline.  Normally, the list contains a single string; however,
        for SyntaxError exceptions, it contains several lines that (when
        printed) display detailed information about where the syntax error
        occurred.  The message indicating which exception occurred is the
        always last string in the list.

        Also lifted nearly verbatim from traceback.py
        FNr*   ro   rc   r.   offsetmsgTz<string>unknownrA   ra   rb   zutf-8r   r   re   r?   ^r@   z%s
c              3       K   | ]	}| d V  
dS )r*   N ).0xs     r1   	<genexpr>z0ListTB._format_exception_only.<locals>.<genexpr>  s(      QQA!xxxQQQQQQr3   	__notes__) r   ExcName__name__r   rI   rJ   rH   
issubclassSyntaxErrorhasattrro   rc   	linecachegetliner   r   cast_unicoder.   rG   isspacerk   rl   rv   Caretrw   	Exception	_some_strrL   getattrr   hookssynchronize_with_editor)r0   r$   rt   have_filedatarm   stype_tokensstyperc   textlineiscipinsts                r1   rO   zListTB._format_exception_only!  s    78 !1299,GG=ut|,,,,%-- 5uj11111uh/////uf-----uh/////ue,,,,, $~ 0%/EN< ""\F(0NNHH&F!H"" 0188* !N,2i,?,?DDV   "4=/* 
 
 
 r>>(5ej'JJH'Ac(mm++0C0C0E0E+Q c(mm++0C0C0E0E+&&#D$45<<!&V 4!&X^^-=-= >!&    |/"!)!elQ.>*>!? ) )A yy{{ ) !Q !S#**'(89@@"'+q3w!7% G   *ue,,,,,I * * *NN5))* 3"" 0188$"]C0"CL"AJ"DM	 
 
 
 
 ""6E>222 QQR1P1PQQQQQQ  	V ]]F!(((uh/////uj1111144U^U\STUUUs   5L L10L1c                 :    t                               | ||          S )zOnly print the exception type and message, without a traceback.

        Parameters
        ----------
        etype : exception type
        value : exception value
        )r#   rU   )r0   r$   rt   s      r1   get_exception_onlyzListTB.get_exception_only  s     **4>>>r3   c                     | j         }|                                 |                    d                    |                     ||                               |                                 dS )zOnly print the exception type and message, without a traceback.

        Parameters
        ----------
        etype : exception type
        evalue : exception value
        r*   N)r+   r,   r-   rN   r   )r0   r$   r%   r+   s       r1   show_exception_onlyzListTB.show_exception_only  sW     ,dii 7 7v F FGGHHHr3   c                     	 t          j        t          |                    S #  dt          |          j        z  cY S xY w)Nz<unprintable %s object>)r   r   strtyper   )r0   rt   s     r1   r   zListTB._some_str  sC    	D)#e**555	D,tE{{/CCCCCs    # >NNr:   )r   
__module____qualname____doc__r   BaseExceptionr   r2   r7   StackSummaryr9   r   rF   rE   r   rU   r   rM   rO   r   r   r   r{   r3   r1   r#   r#   s   s       O O$!M"! $! T!	!
 
! ! ! !md2 y7MPT7T     (,#'Z ZZ 'Z m$	Z
 C=Z Z 
cZ Z Z Zx-49 -c - - - -^n-(n1>1En	cn n n n`? ? ?"T)3@43G	   "Ds Ds D D D D D Dr3   r#   defaultc                       e Zd ZU dZdZdZeed<   edddddddfe	d	d
ede
dedede
de
deg df         dz  dedz  def fdZdedefdZd&dede
defdZd Zdedee         dee         dedee         deee                  fdZdedededefdZ	 	 	 d'dedee         dee         dee         dedee         fd!Zd&d"e
ddfd#Zd(d$Zd)d%Z xZS )*	VerboseTBa;  A port of Ka-Ping Yee's cgitb.py module that outputs color text instead
    of HTML.  Requires inspect and pydoc.  Crazy, man.

    Modified version which optionally strips the topmost entries from the
    traceback, to be used with alternate interpreters (because their own code
    would appear in the traceback).zbg:ansiyellowr   _modeFNr   T)color_scheme
theme_namecall_pdbr+   r;   long_headerinclude_varscheck_cachedebugger_clsr   c	                   |	t           urnt          |	t                    sJ |	                                }t	          j        ddt                     |t          k    rt	          j        ddt                     |t          k    rd}t          |t                    sJ t                      	                    ||||           || _
        || _        || _        |t          j        }|| _        d| _        dS )	aW  Specify traceback offset, headers and color scheme.

        Define how many frames to drop from the tracebacks. Calling it with
        tb_offset=1 allows use of this handler in interpreters which will have
        their own code at the top of the traceback (VerboseTB will first
        remove that frame before printing the traceback info).zcolor_scheme is deprecated as of IPython 9.0 and replaced by theme_name (which should be lowercase). As you passed a color_scheme value I will try to see if I have corresponding theme.   )
stacklevelcategoryzYou passed both `theme_name` and `color_scheme` (deprecated) to VerboseTB constructor. `theme_name` will be ignored for the time being.linux)r   r   r+   r   NT)	_sentinelrB   r   lowerwarningswarnDeprecationWarning_defaultsuper__init__r;   r   r   r   
checkcacher   skip_hidden)r0   r   r   r+   r;   r   r   r   r   r   	__class__s             r1   r   zVerboseTB.__init__  s$   ( y((lC00000%++--JM +    X%%5  !/    !! J*c*****!%	 	 	
 	
 	
 #&( #.K&r3   
frame_infor'   c           
      "	   t          |t                    sJ t          |j        t          j                  rJt
          | j                                     t          dft          j	        d|j
        z  ft          dfg          S dt          z  }t          |j        t                    sJ t          j        |j                  \  }}}}|j        |j                                        }nd}|dk    rd}n| j        rt(          nt*          }		 t          j        |||||		          }
t          |
t.                    sJ t
          | j                                     t          d
ft          j        |ft          j        |
fg          }nW# t4          $ rJ t
          | j                                     t          d
ft          j        |ft          j        dfg          }Y nw xY wg }| j        r	 |j        }|D ]X}|                    t          |j        ft          dft          j        dft          j        t=          |j                  fg           Yn-# t@          $ r  |                    t          dfg           Y nw xY w|j        t|j!        J t          j"        tG          j$        |j!                  ft          dft          |ft          dfg}tK          | j                  j&        t          |j'        tP          j)                  sJ |j'        j*        }|j        }|j+        }||z
  }|j,        J ||j,        k    r*t[          ||j,        z
  d          }||j,        z   }|j,        }nd}||j,        z   }|||         }fd|D             }t]          ||||t
          | j                           }t
          | j                                     |          }t
          | j                                     ||z             S t
          | j                                     t_          d|j!        |j                            }||rdndz  }|| dz  }|t
          | j                                     ta          |j1        t
          | j                 | j2        |                    z  }|S )zFormat a single stack framere   z![... skipping similar frames: %s]r*   r?   N?rd   rA   )formatvaluezin z"(***failed resolving arguments***)z= z<Exception trying to inspect frame. No more locals available.r   r   c                 ,    g | ]}| |d           fS )r   r{   )r|   r   _line_formats     r1   
<listcomp>z+VerboseTB.format_record.<locals>.<listcomp>x  s*    LLLQaa!7!78LLLr3   )themeTrb   z, )3rB   r   _sd
stack_dataRepeatedFramesr   rI   rJ   r   r   descriptionINDENT_SIZErc   rF   inspectgetargvaluesframe	executingcode_qualnamer   r   r   formatargvaluesr   VNameValEmKeyErrorvariables_in_executing_piecerH   rp   reprrt   r   ro   
FilenameEm	util_pathcompress_userr   format2codetypesCodeTypeco_firstlineno	raw_linesr<   maxr   r   r   rY   
has_colors)r0   r   indentargsvarargsvarkwlocals_funccallvar_reprscope
lvals_toksfibpvarlevel_tokens
first_linecurrent_liner   indexstartstopraw_color_err	tb_tokens	_tb_linesresultr   s                            @r1   format_recordzVerboseTB.format_record  s   *i00000jnj&?@@ 
	t/077FO;j>TT DM	 	 	 K'*+S11111(/(<Z=M(N(N%gug+'5577DDD:DD "&!2@vvH/'5'x   "%-----"4#34;;U^ek4%85;:NO     " #4#34;;d+&JK #2 )+
 	 ">  C%%"CH-"CL"[$/"[$sy//:	       !! "Z     >!&222!9#::;N#O#OP	L "T-=>>>FLjou~>>>>>(o<J * 1L#-#7I%
2E%111
***EJ$66::z11"*z11!%*-I MLLL)LLLM6!$"23  I ))9:AA)LLIt/077y8PQQQ !1299 z'::CTUUU F d*dd*Fkkk!Fk$"23::'$ 01O	   F Ms'   A7F   AGG!A"I 'I.-I.r$   long_versionc                 (   t          dt                      d                   }|rdt          j                                        d         z   dz   t          j        z   }t          j        t          j                              }t          | j	                 }|
                    t          j        |j        d         |z  ft          dft          j        |ft          d|t          |          z
  t          |          z
  z  ft          |ft          dft          |                    |          fg          }|dz  }n]t          | j	                 
                    t          j        |ft          d	                    |t          |          z
            fg          }|S )
NK   r   zPython : top_liner*   r?   z
A problem occurred executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.z!Traceback (most recent call last))minr   sysversionsplit
executabletimectimer   rI   rJ   r   Toplinesymbolsr   rG   rjust)r0   r$   r   widthpyverdater   heads           r1   prepare_headerzVerboseTB.prepare_header  sa   B)++A.// 	 1 1 3 3A 66=NE:dikk**D 01E<<]EM*$=$EFDM]E*C53u::#5E

#BCDENDMDJJu--.
 
D _DD t/077]E*;AA%#e**BTUU D r3   c                     	 t          t          ||f          \  }}nC#  t          t          j                    d d         }}t          t          ||f          \  }}Y nxY wt	          |dg           }t          |t                    rt          |t          t          f          rt          |dt                    g}t           j                                     t          j        |ft          dft          |fg          g fd|D             S )Nr   r   )r   r   c           	   3      K   | ]Q}t           j                                     t          t	          t          j        |          d           fg          V  RdS )noteN)r   rI   rJ   r   r   r   r   )r|   nr0   s     r1   r~   z-VerboseTB.format_exception.<locals>.<genexpr>  sq          D,-44\)*@*C*CVLLMN      r3   )mapr   r   exc_infor   rB   r   bytesr   r   r   rI   rJ   r   r   )r0   r$   r%   	etype_str
evalue_strnotess   `     r1   format_exceptionzVerboseTB.format_exception  s    	>$'eV_$=$=!Izz	>!36E$'eV_$=$=!Izzz R00%** 	Bje.M.M 	B!%4@@@AE ()00-+eT]UJ<OP 

    	  	

 
	
s	    >Ar%   r&   r<   c           	      x   |}	 |j         }n# t          $ r Y nw xY w|| j        n|}t          |t                    sJ |                     t          |          | j                  }|r|                     |||          ng }g }	d}
t          |          dz
  }t          |          D ]\  }}t          |j        t          j                  s3| j        r,|j        j                            dd          r||k    r|
dz  }
W|
rZ|	                    t&          | j                                     t,          dft,          j        d|
z  ft,          dfg                     d}
|	                    |                     |                     |
rX|	                    t&          | j                                     t,          dft,          j        d|
z  ft,          dfg                     |                     ||          }|r>|d         }t5                      }|&|j                            |j        |j        d           |g|	z   |z   gS )	zFormats the header, traceback and exception message for a single exception.

        This may be called multiple times by Python 3 exception chaining
        (PEP 3134).
        Nr   r   __tracebackhide__re   z[... skipping hidden %s frame]r*   )r   AttributeErrorr;   rB   rF   r  r   r   get_recordsrG   rf   r   r   r   r   r   f_localsgetrH   r   rI   rJ   r   r   r   r  r   r   r   ro   rc   )r0   r$   r%   r&   r<   r;   
orig_etyper  recordsframesskipped
lastrecordr   recordformatted_exceptionr   r   s                    r1   format_exception_as_a_wholez%VerboseTB.format_exception_as_a_whole  s    
	NEE 	 	 	D	 '0&7DNNY	)S)))))""3u::t/?@@?BJ$""3;;;\\A%
"7++ 	6 	6IAvvz:+DEE	$	
 L)--.A1EEZqLG 
 0188"FO"],Lw,VW"DM    MM$,,V445555 		MMD,-44(H7(RS    #33E6BB 	 J ]]F!44'):A   "5566s    
c                    |J |dz
  }|dz  }||z
  }| j         rOt          | j                                                 }t	          j        || j                  }t          |          }nd }t	          j        |||          }	|}
d}g }|
	 t          j
        |
j                  }|,|j        }|                    d          ^}}|dk    r|
j        }
Jt          |
j                  }n# t           $ r d}Y nw xY wt#          ||          }|                    |
           t'          |
dd           }
|
|t(          k    rMg }|D ]F}|j        }|j        }|j        }|j        }|                    t1          d	|||||
                     G|S t3          t          j                            ||	                    |d          }d |D             }|S )Nr   r   )style)beforeafterpygments_formatterr   .IPythontb_nextz	Raw frame)r<   )optionsc                 6    g | ]}t          j        |          S r{   )r   _from_stack_data_FrameInfo)r|   rs     r1   r   z)VerboseTB.get_records.<locals>.<listcomp>Q  s#    EEEA	4Q77EEEr3   )r   r   rI   as_pygments_styler   style_with_executing_nodetb_highlightr
   Optionsr   	getmoduletb_framer   r  r/  r   OSErrorr   rH   r   FAST_THRESHOLDf_linenof_codeco_filenamer   rE   )r0   r&   r<   r;   r+  r*  
base_styler)  	formatterr0  cfmax_lentbsmodmod_name	root_name_FIsr4   r   rc   r   ro   resres2s                            r1   r  zVerboseTB.get_records  s&   A+15? 	$T%56HHJJJ8TEVWWE,5999III$(
 
 
 '*n'44?"|H$,NN3$7$7MI I--Z 22;??   '7++GJJrNNNY--B n" ^###%C 
 
|+

#XvudG     
 J:'2232HHII)**UEEEEEs   AC( C( (C76C7r:   c                    |                      |||||          }t          dt                      d                   }t          | j                 }|                    t          j        |j        d         |z  fg          }	|	g}
d}d}| 	                    |          }|r(|J || 
                    |j                  z  }|\  }}}nd}t                      }|r||                      |||||          z  }| 	                    |          }|rct          |d                   |vrL|                    t          |d                              || 
                    |j                  z  }|\  }}}nd}|t          |          D ]}|
|z  }
|
S )z5Return a nice text document describing the traceback.r   r   r      Nr   )r'  r   r   r   rI   rJ   r   r  r  rP   rR   rS   rD   rQ   rT   reversed)r0   r$   r%   r&   r;   r<   formatted_exceptionstermsizer   r  structured_traceback_partsr\   lines_of_contextrZ   rV   fxs                   r1   rU   zVerboseTB.structured_tracebackT  s    150P0P631
 1
 r,..q122D,-LL MM*-8
 
 26"'($77??	 	%%% D$J$J % %   "+E633F%% 	 D$D$Dvs$46R% %   ;;FCCI 	R	!--_DD##y|$$   %(N(N$) ) $ &/"vss  	& /00 	- 	-B&",&&))r3   forcec                 6   |s| j         rz| j        |                                 | _        t          t          j                  }|5  | j                                         t          | d          r| j        | j        }nt          j	        x}| _        | j        >| j        j
        2| j        j
        J | j        j
        | _        | j        | j        j
        2|r|j
        r|j
        }|j        | j        _        t          j        dk     rt          j        nt          t          dt          j                  }|r| j                            d|           n| j                            d|           ddd           n# 1 swxY w Y   t          | d          r| `dS dS )a4  Call up the pdb debugger if desired, always clean up the tb
        reference.

        Keywords:

          - force(False): by default, this routine checks the instance call_pdb
            flag and does not actually invoke the debugger if the flag is false.
            The 'force' option forces the debugger to activate even if the flag
            is false.

        If the call_pdb flag is set, the pdb interactive debugger is
        invoked. In all cases, the self.tb reference to the current traceback
        is deleted to prevent lingering references which hamper memory
        management.

        Note that each call to pdb() does an 'import readline', so if your app
        requires a special setup for the readline completers, you'll have to
        fix that by hand after invoking the exception handler.N)hookr4   )rL     last_exc)r   pdbr   r   r   __displayhook__resetr   r4   last_tracebackr/  r9  botframeversion_info
last_valuer   interaction)r0   rS  display_trapr&   excs        r1   debuggerzVerboseTB.debugger  s   (  	4DM 	4x,,.. 'C,?@@@L 4 4   4&& 747+>'CC$'$66C$'g)dgo.I7?666"goDG g)dgo.I  &3; &+C$'L!
 ''11 NN j#.AA 
  4H((s3333H((s333/4 4 4 4 4 4 4 4 4 4 4 4 4 4 42 4 		 	s   D'E::E>E>c                 "   |pt          j                    \  }}}|| _        | j        }|                                 |                    |                     |||                     |                    d           |                                 d S r)   )r   r  r4   r+   r,   r-   r.   )r0   infor$   r%   r&   r+   s         r1   handlerzVerboseTB.handler  sy    #5s|~~,diivs33444dr3   c                     ||                                   n|                      |||f           	 |                                  dS # t          $ r t          d           Y dS w xY w)z@This hook can replace sys.excepthook (for Python 2.1 or higher).N
KeyboardInterrupt)re  rb  KeyboardInterruptprintr/   s       r1   r2   zVerboseTB.__call__  sx    ;LLNNNNLL%-...	)MMOOOOO  	) 	) 	)'((((((	)s   A A$#A$)Fr   r6   )NNN)r   r   r   r   r6  tb_highlight_styler   __annotations__r   r   boolr   rF   r   r   r   r   r   r  r  r   r   r   rE   r'  r  rU   rb  re  r2   __classcell__r   s   @r1   r   r     s        ' ' #L"JJJ
 #!!15$(>  &>  >  >  >  	> 
 >  >  >  >  b$h'$.>  Tk>  >  >  >  >  >  > @L	 Lc L L L L\" "C "t " " " " "H
 
 
6G7G7 'G7 m$	G7
 G7 C=G7 
d3iG7 G7 G7 G7R6} 6s 6s 6s 6 6 6 6x (,#':* :*:* ':* m$	:*
 C=:* :* 
c:* :* :* :*x4 4d 4t 4 4 4 4l   	) 	) 	) 	) 	) 	) 	) 	)r3   r   c                       e Zd ZU dZeed<   	 	 	 	 	 	 	 	 	 ddZ	 	 	 dd
ededz  de	dz  de
dz  de
dee         fdZdee         defdZddee         ddfdZddZddZddZddZdS )FormattedTBa  Subclass ListTB but allow calling with a traceback.

    It can thus be used as a sys.excepthook for Python > 2.1.

    Also adds 'Context' and 'Verbose' modes, not available in ListTB.

    Allows a tb_offset to be specified. This is useful for situations where
    one needs to remove a number of topmost frames from the traceback (such as
    occurs with python programs that themselves execute other python code,
    like Python shells).modePlainr   FNr   c
                     g d| _         | j         dd         | _        t                              | ||||||||		  	         t	          ddddd          | _        |                     |           d S )N)rr  ContextVerboseMinimalDocsr   rL  r   r   r+   r;   r   r   r   r   rA   r*   )valid_modesverbose_modesr   r   dict_join_charsset_mode)
r0   rq  r   r   r+   r;   r   r   r   r   s
             r1   r   zFormattedTB.__init__  s     NMM!-ac2!#%#% 	 
	
 
	
 
	
  dD"2
 
 
 	dr3   r:   r$   r%   r&   r;   r<   r'   c           
         || j         n|}| j        }|| j        v rt                              | |||||          S |dk    rQt          | j        | j        | j        || j	        | j
        | j        | j                                      ||||d          S |dk    rt                              | ||          S |                                  t                              | |||||          S )Nrw  rx  r   rv  )r;   rq  rz  r   rU   r   rI   r   r+   r   r   r   r   r#   r   )r0   r$   r%   r&   r;   r<   rq  s          r1   rU   z FormattedTB.structured_traceback  s    '0&7DNNY	y4%%%11eVS)W   V^^+# ,!. ,!.	 	 	 #"vsIq  Y,,T5&AAA ..eVS)W  r3   stbc                 6    | j                             |          S )4Convert a structured traceback (a list) to a string.)tb_join_charrN   r0   r  s     r1   stb2textzFormattedTB.stb2text:  s     %%c***r3   c                    |sJ| j                             | j                  dz   t          | j                   z  }| j         |         | _        nQ|| j         vr*t	          d|z   dz   t          | j                   z             t          |t
                    sJ || _        | j        | j         d         k    | _        | j        | j                 | _	        dS )zbSwitch to the desired mode.

        If mode is not specified, cycles through the available modes.r   z#Unrecognized mode in FormattedTB: <z>
Valid modes: r   N)
ry  r   rq  rG   
ValueErrorr   rB   r   r|  r  )r0   rq  new_idxs      r1   r}  zFormattedTB.set_mode>  s    
  
	'--di881<DDT@U@UUG(1DII)))5< @   "%d&6"7"78  
 dC(((((DI I)9!)<< ,TY7r3   c                 F    |                      | j        d                    d S Nr   r}  ry  r0   s    r1   plainzFormattedTB.plainT  "    d&q)*****r3   c                 F    |                      | j        d                    d S )Nr   r  r  s    r1   r<   zFormattedTB.contextW  r  r3   c                 F    |                      | j        d                    d S )Nr   r  r  s    r1   verbosezFormattedTB.verboseZ  r  r3   c                 F    |                      | j        d                    d S )NrL  r  r  s    r1   minimalzFormattedTB.minimal]  r  r3   )	rr  r   FNr   FFNNr   r6   )r'   N)r   r   r   r   r   rk  r   r   r   r   rF   rE   rU   r  r   r}  r  r<   r  r  r{   r3   r1   rp  rp    so        	 	 III # # # #R %) $' '' $' T!	'
 :' ' 
c' ' ' 'R+DI +# + + + +8 8Xc] 8d 8 8 8 8,+ + + ++ + + ++ + + ++ + + + + +r3   rp  c                       e Zd ZdZ	 	 	 	 	 ddedz  dedz  dedz  dededz  ddfd	Z		 	 	 ddede
e         de
e         de
e         dedee         fdZdS )AutoFormattedTBaF  A traceback printer which can be called on the fly.

    It will find out about exceptions by itself.

    A brief example::

        AutoTB = AutoFormattedTB(mode = 'Verbose', theme_name='linux')
        try:
          ...
        except:
          AutoTB()  # or AutoTB(out=logfile) where logfile is an open file object
    Nr$   r%   r&   outr;   r'   c                 R   || j         }|                                 |                    |                     ||||                     |                    d           |                                 	 |                                  dS # t
          $ r t          d           Y dS w xY w)aI  Print out a formatted exception traceback.

        Optional arguments:
          - out: an open file-like object to direct output to.

          - tb_offset: the number of frames to skip over in the stack, on a
          per-call basis (this overrides temporarily the instance's tb_offset
          given at initialization time.Nr*   rg  )r+   r,   r-   r.   rb  rh  ri  )r0   r$   r%   r&   r  r;   s         r1   r2   zAutoFormattedTB.__call__p  s    " ;,C				$))E63	::;;;		$			)MMOOOOO  	) 	) 	)'((((((	)s   3B	 	B&%B&r:   r<   c                     |t          j                    \  }}}t          |t                    r|d         | _        n|| _        t
                              | |||||          S r  )r   r  rB   rC   r4   rp  rU   )r0   r$   r%   r&   r;   r<   s         r1   rU   z$AutoFormattedTB.structured_traceback  sf     =!$E63c5!! 	!fDGGDG//%i
 
 	
r3   )NNNNNr   )r   r   r   r   r   r   r   r   rF   r2   r   rE   r   rU   r{   r3   r1   r  r  b  s         "'+$( $) )d{) $) T!	)
 ) :) 
) ) ) )D (,#'
 

 '
 m$	

 C=
 
 
c
 
 
 
 
 
r3   r  c                   "     e Zd ZdZ fdZ xZS )ColorTBzDeprecated since IPython 9.0.c                 r    t          j        dt          d            t                      j        |i | d S )NzNDeprecated since IPython 9.0 use FormattedTB directly ColorTB is just an aliasr   )r   )r   r   r   r   r   )r0   r   kwargsr   s      r1   r   zColorTB.__init__  sI    \	
 	
 	
 	
 	$)&)))))r3   )r   r   r   r   r   rm  rn  s   @r1   r  r    s>        ''* * * * * * * * *r3   r  c                        e Zd ZU dZedz  ed<    fdZ fdZ	 	 	 ddededz  d	e	dz  d
e
dz  de
dee         f fdZdedz  fdZdee         defdZ xZS )SyntaxTBz:Extension which holds some state: the last exception valueNlast_syntax_errorc                Z    t                                          |           d | _        d S )Nr   )r   r   r  )r0   r   r   s     r1   r   zSyntaxTB.__init__  s,    J///!%r3   c                 \    || _         t                                          |||           d S r6   )r  r   r2   )r0   r$   rt   rW   r   s       r1   r2   zSyntaxTB.__call__  s-    !&u-----r3   r:   r$   r%   r&   r;   r<   r'   c                    |}t          |t                    rut          |j        t                    r[t          |j        t
                    rAt          j        |j                   t          j        |j        |j                  }|r||_	        || _
        t          t          |                               |||||          S )N)r;   r<   )rB   r   ro   r   rc   rF   r   r   r   r.   r  r   r  rU   )	r0   r$   r%   r&   r;   r<   rt   newtextr   s	           r1   rU   zSyntaxTB.structured_traceback  s     
 uk**	%5>3//	% 5<--	%
  000'EEG %$
!&Xt$$995#G : 
 
 	
r3   c                 "    | j         }d| _         |S )z+Return the current error state and clear itN)r  )r0   es     r1   clear_err_statezSyntaxTB.clear_err_state  s    "!%r3   r  c                 ,    d                     |          S )r  rA   )rN   r  s     r1   r  zSyntaxTB.stb2text  s    wws||r3   r   )r   r   r   r   r   rk  r   r2   r   r   rF   rE   r   rU   r   r  r  rm  rn  s   @r1   r  r    s)        DD$t++++& & & & &. . . . . %) $
 

 $
 T!	

 :
 
 
c
 
 
 
 
 
4t    DI #        r3   r  )>r   	functoolsr   r   r   r  r7   r   r   collections.abcr   r   typingr   r   r   r   r	   r   pygments.formatters.terminal256r
   pygments.tokenr   r.  r   IPython.utilsr   r   r   IPython.utils.PyColorizer   r   r   r   IPython.utils.terminalr   r`  r   doctbr   tbtoolsr   r   r   r   r   r   r   r   r   r    r   r;  r#   objectr   r   r   rp  r  r  r  r{   r3   r1   <module>r     s5  : :H          



        $ $ $ $ $ $       7 7 7 7 7 7 7 7 7 7 7 7 7 7     @ @ @ @ @ @                   + + + + + + # # # # # # L L L L L L L L L L L L 4 4 4 4 4 4 % % % % % %                               ~D ~D ~D ~D ~DW ~D ~D ~DB
 FHH	a) a) a) a) a) a) a) a)J@+ @+ @+ @+ @+)V @+ @+ @+H>
 >
 >
 >
 >
k >
 >
 >
J
* 
* 
* 
* 
*k 
* 
* 
*0 0 0 0 0v 0 0 0 0 0r3   