+
    ^|iB                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
 ^ RIHt ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHtHtHt ]! 4       t^t] P>                  R R l4       t R R lt!]"3R R llt#R R lt$R R lt%]%3R R llt&]%3R R llt'RR/R R llt(R R lt) ! R R4      t* ! R  R!4      t+R# )"    N)TracebackType)AnyOptionalTuple)Callable)Token)get_ipython)debugger)path)	py3compat)ThemeTokenStreamtheme_tablec                0    V ^8  d   QhR\         R\        /# )   filenamereturn)strint)formats   "6/usr/lib/python3/dist-packages/IPython/core/tbtools.py__annotate__r      s      S S     c                    V P                  R4      '       g   ^ #  \        V R4      ;_uu_ 4       p\        R V 4       4      pRRR4       V#   + '       g   i     X# ; i  \         d     ^ # i ; i)zv
Given a filename, returns the number of lines in the file
if it ends with the extension ".py". Otherwise, returns 0.
z.pyrc              3   &   "   T F  p^x  K	  	  R# 5i)   N ).0lines   & r   	<genexpr>)count_lines_in_py_file.<locals>.<genexpr>#   s     +ddds   N)endswithopensumUnicodeError)r   filess   &  r   count_lines_in_py_filer)      sk     U##	h$$+d++ % H	 %$ H  		s.   A  AA  A	A  A   A/.A/c                D    V ^8  d   QhR\         P                  R\        /# )r   framer   )types	FrameTyper   )r   s   "r   r   r   )   s     , ,EOO , ,r   c                    V P                   P                  pVf6   \        R4       \        P                  ! V 4      w  r#V\        V4      ,           # \        V4      # )a  
Given a frame object, returns the total number of lines in the file
containing the frame's code object, or the number of lines in the
frame's source code if the file is not available.

Parameters
----------
frame : FrameType
    The frame object whose line number is to be determined.

Returns
-------
int
    The total number of lines in the file containing the frame's
    code object, or the number of lines in the frame's source code
    if the file is not available.
zNo file....)f_codeco_filenameprintinspectgetsourcelineslenr)   )r+   r   linesfirsts   &   r   get_line_number_of_framer7   )   sM    $ ||''Hm--e4s5z!!!(++r   c                H    V ^8  d   QhR\         R\         R\         R\        /# )r   valuewhatfuncr   r   r   )r   s   "r   r   r   C   s(     4 4 43 4c 4C 4r   c                 H     V! V 4      #    R T RTP                    R2u # ; i)< z
() failed>)__name__)r9   r:   r;   s   &&&r   _safe_stringrA   C   s1    4E{44&$--
33s   
 !c          
          V ^8  d   QhR\         \        P                  ,          R\        R\        R\         \
        ,          R\
        /# )r   r5   theme
has_colors
lvals_toksr   )list
stack_dataLiner   boolr   )r   s   "r   r   r   K   sH     4 4
 44 4 [!	4
 4r   c                   \         ^,
          p. pV  EF  pV\        P                  J d'   \        P                  R3.pVP                  V4       K>  VP                  pVP                  VR7      P                  R4      R,           p	VP                  '       dg   V\        \        V4      4      ,
          p
\        P                  VP                  V
4      3\        P                  \        V4      3\        R3\        V	3.pM4RWH3,          p\        P                  \        V4      3\        R3\        V	3.pVP                  V4       V'       g   EK:  VP                  '       g   EKO  V FM  pVP                  \        R\         ,          34       VP                  V4       VP                  \        R34       KO  	  VRR pEK  	  V# )z
Format tracebacks lines with pointing arrow, leading numbers,
this assumes the stack have been extracted using stackdata.


Parameters
----------
lines : list[Line]
z   (...))	pygmented
r?   %*sN)INDENT_SIZErG   LINE_GAPr   LinenoEmextendlinenorenderrstrip
is_currentr4   r   
make_arrowappend)r5   rC   rD   rE   numbers_widthtokens
stack_linetoksrS   r    padnumlvs   &&&&         r   _format_traceback_linesr`   K   sw     !OMF
,,,^^Z01DMM$""  : 6==dCdJ   #c&k"22C!1!1#!67V-	D =11CS*D 	d:*/// ucK&789b!udm, !
 CR[FA D Mr   c                0    V ^8  d   QhR\         R\        /# )r   r9   r   r<   )r   s   "r   r   r      s     4 4S 4S 4r   c                p    \         P                  P                  V 4      #   \         d    h   \        T 4      u #   \         d    h   \	        T RR4      pT'       d   \        T4      u u # \	        T RR4      pT'       d   R\        T4      ,          u u #   R#   \         d    h     R# ; i; i; i)z(Hopefully pretty robust repr equivalent.r@   N	__class__z%s instancezUNRECOVERABLE REPR FAILURE)pydoctextreprKeyboardInterruptgetattr	text_repr)r9   nameklasss   &  r   ri   ri      s    4zzu%% 4	4;  		44 uj$7$T?*{D9(9U+;;;3$ 43s_   ! B5
<B5B2
B)B2*B5.&BB2B5B5B/*B2+B5/B22B5c                `    V ^8  d   QhR\         R\        \         .\        3,          R\        /# r   r9   rf   r   r   r   r   )r   s   "r   r   r      s,      # XseSj1 # r   c                      R V! V 4      ,          # )z=%sr   r9   rf   s   &&r   eqreprrq      s    4;r   c                `    V ^8  d   QhR\         R\        \         .\        3,          R\        /# rm   rn   )r   s   "r   r   r      s,      C xs
3 C r   c                     R # ) r   rp   s   &&r   nullreprru      s    r   rS   c                d    V ^8  d   QhR\         R\        R,          R\        R,          R\        /# )r   emr'   NrS   r   )rI   r   r   r   )r   s   "r   r   r      s8     0 00
*0 $J	0
 0r   c                  V '       d   \         P                  M\         P                  pV '       d   \         P                  M\         P                  p\        4       pVe@   VP                  P                  V4      ;pe!   Vw  rxVf
   W73VR3WH3.# W73VR3WH3VRV 23.# \        P                  ! \        P                  ! V\        P                  4      4      pVf   VR3WH3.# VR3WH RV 23.# )z
