o
    rh                     @  s   d dl mZ 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	 d dlm
Z
 d dlZd dlZe
r<d dlmZ G d	d
 d
ZdddZejddddddZejddddddZejddddddZdS )    )annotationsN)TracebackType)Any)Callable)	Generator)TYPE_CHECKING)Selfc                   @  s8   e Zd ZdZdddZddd	ZdddZdddZdS )catch_threading_exceptiona  Context manager catching threading.Thread exception using
    threading.excepthook.

    Storing exc_value using a custom hook can create a reference cycle. The
    reference cycle is broken explicitly when the context manager exits.

    Storing thread using a custom hook can resurrect it if it is set to an
    object which is being finalized. Exiting the context manager clears the
    stored object.

    Usage:
        with threading_helper.catch_threading_exception() as cm:
            # code spawning a thread which raises an exception
            ...
            # check the thread exception: use cm.args
            ...
        # cm.args attribute no longer exists at this point
        # (to break a reference cycle)
    returnNonec                 C  s   d | _ d | _d S N)args	_old_hookself r   U/var/www/html/alpaca_bot/venv/lib/python3.10/site-packages/_pytest/threadexception.py__init__)   s   
z"catch_threading_exception.__init__r   threading.ExceptHookArgsc                 C  s
   || _ d S r   )r   )r   r   r   r   r   _hook-   s   
zcatch_threading_exception._hookr   c                 C  s   t j| _| jt _| S r   )	threading
excepthookr   r   r   r   r   r   	__enter__0   s   z#catch_threading_exception.__enter__exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Nonec                 C  s$   | j d usJ | j t_d | _ | `d S r   )r   r   r   r   )r   r   r   r   r   r   r   __exit__5   s   z"catch_threading_exception.__exit__N)r
   r   )r   r   r
   r   )r
   r   )r   r   r   r   r   r   r
   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r	      s    


r	   r
   Generator[None]c                  c  s    t  q} z5d V  W | jr:| jjd u rdn| jjj}d| d}|dt| jj| jj| jj	7 }t
t| n2| jrl| jjd u rFdn| jjj}d| d}|dt| jj| jj| jj	7 }t
t| w w W d    d S 1 sxw   Y  d S )Nz	<unknown>zException in thread z

 )r	   r   threadnamejoin	tracebackformat_exceptionr   	exc_valueexc_tracebackwarningswarnpytest%PytestUnhandledThreadExceptionWarning)cmthread_namemsgr   r   r   thread_exception_runtest_hookA   s@   "r4   T)wrappertrylastc                   c      t  E d H  d S r   r4   r   r   r   r   pytest_runtest_setupU      r9   )r5   tryfirstc                   c  r7   r   r8   r   r   r   r   pytest_runtest_callZ   r:   r<   c                   c  r7   r   r8   r   r   r   r   pytest_runtest_teardown_   r:   r=   )r
   r$   )
__future__r   r   r)   typesr   typingr   r   r   r   r-   r/   typing_extensionsr   r	   r4   hookimplr9   r<   r=   r   r   r   r   <module>   s(    
-