o
    Zh                     @   s   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
mZ d dlmZ d dlmZ zd dlZd d	lmZ W n eyG   ed
w er\d dlmZ d dlmZ d dlmZ dd Zdd Zdd ZG dd de
ZdS )    )absolute_importN)reraise)OP)Hub)IntegrationDidNotEnable)TYPE_CHECKING)event_from_exception)Taskzasyncio not available)Any)	Coroutine)ExcInfoc                 C   s   t | dd pt | dd pdS )N__qualname____name__zcoroutine without __name__)getattrcoro r   V/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/asyncio.pyget_name   s
   
r   c                     sF   d  zt  } |    fdd}| | W d S  ty"   Y d S w )Nc                    sL    fdd}r| | fi |S t | fd| i|}|jr$|jd= |S )Nc               
      s   t t j} d }| B | jtjt d z I d H }W n ty,   tt|   Y nw W d    n1 s7w   Y  W d    |S W d    |S 1 sOw   Y  |S )N)opdescription)	r   currentZ
start_spanr   ZFUNCTIONr   	Exceptionr   _capture_exception)hubresultr   r   r   _coro_creating_hub_and_span,   s&   


zPpatch_asyncio.<locals>._sentry_task_factory.<locals>._coro_creating_hub_and_spanloop)r
   Z_source_traceback)r   r   kwargsr   taskZorig_task_factoryr   r   _sentry_task_factory)   s   	z+patch_asyncio.<locals>._sentry_task_factory)asyncioZget_running_loopZget_task_factoryZset_task_factoryRuntimeError)r   r#   r   r"   r   patch_asyncio"   s   "r&   c                 C   sL   t  }| t}|d ur$| j}t||jdddd\}}| j||d |S )Nr$   F)typeZhandled)Zclient_optionsZ	mechanism)hint)sysexc_infoZget_integrationAsyncioIntegrationclientr	   optionsZcapture_event)r   r*   Zintegrationr,   eventr(   r   r   r   r   Q   s   

r   c                   @   s   e Zd ZdZedd ZdS )r+   r$   c                   C   s
   t   d S )N)r&   r   r   r   r   
setup_onceg   s   
zAsyncioIntegration.setup_onceN)r   
__module__r   
identifierstaticmethodr/   r   r   r   r   r+   d   s    r+   )
__future__r   r)   Zsentry_sdk._compatr   Zsentry_sdk.constsr   Zsentry_sdk.hubr   Zsentry_sdk.integrationsr   r   Zsentry_sdk._typesr   Zsentry_sdk.utilsr	   r$   Zasyncio.tasksr
   ImportErrortypingr   collections.abcr   r   r   r&   r   r+   r   r   r   r   <module>   s,    	/