
    Yh(                         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	 e j
        d             ZdddZdddd	Zd
 Z G d d          Zd ZdS )    N)TracebackType)Optionalc               #     K   	 d V  d S # t           $ r} | j        }g }|w|j        j        j        }|j        j                            d          }|dk    r!|t          j        ddd          5 }|	                    |           d d d            n# 1 swxY w Y   |j        }t          d|j        d          }|                    |j        j        	          }t          |j        d
          r+|                    |j        j        |j        j                  }t#          ||j        i |j        dt&          j        i          }t+          d ||j        |j                  }	|                    |	           n|                    |           |j        }|wd }
t5          |          D ]}|
|_        |}
|                     |
          d } ~ ww xY 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              h/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/utils/_traceback.pyreport_compile_source_on_errorr2   1   s<     P* N* N* N* n{)5H[*../CDDF:%%&*<2 0U5   $GGFOOO$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 9166JJ||EL,@|AA5<88   <<%*\%>',|'B (  D "OVu~V'?AUVV 

 (j"+r|TTW%%%%R   BA nF 5// 	 	B BJGG  )))]N*s:   
 GAG
2BG
B	G
B	D.G

Gbasec                $   |At           j                            t           j                            t                              }	 t           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)fnr4   prefixs      r1   shorten_filenamer@      s    |wrwx8899%##RJ// #f++/##$$    			s   !B   BBF)r4   linec                r    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  # r3   :z in )rA   r@   r*   linenor   )r-   r4   rA   
extra_lines       r1   format_framerG      sX     J )
(((
f*5>EEEffffZ_Zdfff    c                 P    t          t          j        |           d                   S )zJFormat a TracebackType in a short way, printing only the inner-most frame.)rG   	traceback
extract_tbr(   s    r1   format_traceback_shortrN      s     	,R004555rH   c                   l    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dS )CapturedTracebackr(   skipr   c                 "    || _         || _        d S Nr(   rQ   )selfr(   rQ   s      r1   __init__zCapturedTraceback.__init__   s    			rH   c                     d | _         d S rS   rM   rU   s    r1   cleanupzCapturedTraceback.cleanup   s    rH   c                     dd l }| j        t          j                    S t	          |j        j                            | j        g          d         | j                  S )Nr   )	torch._C._profilerr(   rK   StackSummary_extract_symbolized_tb_C	_profilersymbolize_tracebacksrQ   )rU   torchs     r1   summaryzCapturedTraceback.summary   sY    !!!!7?)+++%H33TWI>>qA49
 
 	
rH   c                     d d | j         dfS )NrT   )rQ   rX   s    r1   __getstate__zCapturedTraceback.__getstate__   s!    	 
 	
rH   F)scriptcpprQ   c                     ddl }| s|r|dk    s
J d            t          |j        j                            d| |          | s|rdn|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)pythonre   rf   r6   )r[   rP   r^   r_   gather_traceback)re   rf   rQ   ra   s       r1   extractzCapturedTraceback.extract   sz     	"!!! 	9S 	919998999 H//tFPS/TT ,3,AAD1H	
 
 	
rH   c                 N    t          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
        )rK   format_listrb   rX   s    r1   formatzCapturedTraceback.format   s     $T\\^^444rH   c                     ddl }g }g }t                     D ]L\  }}|j        |                    g            "|                    d           |                    |           M|j        j                             fd|D                        |D ]1}t          j         |         	                                          ||<   2|S )z_
        Bulk version of CapturedTraceback.format.  Returns a list of list of strings.
        r   Nc                 *    g | ]}|         j         S  rM   ).0itbss     r1   
<listcomp>z0CapturedTraceback.format_all.<locals>.<listcomp>   s    0Q0Q0QqQ0Q0Q0QrH   )
r[   	enumerater(   r#   r^   r_   r`   rK   rl   rb   )rs   ra   rsdelayed_idxsrr   r(   s   `     r1   
format_allzCapturedTraceback.format_all   s    
 	"!!! )+s^^ 	' 	'EAru}		"		$##A&&&&//0Q0Q0Q0QL0Q0Q0QRRR 	< 	<A)#a&..*:*:;;BqEE	rH   N)r   )__name__
__module____qualname__	__slots__rV   rY   rb   rd   staticmethodrj   rm   rx   rp   rH   r1   rP   rP      s        vI     	
 	
 	

 
 
 U 
 
 
 
 \
.5 5 5   \  rH   rP   c           	          t          j                    }t          | |d                   D ]=}|                    t          j        |d         |d         |d                              >|S )z
    Given a symbolized traceback from symbolize_tracebacks, return a StackSummary object of
    pre-processed stack trace entries.
    Nr*   rA   r   )rK   r\   r%   r#   FrameSummary)r(   rQ   r)   r,   s       r1   r]   r]      sh    
 "$$Ebi   R RY+AjM1V9aiPPQQQQLrH   )
contextlibr   os.pathr7   r   rK   typesr   typingr   contextmanagerr2   r@   rG   rN   rP   r]   rp   rH   r1   <module>r      s                         R Q* Q* Q*h "& 
% 
% 
% 
% 
% !%5 	g 	g 	g 	g 	g6 6 6
U U U U U U U Up    rH   