o
    h                     @   s  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mZ d dlmZ d dlmZ erFd d	lmZmZmZ d d
lmZ z
d dlmZmZ W n ey[   edw zd dlZW n eym   edw dZG dd deZdd Zdd ZdS )    N)deepcopy)wraps)DidNotEnable)should_send_default_pii)SOURCE_FOR_STYLETransactionSource)transaction_from_function)TYPE_CHECKING)AnyCallableDict)Event)StarletteIntegrationStarletteRequestExtractorzStarlette is not installedzFastAPI is not installedzgeneric FastAPI requestc                   @   s   e Zd ZdZedd ZdS )FastApiIntegrationfastapic                   C   s
   t   d S N)patch_get_request_handler r   r   a/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/fastapi.py
setup_once%   s   
zFastApiIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r   "   s    r   c                 C   s   d}|dkr|j d}|rt|pd}n|dkr-|j d}|r-t|dd }|d ur-|}|s5t}tj}nt| }| j||d d S )N endpointurlroutepath)source)	scopegetr   getattr_DEFAULT_TRANSACTION_NAMEr   ROUTEr   set_transaction_name)r"   transaction_stylerequestnamer   r   r    r!   r   r   r    _set_transaction_name_and_source+   s"   r+   c                     s    t jj  fdd} | t j_d S )Nc                     sb   | d}|r"|jd ur"t|js"|jtfdd}||_| i |  fdd}|S )N	dependantc                     sF   t  }|jd ur|j  t  }|jd ur|j   | i |S r   )
sentry_sdkget_current_scopetransactionupdate_active_threadget_isolation_scopeprofileupdate_active_thread_id)argskwargscurrent_scopesentry_scope)old_callr   r   _sentry_callR   s   



zTpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_callc                     s   t  t}|d u r| i |I d H S | d }tt  |j| t  }t|}|	 I d H   fdd}tj
|_|||| | i |I d H S )Nr   c                    s    fdd}|S )Nc                    sN   |  di } rd v rt r d |d< d v r d |d< t|| d< | S )Nr)   cookiesdata)r#   r   r   )eventhintrequest_infoinfor   r   event_processort   s   zpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor.<locals>.event_processorr   )reqintegrationrA   r?   r   r   _make_request_event_processorr   s   zzpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app.<locals>._make_request_event_processor)r-   
get_clientget_integrationr   r+   r.   r(   r1   r   extract_request_infor   _nameadd_event_processor)r4   r5   rC   r)   r7   	extractorrD   )old_appr?   r   _sentry_appc   s"   zSpatch_get_request_handler.<locals>._sentry_get_request_handler.<locals>._sentry_app)r#   callasyncioiscoroutinefunctionr   )r4   r5   r,   r9   rL   old_get_request_handler)rK   r8   r   _sentry_get_request_handlerH   s   


(z>patch_get_request_handler.<locals>._sentry_get_request_handler)r   routingget_request_handler)rR   r   rP   r   r   D   s   Er   )rN   copyr   	functoolsr   r-   sentry_sdk.integrationsr   sentry_sdk.scoper   sentry_sdk.tracingr   r   sentry_sdk.utilsr   typingr	   r
   r   r   sentry_sdk._typesr   !sentry_sdk.integrations.starletter   r   r   ImportErrorr%   r   r+   r   r   r   r   r   <module>   s4    	