
    c#                         d dl Z d dlZd dlZd dlmZ dgZ G d de      ZddZ edd      Z	 G d d	e	      Z
 G d
 de      ZddZddZ G d dee      Zd ZddZd Zedk(  r		  e        yy# e$ r d dlZ ej,                           w xY w)    N)
namedtupleExceptionCauseMixinc                   N     e Zd ZdZdZ fdZd Zd Z fdZd	dZ	 fdZ
 xZS )
r   ak  
    A mixin class for wrapping an exception in another exception, or
    otherwise indicating an exception was caused by another exception.

    This is most useful in concurrent or failure-intolerant scenarios,
    where just because one operation failed, doesn't mean the remainder
    should be aborted, or that it's the appropriate time to raise
    exceptions.

    This is still a work in progress, but an example use case at the
    bottom of this module.

    NOTE: when inheriting, you will probably want to put the
    ExceptionCauseMixin first. Builtin exceptions are not good about
    calling super()
    Nc                 h   d }|rt        |d   t              r
|d   |dd  }}t        t        |   | g|i |}||_        ||S t        |dd       }|||_        n||_        t        |dd       }|Ft        |      |_	        t        |j                        |_
        t        |j                        |_        |S 	 t        j                         \  }}}	|||~	S ||u s||u rKt        |	      |_
        t        |	j                         |_        |j                  d d |j                  z   |_	        ~	|S # ~	w xY w)Nr      
root_cause
full_trace)
isinstance	Exceptionsuperr   __new__causegetattrr   listr	   _tb_stacksysexc_info_extract_from_tb_extract_from_frametb_frame)clsargskwr   retr   r	   exc_type	exc_valueexc_tb	__class__s             0lib/python3.12/site-packages/boltons/excutils.pyr   zExceptionCauseMixin.__new__D   s@   JtAw	2q'484E'5cGDGBG	=JUL$7
"CN'CNUL$7
!!*-CN599oCGell+CJJ	*-,,.'HiI$5  	!Z9%< +620A
!$CR377!:
 s   9D. AD. .D1c                     g }| j                         }|r|j                  d|g       |j                  | j                                dj	                  |      S )z
        Get formatted the formatted traceback and exception
        message. This function exists separately from __str__()
        because __str__() is somewhat specialized for the built-in
        traceback module's particular usage.
        z#Traceback (most recent call last):
 )_get_trace_strextendappend_get_exc_strjoin)selfr   	trace_strs      r!   get_strzExceptionCauseMixin.get_strh   sO     '')	JJ>	JK

4$$&'wws|    c                 X    t        | dg       }| j                  r|dd  }|r
|d   r|d   S y)Nr   r   r   r#   )r   r   )r)   r   s     r!   _get_messagez ExceptionCauseMixin._get_messagev   s7    tVR(::8DDG7Nr,   c                     | j                   st        t        |          S | j                  r.dj                  t        j                  | j                              S y)Nr#   )r   r   r   __repr__r	   r(   	tracebackformat_list)r)   r    s    r!   r$   z"ExceptionCauseMixin._get_trace_str~   sC    zz,d<>>??77900ABBr,   c                     t        | j                        }| j                         }g }|r| j                  j                  dg}|r|j                  |d|dg       n|j                  d|g       dj                  |      S )Nz: z (caused by )z caused by r#   )_format_excr   r.   r    __name__r%   r(   )r)   	incl_name	cause_strmessager   s        r!   r'   z ExceptionCauseMixin._get_exc_str   sq    0	##%>>**D1CJJC@AJJy12wws|r,   c                 @   | j                   st        t        |          S | j	                         }g }|rZ| j                         }|r|j                  |dg       |j                  d|| j                  d      g       dj                  |      S | j                  d      S )Nz --- z+Wrapped traceback (most recent call last):
T)r7   r#   F)	r   r   r   __str__r$   r.   r%   r'   r(   )r)   r*   r   r9   r    s       r!   r;   zExceptionCauseMixin.__str__   s    zz,d;=='')	'')G

