o
    hY                     @  sB  U d dl mZ d dlZd dlmZ d dlZ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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erP	 ejd
k r[d dlmZ G dd de
Ze Zded< d,ddZd-ddZd.ddZd,d d!Zej d"d#d/d&d'Z!ej d"d#d/d(d)Z"ej d"d#d/d*d+Z#dS )0    )annotationsN)Callable)
NamedTuple)TYPE_CHECKING)Config)Item)StashKey)tracemalloc_message)      )ExceptionGroupc                   @  s&   e Zd ZU ded< ded< ded< dS )ThreadExceptionMetastrmsg	cause_msgzBaseException | None	exc_valueN)__name__
__module____qualname____annotations__ r   r   X/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/threadexception.pyr      s   
 r   z@StashKey[collections.deque[ThreadExceptionMeta | BaseException]]thread_exceptionsconfigr   returnNonec              
   C  s   | j t j}g }d }d }zn	 z| }W n	 ty   Y nHw t|tr/td}||_|| q|j	}z
t
t| W n& tjyb } z|jd urS|jf|_|j|_|| W Y d }~nd }~ww qt|dkrn|d |rutd|W ~~~d S ~~~w )NTz"Failed to process thread exception   r   z"multiple thread exception warnings)stashr   pop
IndexError
isinstanceBaseExceptionRuntimeError	__cause__appendr   warningswarnpytest%PytestUnhandledThreadExceptionWarningr   r   argslenr   )r   pop_thread_exceptionerrorsmeta
hook_errorr   er   r   r   collect_thread_exception&   sB   





r0   	prev_hook,Callable[[threading.ExceptHookArgs], object]c                 C  s6   zz	t |  W |t_n|t_w W | jt= d S | jt= w N)r0   	threading
excepthookr   r   r   r1   r   r   r   cleanupM   s
   
r7   r)   threading.ExceptHookArgsr$   7Callable[[ThreadExceptionMeta | BaseException], object]c         	   
   C  s   z=| j d u rdn| j j}d| }ddt| j| j| j }dt| j  }|| | }|| }|t	||| jd W d S  t
yN } z||  d }~ww )Nz	<unknown>zException in thread z

 
)r   r   r   )threadnamejoin	tracebackformat_exceptionexc_typer   exc_tracebackr	   r   r!   )	r)   r$   thread_namesummarytraceback_messagetracemalloc_tbr   r   r/   r   r   r   thread_exception_hook\   s2   

rG   c                 C  sD   t j}t }|| jt< | tjt	| |d tjt
|jdt _d S )Nr6   )r$   )r4   r5   collectionsdequer   r   add_cleanup	functoolspartialr7   rG   r$   )r   r1   rI   r   r   r   pytest_configure   s
   
rM   T)trylastitemr   c                 C     t | j d S r3   r0   r   rO   r   r   r   pytest_runtest_setup      rS   c                 C  rP   r3   rQ   rR   r   r   r   pytest_runtest_call   rT   rU   c                 C  rP   r3   rQ   rR   r   r   r   pytest_runtest_teardown   rT   rV   )r   r   r   r   )r   r   r1   r2   r   r   )r)   r8   r$   r9   r   r   )rO   r   r   r   )$
__future__r   rH   collections.abcr   rK   sysr4   r?   typingr   r   r%   _pytest.configr   _pytest.nodesr   _pytest.stashr   _pytest.tracemallocr	   r'   version_infoexceptiongroupr   r   r   r   r0   r7   rG   rM   hookimplrS   rU   rV   r   r   r   r   <module>   s@    



'

(


