
    Ǆg?(                         d dl mZ d dlmZmZ d dlZd dlZd dlZd dlZd dl	Z
ej                  d        ZdddZdddd	Zd
 Z G d d      Zd Zy)    )TracebackType)ListOptionalNc               #     K   	 d  y # t         $ r} | j                  }g }||j                  j                  j                  }|j                  j
                  j                  d      }|dk(  rE|Bt        j                  ddd      5 }|j                  |       d d d        n# 1 sw Y   nxY w|j                  }t        dj                  d      }|j                  |j                  j                  	      }t        |j                  d
      r;|j                  |j                  j                  |j                  j                         }t#        ||j
                  i |j$                  dt&        j(                  i      }t+        d ||j,                  |j.                        }	|j1                  |	       n|j1                  |       |j2                  }|d }
t5        |      D ]  }|
|_        |}
 | j7                  |
      d } ~ ww xY ww)N__compile_source__z<string>wFz.py)modedeletesuffixz__inspect_currentframe()eval)co_nameco_linetable)r   co_firstlineno__inspect_currentframe)	Exception__traceback__tb_framef_codeco_filename	f_globalsgettempfileNamedTemporaryFilewritecompilenamereplacer   hasattrr   r   r   f_localsinspectcurrentframer   tb_lasti	tb_linenoappendtb_nextreversedwith_traceback)exctbstackfilenamesourcefframecode
fake_framefake_tbr%   s              ^/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/utils/_traceback.pyreport_compile_source_on_errorr3   /   s    S* Q* n{{))55H[[**../CDF:%&*<2 00c%PUV $Z[GGFO$ $ $ 91666J||ELL,@,@|A5<<8  <<%*\\%>%>',||'B'B ( D "OO..0'2F2F
 (*bkk2<< W%R BG nL 5/ 	B BJG	   ))cQ*sD   H		 H	
HA7H
B%	H%B.	*D)H,HHH	basec                   |@t         j                  j                  t         j                  j                  t                    }	 t         j                  j	                  | |g      }| t        |      dz   d S # t        $ r | cY S w xY w)ziShorten a source filepath, with the assumption that torch/ subdirectories don't need to be shown to user.N   )ospathdirname__file__
commonpathlen
ValueError)fnr5   prefixs      r2   shorten_filenamerA      sq    |wwrwwx89$##RJ/ #f+/"##  	s   !A6 6BBF)r5   linec                    d}|r| j                    d}| t        | j                  |       d| j                   d| j                   S )z
    Format a FrameSummary in a short way, without printing full absolute path or code.

    The idea is the result fits on a single line.
     z  # r4   :z in )rB   rA   r+   linenor   )r.   r5   rB   
extra_lines       r2   format_framerH      sQ     J

|4(
\*5>>EFa~UYZ_ZdZdYeff    c                 D    t        t        j                  |       d         S )zJFormat a TracebackType in a short way, printing only the inner-most frame.)rH   	traceback
extract_tbr)   s    r2   format_traceback_shortrO      s    	,,R0455rI   c                   ^    e Zd ZddgZddZd Zd Zd Zedddd	d
       Z	d Z
ed        Zy)CapturedTracebackr)   skipr   c                      || _         || _        y Nr)   rR   )selfr)   rR   s      r2   __init__zCapturedTraceback.__init__   s    	rI   c                     d | _         y rT   rN   rV   s    r2   cleanupzCapturedTraceback.cleanup   s	    rI   c                     dd l }| j                  t        j                         S t	        |j
                  j                  j                  | j                  g      d   | j                        S )Nr   )	torch._C._profilerr)   rL   StackSummary_extract_symbolized_tb_C	_profilersymbolize_tracebacksrR   )rV   torchs     r2   summaryzCapturedTraceback.summary   sT    !77?))++%HH33TWWI>qAII
 	
rI   c                 $    d d | j                   dfS )NrU   )rR   rY   s    r2   __getstate__zCapturedTraceback.__getstate__   s    II
  	rI   F)scriptcpprR   c                     ddl }| s|r|dk(  sJ d       t        |j                  j                  j	                  d| |      | s|rd      S |dz         S )a  
        Like traceback.extract_stack(), but faster (approximately 20x faster); it
        is fast enough that you can unconditionally log stacks this way as part of
        normal execution.  It returns a torch._C._profiler.CapturedTraceback
        object that must be formatted specially with format_captured_tb.

        By default, this only reports Python backtraces (like extract_stack).  You
        can set the script/cpp kwargs to also turn on TorchScript/C++ trace
        reporting.
        r   Nzskip with script/cpp NYIT)pythonrf   rg   r7   )r\   rQ   r_   r`   gather_traceback)rf   rg   rR   rb   s       r2   extractzCapturedTraceback.extract   sg     	"S198889 HH//tFPS/T 3A	
 	
 %)1H	
 	
rI   c                 H    t        j                  | j                               S )al  
        Formats a single torch._C._profiler.CapturedTraceback into a list of
        strings equivalent to the output of traceback.format_list.  Note that if
        pass it CapturedTraceback with C++ traces,  it is better not to use this
        function and use the batch formatting API format_captured_tbs to amortize
        the cost of symbolization
        )rL   format_listrc   rY   s    r2   formatzCapturedTraceback.format   s     $$T\\^44rI   c                    ddl }g }g }t        |       D ]E  \  }}|j                  |j                  g        $|j                  d       |j                  |       G |j                  j
                  j                  |D cg c]  }| |   j                   c}      }t        ||      D ].  \  }}t        j                  | |   j                               ||<   0 |S c c}w )z_
        Bulk version of CapturedTraceback.format.  Returns a list of list of strings.
        r   N)r\   	enumerater)   r$   r_   r`   ra   ziprL   rm   rc   )tbsrb   rsdelayed_idxsir)   stbsstbs           r2   
format_allzCapturedTraceback.format_all   s    
 	" )+s^ 	'EAruu}		"		$##A&	' xx!!66<7XaA		7XY,- 	<FAs))#a&..*:;BqE	< 		 8Ys   ?CN)r   )__name__
__module____qualname__	__slots__rW   rZ   rc   re   staticmethodrk   rn   rx    rI   r2   rQ   rQ      sS    vI

 U 
 
.5  rI   rQ   c           	          t        j                         }t        | |d       D ]1  }|j                  t        j                  |d   |d   |d                3 |S )z
    Given a symbolized traceback from symbolize_tracebacks, return a StackSummary object of
    pre-processed stack trace entries.
    Nr+   rB   r   )rL   r]   r&   r$   FrameSummary)r)   rR   r*   r-   s       r2   r^   r^      sZ    
 ""$Ebi  RY++AjM1V9aiPQRLrI   )typesr   typingr   r   r   rL   
contextlibr    os.pathr8   contextmanagerr3   rA   rH   rO   rQ   r^   r~   rI   r2   <module>r      sf     !     N T* T*l "& 
$ !%5 	g6S SlrI   