GW-.JJF!))D)9; < 773<$$u$55r,   )T)r6   
__module____qualname____doc__r   r   r+   r.   r$   r'   r;   __classcell__r    s   @r!   r   r   0   s3    " E"H
6 6r,   c                 ~    || }t        j                  | j                  j                  |      }|j	                         S N)r1   _format_final_exc_liner    r6   rstrip)excr9   exc_strs      r!   r5   r5      s5    ..s}}/E/EwOG>>r,   _BaseTBItemzfilename, lineno, name, linec                        e Zd Z fdZ xZS )_TBItemc                 P    t         t        |          }|d| j                  z  z  }|S )Nz <%r>)r   rI   r0   frame_id)r)   r   r    s     r!   r0   z_TBItem.__repr__   s*    GT+-w&&
r,   )r6   r<   r=   r0   r?   r@   s   @r!   rI   rI      s     r,   rI   c                   8    e Zd Zd	dZd Zd Zd Zd Zd Zd Z	y)
_DeferredLineNc                     || _         || _        |xs i }t        |j                         D cg c]  \  }}|dv r||f c}}      | _        y c c}}w )N)r6   
__loader__)filenamelinenodictitemsmodule_globals)r)   rP   rQ   rT   kvs         r!   __init__z_DeferredLine.__init__   s^     '-2"~7K7K7M $Htq!'(,F'F &'F $H I $Hs   A
c                 d    | j                   | j                  f|j                   |j                  fk(  S rB   rQ   rP   r)   others     r!   __eq__z_DeferredLine.__eq__   '    T]]+enn/MMMr,   c                 d    | j                   | j                  f|j                   |j                  fk7  S rB   rY   rZ   s     r!   __ne__z_DeferredLine.__ne__   r]   r,   c                    t        | d      r| j                  S t        j                  | j                         t        j
                  | j                  | j                  | j                        }|r|j                         }nd }|| _        |S )N_line)	hasattrra   	linecache
checkcacherP   getlinerQ   rT   strip)r)   lines     r!   r;   z_DeferredLine.__str__   so    4!::T]]+  !%!%!4!46 ::<DD
r,   c                 *    t        t        |             S rB   )reprstrr)   s    r!   r0   z_DeferredLine.__repr__   s    CIr,   c                 *    t        t        |             S rB   )lenrj   rk   s    r!   __len__z_DeferredLine.__len__   s    3t9~r,   c                 4    t        |       j                         S rB   )rj   rf   rk   s    r!   rf   z_DeferredLine.strip   s    4y  r,   rB   )
r6   r<   r=   rW   r\   r_   r;   r0   rn   rf    r,   r!   rM   rM      s(    INN!r,   rM   c                    g }| t        j                  d      } |t        t         dd      }d}| ||k  r| j                  j                  }| j
                  }| j                  j                  }t        ||| j                        }t        ||||      }t        |       |_        |j                  |       | j                  } |dz  }| ||k  r|j                          |S )Nr   tracebacklimit  r   )r   	_getframer   f_codeco_filenamef_linenoco_namerM   	f_globalsrI   idrK   r&   f_backreverse)	flimitr   nrP   rQ   namerg   items	            r!   r   r      s    
CyMM!}-t4	A
-AI88''xxXvq{{;xt41

4HH	Q -AI KKMJr,   c                    g }|t        t        dd      }d}| ||k  r| j                  j                  j                  }| j
                  }| j                  j                  j                  }t        ||| j                  j                        }t        ||||      }t        | j                        |_        |j                  |       | j                  } |dz  }| ||k  r|S )Nrr   rs   r   r   )r   r   r   ru   rv   	tb_linenorx   rM   ry   rI   rz   rK   r&   tb_next)	tbr~   r   r   rP   rQ   r   rg   r   s	            r!   r   r      s    
C}-t4	A
.QY;;%%11{{!!))Xvr{{/D/DExt42;;

4ZZ	Q .QY Jr,   c                       e Zd Zy)	MathErrorN)r6   r<   r=   rp   r,   r!   r   r     s    r,   r   c                      ddz  S )Nr   r   rp   rp   r,   r!   whoops_mathr     s    Q3Jr,   c                 ~    | dk  rt        | dz         S 	 t               S # t        $ r}t        |d      }|d }~ww xY w)N   r   )r   zya done messed up)math_lolr   ZeroDivisionErrorr   )r   zderE   s      r!   r   r     sF    1u!A#} 01	s   	  	<7<c                  X    	 t                y # t        $ r} t        | d      }|d } ~ ww xY w)Nhi)r   
ValueErrorr   )merE   s     r!   mainr     s-    
 D!	s   
 	)$)__main__rB   )NN)r   )r   r1   rc   collectionsr   __all__r   r   r5   rG   rI   objectrM   r   r   r   r   r   r   r   r6   pdbpost_mortemrp   r,   r!   <module>r      s   D    " !
!o6) o6d (FGk #!F #!L**	#Z 	 z   ?3??$s   (A1 1B