o
    h                     @   s  d dl Z d dlZd dlmZ d dlZd dlmZ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mZmZ d d	lmZ erXd d
lmZ d dlmZ d dlmZmZ zd dlZW n eyi   dZY nw z d dlmZmZm Z m!Z!m"Z"m#Z# d dl$m%Z%m&Z&m'Z'm(Z(m)Z) W n ey   edw zd dl*m+Z+ W n ey   d dl,m+Z+ Y nw dZ-G dd deZ.dd Z/dd Z0dd Z1dd Z2dd Z3dd Z4d d! Z5dS )"    N)wraps)DidNotEnableIntegration)_filter_headers)SentryAsgiMiddleware)should_send_default_pii)SOURCE_FOR_STYLE)capture_internal_exceptionsensure_integration_enabledevent_from_exception)TYPE_CHECKING)Any)Union)EventEventProcessor)has_request_contexthas_websocket_contextRequestQuartrequest	websocket)got_background_exceptiongot_request_exceptiongot_websocket_exceptionrequest_startedwebsocket_startedzQuart is not installed)Scaffold)endpointurlc                   @   s4   e Zd ZdZde ZdZd
ddZedd Zd	S )QuartIntegrationquartz
auto.http. r   c                 C   s"   |t vrtd|t f || _d S )Nz7Invalid value for transaction_style: %s (must be in %s))TRANSACTION_STYLE_VALUES
ValueErrortransaction_style)selfr$    r&   _/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/quart.py__init__?   s   
zQuartIntegration.__init__c                   C   sB   t t tt tt tt tt t  t	  d S N)
r   connect_request_websocket_startedr   r   _capture_exceptionr   r   patch_asgi_apppatch_scaffold_router&   r&   r&   r'   
setup_onceH   s   





zQuartIntegration.setup_onceN)r   )	__name__
__module____qualname__
identifieroriginr$   r(   staticmethodr/   r&   r&   r&   r'   r   9   s    

	r   c                        t j  fdd} | t _d S )Nc                    sT   t  td u r |||I d H S t fddtjdd}||||I d H S )Nc                     s    g| R i |S r)   r&   )akw)old_appr%   r&   r'   <lambda>`   s    zApatch_asgi_app.<locals>.sentry_patched_asgi_app.<locals>.<lambda>   )span_originasgi_version)
sentry_sdk
get_clientget_integrationr   r   r4   )r%   scopereceivesend
middlewarer9   )r%   r'   sentry_patched_asgi_appZ   s   z/patch_asgi_app.<locals>.sentry_patched_asgi_app)r   __call__)rF   r&   rE   r'   r-   V   s   
r-   c                     r6   )Nc                     s   | i |  fdd}|S )Nc                    sB   t  rt st tt  fdd}|S  S )Nc                     sF   t  }|jd ur|j  t  }|jd ur|j   | i |S r)   )r>   get_current_scopetransactionupdate_active_threadget_isolation_scopeprofileupdate_active_thread_id)argskwargscurrent_scopesentry_scopeold_funcr&   r'   _sentry_funcx   s   



zTpatch_scaffold_route.<locals>._sentry_route.<locals>.decorator.<locals>._sentry_func)inspect
isfunctionasyncioiscoroutinefunctionr   r
   r   )rS   rT   old_decoratorrR   r'   	decoratorq   s   z>patch_scaffold_route.<locals>._sentry_route.<locals>.decoratorr&   )rN   rO   r[   	old_routerY   r'   _sentry_routem   s   z+patch_scaffold_route.<locals>._sentry_route)r   route)r^   r&   r\   r'   r.   i   s   
r.   c                 C   sD   z|j j|j jd}| j|| t| d W d S  ty!   Y d S w )N)r   r   )source)url_ruleruler   set_transaction_namer   	Exception)rA   r$   r   name_for_styler&   r&   r'    _set_transaction_name_and_source   s   rf   c                    sl   t  t}|d u rd S t rt }t rt }t	t 
 |j| t  }t| ||}|| d S r)   )r>   r?   r@   r   r   r   _get_current_objectr   r   rf   rH   r$   rK   _make_request_event_processoradd_event_processor)apprO   integrationrequest_websocketrA   evt_processorr&   r&   r'   r+      s   r+   c                    s    fdd}|S )Nc                    s    d u r| S t  ? | di } j|d<  j|d<  j|d< tt j|d< t r@d j	d i|d< t
|  W d    | S W d    | S 1 sKw   Y  | S )	Nr   r   query_stringmethodheadersREMOTE_ADDRr   env)r	   
setdefaultr   rn   ro   r   dictrp   r   access_route_add_user_to_event)eventhintrequest_infor   r&   r'   inner   s$   





z,_make_request_event_processor.<locals>.innerr&   )rj   r   rk   r{   r&   rz   r'   rh      s   rh   c                    sL   t  t}|d u rd S t|t  jdddd\}}t j||d d S )Nr    F)typehandled)client_options	mechanism)rx   )r>   r?   r@   r   r   optionscapture_event)sender	exceptionrO   rk   rw   rx   r&   r&   r'   r,      s   
r,   c                 C   sb   t d u rd S t j}|d u rd S t  | di }t jj|d< W d    d S 1 s*w   Y  d S )Nuserid)
quart_authcurrent_userr	   rs   _auth_id)rw   r   	user_infor&   r&   r'   rv      s   "rv   )6rW   rU   	functoolsr   r>   sentry_sdk.integrationsr   r   $sentry_sdk.integrations._wsgi_commonr   sentry_sdk.integrations.asgir   sentry_sdk.scoper   sentry_sdk.tracingr   sentry_sdk.utilsr	   r
   r   typingr   r   r   sentry_sdk._typesr   r   r   ImportErrorr    r   r   r   r   r   r   quart.signalsr   r   r   r   r   quart.scaffoldr   flask.sansio.scaffoldr"   r   r-   r.   rf   r+   rh   r,   rv   r&   r&   r&   r'   <module>   sP      &