Format filename lines with custom formatting from caching compiler or `File *.py` by default

Parameters
----------
em: wether bold or not
file : str
r?   z, line zFile :)r   NormalEmNormal
FilenameEmFilenamer	   compileformat_code_name	util_pathcompress_userr   cast_unicodefs_encoding)	rw   r'   rS   r{   r}   ipinstdatalabelrj   s	   &&$      r   _tokens_filenamer      s     "U^^u||F#%u5>>H]F^^44T::TG>    WVH-.	  &&""4)>)>?
 >!   !V1VH-. r   c                    V ^8  d   QhR\         R\         R\        \        \        \        \        \        3,          3,          ,          R\        \
        ,          R\        R\
        /# )r   lnumindexr5   rE   rC   r   )r   rF   tupler   rI   r   r   )r   s   "r   r   r      sa     = =
== c5d++,-= [!	=
 = =r   c                   V FC  p\        V\        4      '       g   Q hV F"  p\        V^,          \        4      '       d   K"  Q h	  KE  	  \        ^,
          p. p\	        W V,
          4       F  w  p	w  p
w  rV'       g   Tp
T
pW8X  dg   V\        \        V	4      4      ,
          p\        P                  VP                  V4      3\        P                  \        V 4      3\        R3\        V3.pM+RWy3,          p\        P                  V3\        R3\        V3.pVP                  V4       V'       g   K  W8X  g   K  V F  pVP                  V4       K  	  K  	  V# )a  
Format tracebacks lines with pointing arrow, leading numbers

This should be equivalent to _format_traceback_lines, but does not rely on stackdata
to format the lines

This is due to the fact that stackdata may be slow on super long and complex files.

Parameters
==========

lnum: int
    number of the target line of code.
index: int
    which line in the list should be highlighted.
lines: list[string]
lvals_toks: pairs of token type and str
    Values of local variables, already colored, to inject just after the error line.
r?   rM   )

