o
    Ú­jc  ã                   @   sì   d dl 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m
Z
 d dlZG dd	„ d	ƒZd
ed fdd„Zejddd�d
ed fdd„ƒZejddd�d
ed fdd„ƒZejddd�d
ed fdd„ƒZdS )é    N)ÚTracebackType)ÚAny)ÚCallable)Ú	Generator)ÚOptional)ÚTypec                   @   sX   e Zd ZdZddd„Zddd	„Zdd
d„Zdeee	  dee	 dee
 ddf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)
    ÚreturnNc                 C   s   d | _ d | _d S ©N)ÚargsÚ	_old_hook©Úself© r   úT/var/www/html/CropPilot/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._hookc                 C   s   t j| _| jt _| S r
   )Ú	threadingÚ
excepthookr   r   r   r   r   r   Ú	__enter__+   s   z#catch_threading_exception.__enter__Úexc_typeÚexc_valÚexc_tbc                 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__0   s   z"catch_threading_exception.__exit__)r	   N)r   r   r	   N)r	   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   ÚBaseExceptionr   r   r   r   r   r   r      s    



þýüûr   r	   )NNNc               	   c   s¤   � t ƒ �D} d V  | 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 |¡¡ W d   ƒ d S W d   ƒ d S 1 sKw   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_hook<   s"   €ýÿô"þr/   T)ÚhookwrapperÚtrylastc                   c   ó   � t ƒ E d H  d S r
   ©r/   r   r   r   r   Úpytest_runtest_setupL   ó   €r4   )r0   Útryfirstc                   c   r2   r
   r3   r   r   r   r   Úpytest_runtest_callQ   r5   r7   c                   c   r2   r
   r3   r   r   r   r   Úpytest_runtest_teardownV   r5   r8   )r   r$   r(   Útypesr   Útypingr   r   r   r   r   r*   r   r/   Úhookimplr4   r7   r8   r   r   r   r   Ú<module>   s$    -