
    a$                        d dl 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 n# e$ r dZY nw xY w	 ddl	m
Z
 n# e$ r dZ
Y nw xY we
ses ed          d	Zd
Zej        d          dk    Z e j        d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    N)CodeType)	FrameType)TracebackType)tproxy   )tb_set_nextz(Cannot use tblib. Runtime not supported.z1.7.0)	TracebackTracebackParseErrorFrameCode   zO^\s*File "(?P<co_filename>.+)", line (?P<tb_lineno>\d+)(, in (?P<co_name>.+))?$c                       e Zd ZdZd ZdS )	_AttrDict c                 N    	 | |         S # t           $ r t          |          w xY wN)KeyErrorAttributeError)selfnames     .lib/python3.11/site-packages/tblib/__init__.py__getattr__z_AttrDict.__getattr__   s:    	': 	' 	' 	' &&&	's   
 $N)__name__
__module____qualname__	__slots__r   r       r   r   r      s(        I' ' ' ' 'r   r   c                       e Zd ZdS )__traceback_makerNr   r   r   r   r   r   r   r   %           Dr   r   c                       e Zd ZdS )r
   Nr    r   r   r   r
   r
   )   r!   r   r
   c                   "    e Zd ZdZdZd Zd ZdS )r   zw
    Class that replicates just enough of the builtin Code object to enable serialization and traceback rendering.
    Nc                     |j         | _         |j        | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d S )Nr   r   @   )	co_filenameco_nameco_argcountco_kwonlyargcountco_varnames
co_nlocalsco_stacksizeco_flagsco_firstlineno)r   codes     r   __init__zCode.__init__3   sR    +|!"r   c                 b    |dv rt          | |d                   S  t          | |          |i |S ).
        Necessary for PyPy's tproxy.
        __getattribute__r   r   )getattrr   	operationargskwargss       r   
__tproxy__zCode.__tproxy__?   sC     ;;;4a)))+74++T<V<<<r   )r   r   r   __doc__co_coder0   r:   r   r   r   r   r   -   sC          G	  	  	 = = = = =r   r   c                   $    e Zd ZdZd Zd Zd ZdS )r   zx
    Class that replicates just enough of the builtin Frame object to enable serialization and traceback rendering.
    c                     i | _         d |j                                        D             | _        t          |j                  | _        |j        | _        d S )Nc                 "    i | ]\  }}|d v 	||S )__file__r   r   ).0kvs      r   
<dictcomp>z"Frame.__init__.<locals>.<dictcomp>O   s4     
 
 
1,,, q,,,r   )f_locals	f_globalsitemsr   f_codef_lineno)r   frames     r   r0   zFrame.__init__M   sW    
 
--//
 
 

 5<((r   c                     dS )z
        For compatibility with PyPy 3.5;
        clear() was added to frame in Python 3.4
        and is called by traceback.clear_frames(), which
        in turn is called by unittest.TestCase.assertRaises
        Nr   )r   s    r   clearzFrame.clearW   s      r   c                     |dv rA|d         dk    rt          t          | j        j                  S t	          | |d                   S  t	          | |          |i |S )r2   r3   r   rI   )r   r   rI   r:   r5   r6   s       r   r:   zFrame.__tproxy__`   sg     ;;;Aw(""h(>???tT!W---+74++T<V<<<r   N)r   r   r   r;   r0   rM   r:   r   r   r   r   r   I   sK         ' ' '  
= 
= 
= 
= 
=r   r   c                   d    e Zd ZdZdZd Zd ZeZd Zd Z	e	Z
ed             Zed
d	            ZdS )r	   z5
    Class that wraps builtin Traceback objects.
    Nc                 ^   t          |j                  | _        t          |j                  | _        |j        }| }t          |           }|`t                              |          }t          |j                  |_        t          |j                  |_        ||_        |}|j        }|^d S d S r   )r   tb_frameint	tb_linenotb_nexttypeobject__new__)r   tbprev_tracebackcls	tracebacks        r   r0   zTraceback.__init__s   s    bk**R\** Z4jjns++I!&r{!3!3I"%bl"3"3I%.N"&NB nnnnnr   c                    t           rt          t          | j                  S t          st	          d          | }d}d}|r|j        j        }t          d|j        dz
  z  dz   |j        j        j	        d          }t          |d          r%|                    d|j	        |j        d	d	
          }nt          rZt          d|j        |j        |j        |j        |j        |j        |j        |j        |j	        |j        |j        |j        d	d	          }nwt          d|j        |j        |j        |j        |j        |j        |j        |j	                                        |j                                        |j        |j        d	d	          }	 t5          |t7          |j        j                  i            nG# t:          $ r: t=          j                    d         j         }||}|t          ||           |}~Y nw xY w|j         }|	 |~~S # ~~w xY w)zm
        Convert to a builtin Traceback object that is usable for raising or rendering a stacktrace.
        zUnsupported Python interpreter!N