isinstancerF   r   rO   	enumerater4   r   rQ   rW   rR   )r   r   r5   rE   rC   itemsubitrY   res_toksir    new_lineerrcolored_liner]   	line_tokspadding_numr_   s   &&&&&             r   _simple_format_traceback_linesr      s:   4 $%%%%EeAh,,,,  
  !OMH&/e|&D""D/8D9#c!f+-C!1!1#!67T+%	I  ="44K -%I
 		":!) # !3 'E8 Or   c                      a  ] tR tRt o Rt]V 3R lR l4       tRRRR/V 3R lR	 llt]V 3R
 lR l4       t	]V 3R lR l4       t
]V 3R lR l4       tV 3R ltRtV tR# )	FrameInfoi  za
Mirror of stack data's FrameInfo, but so that we can bypass highlighting on
really long frames.
c                   < V ^8  d   QhRS[ P                  P                  S[ P                  P                  ,          RR/# )r   
frame_infor   r   )rG   corer   RepeatedFrames)r   __classdict__s   "r   r   FrameInfo.__annotate__,  s6     
 
#22Z__5S5SS
	
r   c                    V ! \        VR R4      \        VRR4      \        VRR4      \        VRR4      \        VRR4      VRR7      # )descriptionNr   rS   r+   code)sdcontextrh   )clsr   s   &&r   _from_stack_data_FrameInfo$FrameInfo._from_stack_data_FrameInfo+  sS     Jt4J
D1J$/J.J-
 	
