a
    d#                     @   s   d dl Z d dlZd dlZd dlmZ dgZG dd deZdddZeddZ	G d	d
 d
e	Z
G dd deZdddZdddZG dd deeZdd ZdddZdd Zedkrz
e  W n$ ey   d dlZe   Y n0 dS )    N)
namedtupleExceptionCauseMixinc                       sV   e Zd ZdZdZ fddZdd Zdd Z fd	d
ZdddZ	 fddZ
  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           
         s,  d }|r,t |d tr,|d |dd   }}tt| j| g|R i |}||_|d u r\|S t|dd }|d u rx||_n||_t|dd }|d urt||_	t|j
|_
t|j|_|S zjt \}}}	|d u r|d u r|W ~	S ||u s||u rt|	|_
t|	j|_|jd d |j
 |_	W ~	n~	0 |S )Nr      
root_cause
full_trace)
isinstance	Exceptionsuperr   __new__causegetattrr   listr   Z_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__ Y/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/boltons/excutils.pyr   D   s:    
	
zExceptionCauseMixin.__new__c                 C   s6   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_strr   r   r   get_strh   s    zExceptionCauseMixin.get_strc                 C   s6   t | dg }| jr|dd  }|r2|d r2|d S dS )Nr   r   r   r    )r   r   )r&   r   r   r   r   _get_messagev   s    z ExceptionCauseMixin._get_messagec                    s0   | j stt|  S | jr,dt| jS dS )Nr    )r   r
   r   __repr__r   r%   	tracebackformat_listr&   r   r   r   r!   ~   s
    z"ExceptionCauseMixin._get_trace_strTc                 C   sV   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_nameZ	cause_strmessager   r   r   r   r$      s    
z ExceptionCauseMixin._get_exc_strc                    sp   | j stt|  S |  }g }|r`|  }|r>||dg |d|| jddg d|S | jddS d S )Nz --- z+Wrapped traceback (most recent call last):
T)r1   r    F)	r   r
   r   __str__r!   r)   r"   r$   r%   )r&   r'   r   r2   r   r   r   r3      s    

zExceptionCauseMixin.__str__)T)r0   
__module____qualname____doc__r   r   r(   r)   r!   r$   r3   __classcell__r   r   r   r   r   0   s   $
c                 C   s$   |d u r| }t | jj|}| S N)r+   _format_final_exc_liner   r0   rstrip)excr2   Zexc_strr   r   r   r/      s    r/   _BaseTBItemzfilename, lineno, name, linec                       s   e Zd Z fddZ  ZS )_TBItemc                    s    t t|  }|d| j 7 }|S )Nz <%r>)r
   r=   r*   frame_id)r&   r   r   r   r   r*      s    z_TBItem.__repr__)r0   r4   r5   r*   r7   r   r   r   r   r=      s   r=   c                   @   sF   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dS )_DeferredLineNc                 C   s0   || _ || _|pi }tdd | D | _d S )Nc                 S   s    g | ]\}}|d v r||fqS ))r0   
__loader__r   ).0kvr   r   r   
<listcomp>   s   z*_DeferredLine.__init__.<locals>.<listcomp>)filenamelinenodictitemsmodule_globals)r&   rE   rF   rI   r   r   r   __init__   s    z_DeferredLine.__init__c                 C   s   | j | jf|j |jfkS r8   rF   rE   r&   otherr   r   r   __eq__   s    z_DeferredLine.__eq__c                 C   s   | j | jf|j |jfkS r8   rK   rL   r   r   r   __ne__   s    z_DeferredLine.__ne__c                 C   sL   t | dr| jS t| j t| j| j| j}|r>| }nd }|| _|S )N_line)	hasattrrP   	linecache
checkcacherE   getlinerF   rI   strip)r&   liner   r   r   r3      s    

z_DeferredLine.__str__c                 C   s   t t| S r8   )reprstrr-   r   r   r   r*      s    z_DeferredLine.__repr__c                 C   s   t t| S r8   )lenrX   r-   r   r   r   __len__   s    z_DeferredLine.__len__c                 C   s   t |  S r8   )rX   rU   r-   r   r   r   rU      s    z_DeferredLine.strip)N)
r0   r4   r5   rJ   rN   rO   r3   r*   rZ   rU   r   r   r   r   r?      s   
r?   c           	      C   s   g }| d u rt d} |d u r*tt dd}d}| d ur||k r| jj}| j}| jj}t||| j}t	||||}t
| |_|| | j} |d7 }q.|  |S )Nr   tracebacklimit  r   )r   	_getframer   f_codeco_filenamef_linenoco_namer?   	f_globalsr=   idr>   r#   f_backreverse)	flimitr   nrE   rF   namerV   itemr   r   r   r      s$    



r   c           	      C   s   g }|d u rt tdd}d}| d ur||k r| jjj}| j}| jjj}t||| jj}t	||||}t
| j|_|| | j} |d7 }q|S )Nr[   r\   r   r   )r   r   r   r^   r_   	tb_linenora   r?   rb   r=   rc   r>   r#   tb_next)	tbrg   r   rh   rE   rF   ri   rV   rj   r   r   r   r      s    



r   c                   @   s   e Zd ZdS )	MathErrorN)r0   r4   r5   r   r   r   r   rn     s   rn   c                   C   s   dd S )Nr   r   r   r   r   r   r   whoops_math  s    ro   c              
   C   sV   | dk rt | d dS zt W S  tyP } zt|d}|W Y d }~n
d }~0 0 d S )N   r   )rh   zya done messed up)math_lolro   ZeroDivisionErrorrn   )rh   Zzder;   r   r   r   rq     s    
rq   c               
   C   sB   z
t   W n2 ty< }  zt| d}|W Y d } ~ n
d } ~ 0 0 d S )Nhi)rq   
ValueErrorrn   )mer;   r   r   r   main  s
    

rv   __main__)N)NN)N)r   )r   r+   rR   collectionsr   __all__r	   r   r/   r<   r=   objectr?   r   r   rt   rn   ro   rq   rv   r0   pdbZpost_mortemr   r   r   r   <module>"   s*   r

&


	