r   zraise __traceback_makerexecreplacer   r   )r(   r&   r'   co_freevarsco_cellvars   )!r   r   r:   r   RuntimeErrorrQ   rI   compilerS   r&   hasattrr_   r'   PY3r   r)   r+   r,   r-   r<   	co_constsco_namesr*   r.   	co_lnotabencoder^   dictrG   	Exceptionsysexc_inforT   )r   currenttop_tbrX   rI   r/   next_tbs          r   as_tracebackzTraceback.as_traceback   sF     	:-999 	B@AAA %	&%,F47#4q#89<UUW^WgWnWz  }C  D  DDtY'' ||060BFN02 $ D D  t-OT%6L$.$-AQ&'R   OT%6L$.$-AQ&--//1F1F1H1H'R 	T4 0 :;;R@@@@   ,..+3>$F>G,,,GG oGK  %	&L	 FFFFs   	(F2 2AG65G6H Hc                    |dv rm|d         dk    r | j         o| j                                         S |d         dk    rt          t          | j        j                  S t          | |d                   S  t          | |          |i |S )r2   r3   r   rT   rQ   )rT   rr   r   r   rQ   r:   r5   r6   s       r   r:   zTraceback.__tproxy__   s     ;;;Aw)##|C(A(A(C(CCaJ&&i)ABBBtT!W---+74++T<V<<<r   c                     | j         d}n| j                                         }| j        j        j        | j        j        j        d}| j        j        || j        j        d}|| j        |dS )z
        Converts to a dictionary representation. You can serialize the result to JSON as it only has
        builtin objects like dicts, lists, ints or strings.
        Nr&   r'   rG   rI   rJ   rQ   rS   rT   )	rT   to_dictrQ   rI   r&   r'   rG   rJ   rS   )r   rT   r/   rK   s       r   as_dictzTraceback.as_dict   s    
 <GGl**,,G  =/;}+3
 

 0.
 
 
 
 	
r   c                 R   |d         r|                      |d                   }nd}t          |d         d         d         |d         d         d                   }t          |d         d         ||d         d	         
          }t          ||d         |          } | |          S )zj
        Creates an instance from a dictionary with the same structure as ``.as_dict()`` returns.
        rT   NrQ   rI   r&   r'   ru   rG   rJ   rv   rS   rw   )	from_dictr   )rZ   dctrT   r/   rK   rX   s         r   r{   zTraceback.from_dict   s    
 y> 	mmC	N33GGGJ1-@
OH-i8
 
 
 *ok2_Z0
 
 

 +&
 
 

 s2wwr   Tc                 H   g }|}|                                 D ]}|                                }|r	|dk    rd}!t                              |          }|r(|                    |                                           e|                    d          r{|r n|rwd}t          |          D ]Z}t          |t          |t          |d         d          t          |          t          |d                   	          |
          }[ | |          S t          d|z            )z
        Creates an instance by parsing a stacktrace. Strict means that parsing stops when lines are not indented by at least two spaces
        anymore.
        z"Traceback (most recent call last):Fz  Nr&   ?r@   rS   rv   )rQ   rT   z Could not find any frames in %r.)
splitlinesrstripFRAME_REmatchappend	groupdict
startswithreversedr   rR   r
   )	rZ   stringstrictframesheaderlineframe_matchpreviousrK   s	            r   from_stringzTraceback.from_string   sm    %%'' 	 	D;;==D ???"F"....K k33556666&&    	SH!&))  $&"+%*=%9%(# # #  )//!$U;%7!8!8   %   3x== %&H6&QRRRr   )T)r   r   r   r;   rT   r0   rr   to_tracebackr:   ry   rx   classmethodr{   r   r   r   r   r	   r	   m   s          G  "6 6 6n  L= = =
 
 
0 G  [2 (S (S (S [(S (S (Sr   r	   )rerm   typesr   r   r   __pypy__r   ImportErrorcpythonr   __version____all__version_inforf   rd   r   rk   r   rl   r   r
   rV   r   r   r	   r   r   r   <module>r      s6   				 



                     FFF$$$$$$$   KKK  B6 B
+@
A
AA
=	qQ2:hii' ' ' ' ' ' ' '	 	 	 	 		 	 	 		 	 	 	 	) 	 	 	= = = = =6 = = =8!= != != != !=F != != !=H|S |S |S |S |S |S |S |S |S |Ss   # --8 AA