r   r   Nr   c                   < V ^8  d   QhRS[ S[,          RS[RS[RS[RS[ S[P
                  ,          RS[RS[R,          /# )	r   r   r   rS   r+   r   r   r   N)r   r   r   r   r,   CodeType)r   r   s   "r   r   r   9  sb      c]  	
  u~~&  tr   c               0   \        V\        \        R 4      34      '       g   Q V4       hWn        W n        W0n        W@n        WPn        W`n        Wpn	        Vf&    \        P                  ! V4      ^ ,          V n        R # R #   \         d    R.T n         R # i ; i)NzG'Could not get source, probably due dynamically evaluated source code.')r   r   typer   r   rS   r+   r   _sdr   r2   r3   	raw_linesOSError)selfr   r   rS   r+   r   r   r   s   &&&&&&$$r   __init__FrameInfo.__init__9  s     &3T
"344<f<4& 
	 :!(!7!7!>q!A   ]"s   "A> >BBc                0   < V ^8  d   QhRS[ S[,          /# r   r   rF   r   )r   r   s   "r   r   r   X  s      d3i r   c                N    V P                   e   V P                   P                  # . # N)r   variables_in_executing_piecer   s   &r   r   &FrameInfo.variables_in_executing_pieceW  s!    8888888Ir   c                0   < V ^8  d   QhRS[ S[,          /# r   r   )r   r   s   "r   r   r   _  s      tCy r   c                    ^ RI Hp V P                  f   Q h V P                  P                  #   T d     ! R R4      pT! 4       .u # i ; i)r   )NotOneValueFoundc                   :   a  ] tR tRt o ^ tRtV 3R lR ltRtV tR# )FrameInfo.lines.<locals>.Dummyig  Fc                &   < V ^8  d   QhRS[ RS[/# )r   rK   r   )rI   r   )r   r   s   "r   r   +FrameInfo.lines.<locals>.Dummy.__annotate__k  s     f ft f fr   c                   R # )zH<Error retrieving source code with stack_data see ipython/ipython#13598>r   )r   rK   s   &$r   rT   %FrameInfo.lines.<locals>.Dummy.renderk  s    er   r   N)	r@   
__module____qualname____firstlineno__rS   rV   rT   __static_attributes____classdictcell__r   s   @r   Dummyr   g  s     "
f fr   r   )executing.executingr   r   r5   )r   r   r   s   &  r   r5   FrameInfo.lines^  sO    8xx###	88>>! 		f f G9		s   . A
	A
c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r   q  s      3 r   c                N    V P                   e   V P                   P                  # R # r   )r   	executingr   s   &r   r   FrameInfo.executingp  s    8888%%%r   c                   < V ^8  d   Qh/ S[ S[,          ;R&   S[ S[,          ;R&   S[;R&   S[ S[,          ;R&   S[S[,          ;R&   S[P
                  P                  ;R&   S[;R&   # )r   r   r   rS   r   r   r   r+   )r   r   r   rF   rG   r   r   r   )r   r   s   "r   r   r     sx      #  sm  K  c]  Cy  
	"	""  J r   )r   r   r   r   r   r+   rS   r   )r@   r   r   r   __doc__classmethodr   r   propertyr   r5   r   __annotate_func__r   r   r   s   @r   r   r     s      
 
  # <    "  k  r   r   c                   n  a a ] tR tRt oRt^ t]RR3RRRR/V3R lV 3R	 lllltV3R
 lR ltV3R lR lt	]
! ]]	4      t]V3R lR l4       tV3R lR ltV3R lR lt]
V3R lR l4       tV3R lR ltV3R lR ltV3R lR ltV3R lR ltR$V3R lR lltR%V3R  lR! lltV3R" ltR#tVtV ;t# )&TBToolsix  z2Basic tools used by all traceback printer classes.FNdebugger_cls
theme_namenocolorc          
      F   < V ^8  d   QhRS[ RS[RS[ RS[R,          RS[/# )r   color_schemecall_pdbostreamr   Nr   )r   rI   r   r   )r   r   s   "r   r   TBTools.__annotate__  sA     - -- - 	- Tk- -r   c                  < V\         Jd=   \        V\        4      '       g   Q V4       h\        P                  ! R \
        ^R7       TpVR9   d@   \        P                  ! RVP                  4        R2\
        ^R7       VP                  4       p\        SV `!  4        W n	        W0n
        V P                  V4       T;'       g    \        P                  V n        V'       d   V P                  4       V n        R# RV n        R# )zScolor_scheme is deprecated since IPython 9.0, use theme_name instead, all lowercase
stacklevelz?Theme names and color schemes are lowercase in IPython 9.0 use z insteadN)LinuxLightBGNeutralNoColor)	_sentinelr   r   warningswarnDeprecationWarninglowersuperr   r   _ostreamset_theme_namer
   Pdbr   pdb)r   r   r   r   r   r   rc   s   &&&&$$r   r   TBTools.__init__  s     y(lC00>,>0MMe"
 &JCCMMQR\RbRbRdQeemn"
 $))+J 	    	J'(88HLL((*DHDHr   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r     s     F Fc Fr   c                V    V P                   f   \        P                  # V P                   # )aC  Output stream that exceptions are written to.

Valid values are:

- None: the default, which means that IPython will dynamically resolve
  to sys.stdout.  This ensures compatibility with most tools, including
  Windows (where plain stdout doesn't recognize ANSI escapes).

- Any object with 'write' and 'flush' attributes.
)r   sysstdoutr   s   &r   _get_ostreamTBTools._get_ostream  s      "]]2szzEEr   c                   < V ^8  d   QhRR/# r   r   Nr   )r   r   s   "r   r   r     s      4 r   c                f    Ve'   \        VR4      '       d   \        VR4      '       g   Q hWn        R # )Nwriteflush)hasattrr   )r   vals   &&r   _set_ostreamTBTools._set_ostream  s*    {wsG44g9N9NOOr   c                &   < V ^8  d   QhRS[ RS[ /# )r   exception_valuer   r   )r   r   s   "r   r   r     s     = = = =r   c                t    \        V R R4      pV'       d   V# \        V RR4      '       d   R# \        V RR4      # )	__cause__N__suppress_context__F__context__r   )r  causes   & r   _get_chained_exceptionTBTools._get_chained_exception  s:    d;L?$:EBBt<<r   c                ^   < V ^8  d   QhRS[ R,          RS[S[S[S[ S[3,          ,          /# )r   evalueNr   )BaseExceptionr   r   r   r   )r   r   s   "r   r   r     s3      #d*	%m]:;	<r   c                j    V P                  V4      pV'       d   VP                  VVP                  3# R # r   )r
  rc   __traceback__)r   r  chained_evalues   && r   get_parts_of_chained_exception&TBTools.get_parts_of_chained_exception  s;     44V<((,, 
 r   c                T   < V ^8  d   QhRS[ R,          RS[S[S[,          ,          /# )r   r	  Nr   )r  rF   r   )r   r   s   "r   r   r     s*      "T)	d3ir   c                2    R pRpV'       d   V..pV# V..pV# )zF
The above exception was the direct cause of the following exception:
zE
During handling of the above exception, another exception occurred:
r   )r   r	  direct_causeexception_during_handlingmessages   &&   r   !prepare_chained_exception_message)TBTools.prepare_chained_exception_message  s@     W 	 V 	" $~&G  223Gr   c                    < V ^8  d   QhRS[ /# r   )rI   )r   r   s   "r   r   r     s     - -D -r   c                v    V P                   V P                   P                  4       8X  g   Q hV P                   R 8g  # )r   )_theme_namer   r   s   &r   rD   TBTools.has_colors  s6    4#3#3#9#9#;;;;9,,r   c                $   < V ^8  d   QhRS[ RR/# r   rj   r   Nr   )r   r   s   "r   r   r     s     * *3 *4 *r   c                    V\         9   g   Q hVP                  4       V8X  g   Q hWn        \        V R 4      '       d.   V P                  e   V P                  P                  V4       R# R# R# )r   N)r   r   r  r   r   r   r   rj   s   &&r   r   TBTools.set_theme_name  sZ    {"""zz|t###4DHH$8HH##D) %9r   c                $   < V ^8  d   QhRS[ RR/# r   r!  )r   r   s   "r   r   r     s     	" 	"s 	"t 	"r   c                b    \         P                  ! R\        ^R7       V P                  V4       R# )z;Shorthand access to the color table scheme selector method.zFset_colors is deprecated since IPython 9.0, use set_theme_name insteadr   N)r   r   r   r   r#  s   &&r   
set_colorsTBTools.set_colors  s)     	T	

 	D!r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     ) )d )r   c                ~    V P                   R8X  d   V P                  V n         R# V P                   V n        RV n         R# )z=Toggle between the currently active color scheme and nocolor.r   N)r  _old_theme_namer   s   &r   color_toggleTBTools.color_toggle  s4    y(#33D#'#3#3D (Dr   c                6   < V ^8  d   QhRS[ S[,          RS[/# )r   stbr   )rF   r   )r   r   s   "r   r   r     s      DI # r   c                $    RP                  V4      # )z4Convert a structured traceback (a list) to a string.rL   )join)r   r/  s   &&r   stb2textTBTools.stb2text  s    yy~r   c                j   < V ^8  d   QhRS[ RS[R,          RS[R,          RS[S[,          RS[RS[/# )r   etyper9   Ntb	tb_offsetr   r   )r   r  r   r   r   r   )r   r   s   "r   r   r     sU     & && t#& D 	&
 C=& & 
&r   c                J    V P                  WW4V4      pV P                  V4      # )zWReturn formatted traceback.

Subclasses may override this if they add extra arguments.
)structured_tracebackr2  )r   r5  r9   r6  r7  r   tb_lists   &&&&&& r   re   TBTools.text  s'     ++E"Q}}W%%r   c                |   < V ^8  d   QhRS[ RS[R,          RS[S[,          RS[S[,          RS[RS[S[,          /# )r   r5  r  Netbr7  r   r   )r   r  r   r   r   rF   r   )r   r   s   "r   r   r     sY     $ $$ $$ m$	$
 C=$ $ 
c$r   c                    \        4       h)zGReturn a list of traceback frames.

Must be implemented by each class.
)NotImplementedError)r   r5  r  r=  r7  r   s   &&&&&&r   r9  TBTools.structured_traceback  s     "##r   c                b   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   S[;R&   S[;R&   S[;R&   S[;R&   # )r   r  r+  r   r   r   r   )r   rI   r   )r   r   s   "r   r   r   x  sP     
     N  L    
H r   )r+  r   r  r   r   r   )N   )NNrB  )r@   r   r   r   r   r7  r   r   r   r  r   r   staticmethodr
  r  r  rD   r   r'  r,  r2  re   r9  r   r   r   __classcell__)rc   r   s   @@r   r   r   x  s     < I &	- %)- $- -^F F  |\2G= =    - -* *	" 	") ) & &$ $O  r   r   ),	functoolsr2   rd   r   r,   r   r   typingr   r   r   collections.abcr   rG   pygments.tokenr   IPythonr	   IPython.corer
   IPython.utilsr   r   r   IPython.utils.PyColorizer   r   r   objectr   rO   	lru_cacher)   r7   r   rA   r`   ri   rq   ru   r   r   r   r   r   r   r   <module>rO     s       
    ' ' $     ! + # D DH	   ,4 58 44p4< 5>  7@ 0 	0f=@Y Yxs$ s$r   