
    .Ph#                     D   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          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             dS # e$ r d dlZ ej                      w xY wdS )    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                    d }|r-t          |d         t                    r|d         |dd          }} t                      j        | g|R i |}||_        ||S t          |dd           }|||_        n||_        t          |dd           }|Ht          |          |_        t          |j	                  |_	        t          |j
                  |_
        |S 	 t          j                    \  }}}	|||~	S ||u s||u rIt          |	          |_	        t          |	j                  |_
        |j
        d d         |j	        z   |_        ~	n# ~	w xY w|S )Nr      
root_cause
full_trace)
isinstance	Exceptionsuper__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             P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/boltons/excutils.pyr   zExceptionCauseMixin.__new__B   st    	,JtAw	22 	,q'484Eeggoc/D///B//	=JUL$77
"CNN'CNUL$77
!!*--CN59ooCGel++CJJ	*-,..'HiI$5  	!!Z9%<%< +6220AA
!$CRC37!:JJJJ
s   E
 7AE
 
Ec                     g }|                                  }|r|                    d|g           |                    |                                            d                    |          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_strf   si     ''))	 	LJJ>	JKKK

4$$&&'''wws||    c                 n    t          | dg           }| j        r
|dd          }|r|d         r|d         S dS )Nr   r   r   r#   )r   r   )r)   r   s     r!   _get_messagez ExceptionCauseMixin._get_messaget   sK    tVR((: 	8D 	DG 	7Nrr,   c                     | j         s t                                                      S | j        r,d                    t          j        | j                            S dS )Nr#   )r   r   __repr__r	   r(   	tracebackformat_list)r)   r    s    r!   r$   z"ExceptionCauseMixin._get_trace_str|   sR    z 	&77##%%%? 	C7790AABBBrr,   Tc                    t          | j                  }|                                 }g }|r| j        j        dg}|r|                    |d|dg           n|                    d|g           d                    |          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   s    00	##%% 	2>*D1C 	3JJC@AAAAJJy1222wws||r,   c                    | j         s t                                                      S |                                 }g }|rn|                                 }|r|                    |dg           |                    d||                     d          g           d                    |          S |                     d          S )Nz --- z+Wrapped traceback (most recent call last):
T)r7   r#   F)r   r   __str__r$   r.   r%   r'   r(   )r)   r*   r   r9   r    s       r!   r;   zExceptionCauseMixin.__str__   s    z 	%77??$$$''))	 		6''))G /

GW-...JJF!))D)99; < < < 773<<$$u$555r,   )T)r6   
__module____qualname____doc__r   r   r+   r.   r$   r'   r;   __classcell__r    s   @r!   r   r   .   s         " E" " " " "H        
 
 
 
6 6 6 6 6 6 6 6 6r,   c                 p    || }t          j        | j        j        |          }|                                S N)r1   _format_final_exc_liner    r6   rstrip)excr9   exc_strs      r!   r5   r5      s3    .s}/EwOOG>>r,   _BaseTBItemzfilename, lineno, name, linec                        e Zd Z fdZ xZS )_TBItemc                 b    t                                                      }|d| j        z  z  }|S )Nz <%r>)r   r0   frame_id)r)   r   r    s     r!   r0   z_TBItem.__repr__   s.    gg  w&&
r,   )r6   r<   r=   r0   r?   r@   s   @r!   rI   rI      s8                r,   rI   c                   :    e Zd Zd	dZd Zd Zd Zd Zd Zd Z	dS )
_DeferredLineNc                 p    || _         || _        |pi }d |                                D             | _        d S )Nc                 "    i | ]\  }}|d v 	||S ))r6   
__loader__ ).0kvs      r!   
<dictcomp>z*_DeferredLine.__init__.<locals>.<dictcomp>   s6     H H H1'(,F'F'F  !!'F'F'Fr,   )filenamelinenoitemsmodule_globals)r)   rV   rW   rY   s       r!   __init__z_DeferredLine.__init__   sQ     '-2H H0D0D0F0F H H Hr,   c                 >    | j         | j        f|j         |j        fk    S rB   rW   rV   r)   others     r!   __eq__z_DeferredLine.__eq__       T]+en/MMMr,   c                 >    | j         | j        f|j         |j        fk    S rB   r\   r]   s     r!   __ne__z_DeferredLine.__ne__   r`   r,   c                     t          | d          r| j        S t          j        | j                   t          j        | j        | j        | j                  }|r|                                }nd }|| _        |S )N_line)	hasattrrd   	linecache
checkcacherV   getlinerW   rY   strip)r)   lines     r!   r;   z_DeferredLine.__str__   sz    4!! 	:T]+++ !%!%!46 6  	::<<DDD
r,   c                 :    t          t          |                     S rB   )reprstrr)   s    r!   r0   z_DeferredLine.__repr__   s    CIIr,   c                 :    t          t          |                     S rB   )lenrm   rn   s    r!   __len__z_DeferredLine.__len__   s    3t99~~r,   c                 D    t          |                                           S rB   )rm   ri   rn   s    r!   ri   z_DeferredLine.strip   s    4yy   r,   rB   )
r6   r<   r=   rZ   r_   rb   r;   r0   rq   ri   rQ   r,   r!   rM   rM      s        H H H HN N NN 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        } |dz  }| ||k     |                                 |S )Nr   tracebacklimit  r   )r   	_getframer   f_codeco_filenamef_linenoco_namerM   	f_globalsrI   idrK   r&   f_backreverse)	flimitr   nrV   rW   namerj   items	            r!   r   r      s    
CyM!}-t44	A
-AII8'xXvq{;;xt441

4H	Q -AII KKMMMJr,   c                 ~   g }|t          t          dd          }d}| ||k     r| j        j        j        }| j        }| j        j        j        }t          ||| j        j                  }t          ||||          }t          | j                  |_        |                    |           | j        } |dz  }| ||k     |S )Nrt   ru   r   r   )r   r   r   rw   rx   	tb_linenorz   rM   r{   rI   r|   rK   r&   tb_next)	tbr   r   r   rV   rW   r   rj   r   s	            r!   r   r      s    
C}-t44	A
.QYY;%1{!)Xvr{/DEExt442;

4Z	Q .QYY Jr,   c                       e Zd ZdS )	MathErrorN)r6   r<   r=   rQ   r,   r!   r   r     s        Dr,   r   c                      ddz  S )Nr   r   rQ   rQ   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   	  s`    1uu!A#}}   011	s   ) 
A
AA
c                  l    	 t                       d S # t          $ r} t          | d          }|d } ~ ww xY w)Nhi)r   
ValueErrorr   )merE   s     r!   mainr     sG    




   D!!	s    
3.3__main__rB   )NN)r   )r   r1   rf   collectionsr   __all__r   r   r5   rG   rI   rM   r   r   r   r   r   r   r   r6   pdbpost_mortemrQ   r,   r!   <module>r      s  @ 


         " " " " " " !
!o6 o6 o6 o6 o6) o6 o6 o6d    j(FGG    k   #! #! #! #! #! #! #! #!L   *   *	 	 	 	 	#Z 	 	 	        z   


?3?$$$ s   7
B B