a
    xd                     @   sn  d dl mZ d dlmZm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 d d	lmZ erd d
lmZ d dlmZ d dlmZ d dlmZ zd dlZW n ey   dZY n0 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Y n0 dZ)G dd deZ*dd Z+dd Z,dd Z-dd Z.dd Z/dS )    )absolute_import)_should_send_default_piiHub)DidNotEnableIntegration)_filter_headers)SentryAsgiMiddleware)Scope)SOURCE_FOR_STYLE)capture_internal_exceptionsevent_from_exception)MYPY)Any)Dict)Union)EventProcessorN)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)endpointurlc                   @   s*   e Zd ZdZdZd	ddZedd ZdS )
QuartIntegrationquart 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&   U/var/www/html/Ranjet/env/lib/python3.9/site-packages/sentry_sdk/integrations/quart.py__init__7   s    zQuartIntegration.__init__c                     sN   t t tt tt tt tt tj	  fdd} | t_	d S )Nc                    sP   t jtd u r$ |||I d H S t fdd}|j|_||||I d H S )Nc                     s    g| R i |S Nr&   )akw)old_appr%   r&   r'   <lambda>Q       zNQuartIntegration.setup_once.<locals>.sentry_patched_asgi_app.<locals>.<lambda>)r   currentget_integrationr   r   Z
_run_asgi3__call__)r%   scopeZreceivesendZ
middlewarer,   )r%   r'   sentry_patched_asgi_appL   s
    z<QuartIntegration.setup_once.<locals>.sentry_patched_asgi_app)
r   connect_request_websocket_startedr   r   _capture_exceptionr   r   r   r1   )r5   r&   r4   r'   
setup_once@   s    




	zQuartIntegration.setup_onceN)r   )__name__
__module____qualname__
identifierr$   r(   staticmethodr9   r&   r&   r&   r'   r   2   s
   
	r   c                 C   sD   z,|j j|j jd}| j|| t| d W n ty>   Y n0 d S )N)r   r   )source)Zurl_ruleZruler   Zset_transaction_namer
   	Exception)r2   r$   r   Zname_for_styler&   r&   r'    _set_transaction_name_and_sourceX   s    
rA   c                 K   s   t j}|t}|d u rd S | P}t r4t }t rBt	 }t
||j| t| ||}|| W d    n1 sz0    Y  d S r)   )r   r/   r0   r   Zconfigure_scoper   r   Z_get_current_objectr   r   rA   r$   _make_request_event_processorZadd_event_processor)appkwargshubintegrationr2   Zrequest_websocketZevt_processorr&   r&   r'   r7   h   s     

r7   c                    s    fdd}|S )Nc                    s    d u r| S t  l | di } j|d<  j|d<  j|d< tt j|d< t rpd j	d i|d< t
|  W d    n1 s0    Y  | S )	Nr   r   query_stringmethodheadersZREMOTE_ADDRr   env)r   
setdefaultr   rG   rH   r   dictrI   r   Zaccess_route_add_user_to_event)eventhintZrequest_infor   r&   r'   inner   s    


&z,_make_request_event_processor.<locals>.innerr&   )rC   r   rF   rQ   r&   rP   r'   rB      s    rB   c                 K   sJ   t j}|td u rd S |j}t||jdddd\}}|j||d d S )Nr    F)typeZhandled)Zclient_optionsZ	mechanism)rO   )r   r/   r0   r   clientr   optionsZcapture_event)Zsender	exceptionrD   rE   rS   rN   rO   r&   r&   r'   r8      s    
r8   c                 C   s`   t d u rd S t j}|d u rd S t ( | di }t jj|d< W d    n1 sR0    Y  d S )Nuserid)
quart_authZcurrent_userr   rK   Z_auth_id)rN   rV   Z	user_infor&   r&   r'   rM      s    rM   )0
__future__r   Zsentry_sdk.hubr   r   Zsentry_sdk.integrationsr   r   Z$sentry_sdk.integrations._wsgi_commonr   Zsentry_sdk.integrations.asgir   Zsentry_sdk.scoper	   Zsentry_sdk.tracingr
   Zsentry_sdk.utilsr   r   Zsentry_sdk._typesr   typingr   r   r   r   rX   ImportErrorr    r   r   r   r   r   r   Zquart.signalsr   r   r   r   r   r"   r   rA   r7   rB   r8   rM   r&   r&   r&   r'   <module>   s:   
  &