
    \j\                        d dl Z 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rd d
lmZ d dlmZ d dlmZmZ 	 d dl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* 	 d dl+m,Z, dZ. G d de      Z/d!dZ0d!dZ1ddde2ddddfdZ3d"dZ4	 	 	 	 	 	 	 	 d#dZ5	 	 	 	 	 	 	 	 d$dZ6d%d Z7y# e$ r dZY qw xY w# e$ r	 d dl-m,Z, Y \w xY w# e$ r	  ed      w xY w)&    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_started)ScaffoldzQuart is not installed)endpointurlc                   B    e Zd ZdZde ZdZd	deddfdZed
d       Z	y)QuartIntegrationquartz
auto.http. transaction_stylereturnNc                 N    |t         vrt        d|dt         d      || _        y )Nz%Invalid value for transaction_style: z (must be in ))TRANSACTION_STYLE_VALUES
ValueErrorr$   )selfr$   s     G/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/quart.py__init__zQuartIntegration.__init__@   s.    $<<$&>@  "3    c                  &   t        j                  t               t        j                  t               t	        j                  t
               t        j                  t
               t        j                  t
               t                t                y N)
r   connect_request_websocket_startedr   r   _capture_exceptionr   r   patch_asgi_apppatch_scaffold_route r-   r+   
setup_oncezQuartIntegration.setup_onceH   sY     :;!!"<= (();<%%&89''(:;r-   )r   r%   N)
__name__
__module____qualname__
identifieroriginr$   strr,   staticmethodr6   r5   r-   r+   r!   r!   :   s@    J*&F3# 3t 3  r-   r!   r%   c                  \    t         j                  	 	 	 	 	 	 	 	 	 	 dfd} | t         _        y )Nc                     K   t        j                         j                  t                |||       d {   S t	         fdt        j
                  d      } ||||       d {   S 7 67 w)Nc                       g| i |S r/   r5   )akwold_appr*   s     r+   <lambda>zApatch_asgi_app.<locals>.sentry_patched_asgi_app.<locals>.<lambda>^   s    WT4A44 r-      )span_originasgi_version)
sentry_sdk
get_clientget_integrationr!   r   r<   )r*   scopereceivesend
middlewarerD   s   `    r+   sentry_patched_asgi_appz/patch_asgi_app.<locals>.sentry_patched_asgi_appW   sp        "223CDL ugt<<<)4(//


  w555 = 6s!   6A5A11A5,A3-A53A5)
r*   r   rL   r   rM   r   rN   r   r%   r   )r   __call__)rP   rD   s    @r+   r3   r3   T   sB    nnG66!6,169>6	6 -ENr-   c                      t         j                  dk\  rt        j                  nt        j                  t
        j                  dfd} | t
        _        y )N)rF      c                  (     | i |dfd}|S )Nc                      t        j                         r7        s/t               t        t               d fd              } |      S         S )Nc                      t        j                         }|j                  |j                  j                          t        j                         }|j
                  |j
                  j                           | i |S r/   )rI   get_current_scopetransactionupdate_active_threadget_isolation_scopeprofileupdate_active_thread_id)argskwargscurrent_scopesentry_scopeold_funcs       r+   _sentry_funczTpatch_scaffold_route.<locals>._sentry_route.<locals>.decorator.<locals>._sentry_funcv   sm     %/$@$@$BM$00<%11FFH#-#A#A#CL#++7$,,DDF#T4V44r-   r]   r   r^   r   r%   r   )inspect
isfunctionr   r   r!   )ra   rb   iscoroutinefunctionold_decorators   ` r+   	decoratorz>patch_scaffold_route.<locals>._sentry_route.<locals>.decorators   sX    !!(+4G4Qx+,<hG	5 H !	5 %\22 **r-   )ra   r   r%   r   r5   )r]   r^   rh   rg   rf   	old_routes      @r+   _sentry_routez+patch_scaffold_route.<locals>._sentry_routep   s    !4262	+( r-   rc   )sysversion_inford   rf   asyncior   route)rj   rf   ri   s    @@r+   r4   r4   g   s@    
7"%99%99I2 #HNr-   rL   zsentry_sdk.Scoper$   r   r   c                     	 |j                   j                  |j                   j                  d}| j                  ||   t        |          y # t
        $ r Y y w xY w)N)r   r   )source)url_ruleruler   set_transaction_namer	   	Exception)rL   r$   r   name_for_styles       r+    _set_transaction_name_and_sourcerv      sg    
##((((11
 	"",-#$56 	# 	
  s   A
A 	AAc                   K   t        j                         j                  t              }|y t	               rt        j                         }t               rt        j                         }t        t        j                         |j                         t        j                         }t        | ||      }|j                  |       y wr/   )rI   rJ   rK   r!   r   r   _get_current_objectr   r   rv   rW   r$   rZ   _make_request_event_processoradd_event_processor)appr^   integrationrequest_websocketrL   evt_processors         r+   r1   r1      s     '')99:JKK#779%99; %$$&(E(EGX **,E1#7H+VM	m,s   CCc                     dfd}|S )Nc                 b   | S t               5  | j                  di       }j                  |d<   j                  |d<   j                  |d<   t        t        j                              |d<   t               rdj                  d   i|d<   t        |        d d d        | S # 1 sw Y   | S xY w)	Nr   r   query_stringmethodheadersREMOTE_ADDRr   env)r
   
setdefaultr   r   r   r   dictr   r   access_route_add_user_to_event)eventhintrequest_infor   s      r+   innerz,_make_request_event_processor.<locals>.inner   s     ?L(* 	* !++Ir:L")++L+2+?+?L(%,^^L"&5d7??6K&LL#&('4g6J6J16M&NU#"5)	* 	* s   B
B$$B.)r   r   r   zdict[str, Any]r%   r   r5   )r{   r   r|   r   s    `  r+   ry   ry      s    . Lr-   c                    K   t        j                         j                  t              }|y t	        |t        j                         j
                  ddd      \  }}t        j                  ||       y w)Nr"   F)typehandled)client_options	mechanism)r   )rI   rJ   rK   r!   r   optionscapture_event)sender	exceptionr^   r|   r   r   s         r+   r2   r2      sh      '')99:JKK&!,,.66"u5KE4 U.s   A3A5c                     t         y t         j                  }|y t               5  | j                  di       }t         j                  j                  |d<   d d d        y # 1 sw Y   y xY w)Nuserid)
quart_authcurrent_userr
   r   _auth_id)r   r   	user_infos      r+   r   r      s`    ""D|	$	& ;$$VR0	$11::	$; ; ;s   0AA'r7   )r{   r   r^   r   r%   N)r{   r   r   r   r|   r!   r%   r   )r   r   r   z Union[ValueError, BaseException]r^   r   r%   N)r   r   r%   N)8rm   rd   rk   	functoolsr   rI   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!   r3   r4   r=   rv   r1   ry   r2   r   r5   r-   r+   <module>r      sE     
   = @ = 4 / 
 !73  3+ / { 4-&"#J25@I	 -*	$3E:// B/NS/	/ ;G  J2  323  1
/
001s0   C
 #C( C 
CCC%$C%(C6