
    lh2                        d dl Z 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mZ d dlmZmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZmZ d dlmZ erDd dl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% d dl&m'Z'm(Z( d dl)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1 	 d dl2m3Z3m4Z5 d dl6m7Z7 d dl0m8Z8 d dl9m:Z: e:jx                  Z=e3j|                  Z?e8j                  ZA	 e3j                  ZC G d de      ZE G d de      ZFd ZGd  ZHd! ZBd" ZId*d#ZJd$ ZKd% ZLd& ZMd' ZN eeE      d(        ZOd) ZPy# e;$ r	  ed      w xY w# eD$ r Y \w xY w)+    N)isawaitable)urlsplit)continue_trace)OP)_check_minimum_versionIntegrationDidNotEnable)RequestExtractor_filter_headers)ignore_logger)TransactionSource)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionHAS_REAL_CONTEXTVARSCONTEXTVARS_ERROR_MESSAGEparse_versionreraise)TYPE_CHECKING)	Container)Any)Callable)Optional)Union)Dict)RequestRequestParameters)BaseHTTPResponse)EventEventProcessorExcInfoHint)Route)Sanic__version__)SanicException)Router)ErrorHandlerzSanic not installedc                   F    e Zd ZdZde ZdZ edh      fdZed        Z	y)SanicIntegrationsanicz
auto.http.Ni  c                 *    |xs
 t               | _        y)aG  
        The unsampled_statuses parameter can be used to specify for which HTTP statuses the
        transactions should not be sent to Sentry. By default, transactions are sent for all
        HTTP statuses, except 404. Set unsampled_statuses to None to send transactions for all
        HTTP statuses, including 404.
        N)set_unsampled_statuses)selfunsampled_statusess     o/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/sanic.py__init__zSanicIntegration.__init__?   s     $6#>     c                  P   t        t              t        _        t	        t        t        j                         t
        st        dt        z         t        j                  d      rt        d       t        j                  t        j                  dk  rt                y t                y )NzUThe sanic integration for Sentry requires Python 3.7+  or the aiocontextvars package.z0.8.root   	   )r   SANIC_VERSIONr*   versionr   r   r	   r   
startswithr   _setup_legacy_sanic_setup_sanic r3   r1   
setup_oncezSanicIntegration.setup_onceI   s     $1#? /1A1I1IJ# 24MN 
 ##F+ &!##/4D4L4Lw4V!r3   )
__name__
__module____qualname__
identifieroriginr:   	frozensetr2   staticmethodr?   r>   r3   r1   r*   r*   :   s;    J*&FG*3SE*: ?  r3   r*   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
SanicRequestExtractorc                 n    | j                   j                  yt        | j                   j                        S )Nr   )requestbodylenr/   s    r1   content_lengthz$SanicRequestExtractor.content_lengthk   s*    <<$4<<$$%%r3   c                 @    t        | j                  j                        S N)dictrJ   cookiesrM   s    r1   rR   zSanicRequestExtractor.cookiesq   s    DLL(())r3   c                 .    | j                   j                  S rP   )rJ   rK   rM   s    r1   raw_datazSanicRequestExtractor.raw_datau       ||   r3   c                 .    | j                   j                  S rP   )rJ   formrM   s    r1   rW   zSanicRequestExtractor.formy   rU   r3   c                     t               rP   )NotImplementedErrorrM   s    r1   is_jsonzSanicRequestExtractor.is_json}   s    !##r3   c                 .    | j                   j                  S rP   )rJ   jsonrM   s    r1   r\   zSanicRequestExtractor.json   rU   r3   c                 .    | j                   j                  S rP   )rJ   filesrM   s    r1   r^   zSanicRequestExtractor.files   s    ||!!!r3   c                 4    t        |j                  xs d      S )Nr>   )rL   rK   )r/   files     r1   size_of_filez"SanicRequestExtractor.size_of_file   s    499?##r3   N)r@   rA   rB   rN   rR   rT   rW   rZ   r\   r^   ra   r>   r3   r1   rH   rH   j   s*    &*!!$!"$r3   rH   c                  @    t         t        _         t        t        _        y rP   )_startupr$   _sentry_error_handler_lookupr(   lookupr>   r3   r1   r=   r=      s    EN6Lr3   c                  ^    t         t        _        t        t        _        t        t        _        y rP   )	_legacy_handle_requestr$   handle_request_legacy_router_getr'   getrd   r(   re   r>   r3   r1   r<   r<      s    1E#FJ6Lr3   c                    K    | j                  d      t                | j                  d      t                | j                  d      t               t	        |        d {    y 7 w)Nzhttp.lifecycle.requestzhttp.lifecycle.responsezhttp.routing.after)signal_context_enter_context_exit_set_transactionold_startuprM   s    r1   rc   rc      sY      *DKK().9 +DKK)*=9 &DKK$%&67 d
s   A A*"A(#A*c                   K   t        j                         j                  t              d u| j                  _        | j                  j
                  sy t        j                  |       }t        j                         | j                  _	        | j                  j                  j                         }|j                          |j                  t        |             t        t        | j                         t"        j$                  | j&                  t(        j*                  t        j,                        }t        j.                  |      j                         | j                  _        y w)N)opnamesourcerD   )
sentry_sdk
get_clientget_integrationr*   ctx_sentry_do_integrationweakrefrefisolation_scope_sentry_scope	__enter__clear_breadcrumbsadd_event_processor_make_request_processorr   rQ   headersr   HTTP_SERVERpathr   URLrD   start_transaction_sentry_transaction)rJ   weak_requestscopetransactions       r1   rm   rm      s      	//0@AM KK& ;;--;;w'L * : : <GKKKK%%//1E		5lCD W__>>\\ $$&&K '1&B&B'ik KK#s   E E"c                   K   t               5  | j                  j                  s
	 d d d        y t        j                         j                  t              }|d n|j                  }t               5  | j                  j                  j                  |       | j                  j                  xj                  t        |t              xr ||j                  vz  c_
        | j                  j                  j                  d d d        d d d        | j                  j                  j                  d d d        d d d        y # 1 sw Y   9xY w# 1 sw Y   y xY wwrP   )r   rx   ry   ru   rv   rw   r*   statusr   set_http_statussampled
isinstancer.   __exit__r}   )rJ   responseintegrationresponse_statuss       r1   rn   rn      s    	$	& ={{11= = !++-==>NO"*"2$ )* 	GKK++;;OLKK++33;(89 K#;+J+JJ3 KK++44T4F	G 	!!**4t<%= =	G 	G= =s@   EE	EAE/BD;/E2	E;E	 EEEc                 `  K   | j                   j                  rt               5  t        j                         }|j
                  j                  | j                  j
                  d      j                  d      }|j                  |t        j                         d d d        y y # 1 sw Y   y xY ww)N .rt   )rx   ry   r   ru   get_current_scopers   replaceappstripset_transaction_namer   	COMPONENT)rJ   route_r   
route_names        r1   ro   ro      s     {{))(* 	W002E++GKK,<,<bAGGLJ&&z:K:U:U&V	W 	W *	W 	Ws   !B.A5B"
B."B+'B.c                     t        |       t        | |g|i |y t        j                         j	                  t
              S fd}|S )Nc                 $  K   	  | |      }t        |      r
| d {   }|t        j                  r(t        j                  dk(  rt        |        d {    S S S 7 >7 	# t        $ r* t        j                         }t        |       t        |  Y nw xY w	 t        j                  r)t        j                  dk(  rt        |        d {  7   y y y # t        j                  r)t        j                  dk(  rt        |        d {  7   w w w xY ww)Nr6   )	r   r*   r:   rn   	Exceptionsysexc_info_capture_exceptionr   )rJ   	exceptionr   r   old_error_handlers       r1   sentry_wrapped_error_handlerzB_sentry_error_handler_lookup.<locals>.sentry_wrapped_error_handler   s     	-()<H8$!)>  '',<,D,D,O#G,,, -P' * -  	 ||~Hx(X	   '',<,D,D,O#G,,, -P''',<,D,D,O#G,,, -P'ss   DA! AA! 1DADA! D!0BC BC 1D	C
D2DDDD)r   old_error_handler_lookupru   rv   rw   r*   )r/   r   argskwargsr   r   s        @r1   rd   rd      sY    y!0yR4R6R ../?@H  -( ('r3   c                   K   t        j                         j                  t              t	        | |g|i | d {   S t        j                  |      }t        j                         5 }|j                          |j                  t        |             t	        | |g|i |}t        |      r
| d {   }|cd d d        S 7 7 # 1 sw Y   y xY wwrP   )ru   rv   rw   r*   old_handle_requestrz   r{   r|   r   r   r   r   )r/   rJ   r   r   r   r   r   s          r1   rg   rg     s     ../?@H'gGGGGG;;w'L		#	#	% !!!"9,"GH%dGEdEfEx %~H 	 H & s:   ;CC-C+AC
6C7C
<CC

CCc                 f   t        | g| }t        j                         j                  t              t               5  t        j                         }t        j                  rt        j                  dk\  rv| j                  j                  j                  }|d   j                  }|j                  d|z        r|t        |      dz   d  }|j                  |t        j                         n.|j                  |d   j                   t        j                         d d d        |S |S # 1 sw Y   |S xY w)N)r7      r   z%s.   r   )old_router_getru   rv   rw   r*   r   get_isolation_scoper:   rx   r   rs   r;   rL   r   r   r   r@   )r/   r   rvr   sanic_app_namesanic_routes         r1   ri   ri     s   		$t	$B../?@L(* 	224E'',<,D,D,O "&!2!2 ejj))%.*@A #.c..AA.E.G"HK**(9(C(C +  **qENN+<+F+F + '	. I2I/	. Is   CD&&D0c                 0   t               5  t        | t        j                         j                  ddd      \  }}|r.t        |d   d   d      r|d   d   j                  r
	 d d d        y t        j                  ||       d d d        y # 1 sw Y   y xY w)	Nr+   F)typehandled)client_options	mechanismr   r   quiet)hint)r   r   ru   rv   optionshasattrr   capture_event)r   eventr   s      r1   r   r   =  s     
%	& 
3*%002::&59
t GD,Q/9d:>Nq>Q>W>W
3 
3 	  T2
3 
3 
3s   AB,BBc                       fd}|S )Nc                    	 |rt        |d   d   t              ry         }|| S t               5  t	        |      }|j                  |        | d   }t        |j                        }|j                  d|j                  |j                  |d<   |j                  |d<   |j                  |d<   d|j                  i|d	<   t        t        |j                               |d
<   d d d        | S # t        $ r Y w xY w# 1 sw Y   | S xY w)Nr   r   rJ   z://urlquery_stringmethodREMOTE_ADDRenvr   )
issubclassr&   KeyErrorr   rH   extract_into_eventr   r   schemenetlocr   queryr   remote_addrr   rQ   r   )r   r   rJ   	extractorrequest_infourlpartsr   s         r1   sanic_processorz0_make_request_processor.<locals>.sanic_processorO  s   	
4
#3A#6G .?L(* 	M-g6I((/ +L,H #L ,4>>L(%,^^L"#0'2E2E"FL&5d7??6K&LL#!	M$ 3  			M$ s   C, B1C;,	C87C8;Dr>   )r   r   s   ` r1   r   r   M  s    B r3   rP   )Qr   rz   inspectr   urllib.parser   ru   r   sentry_sdk.constsr   sentry_sdk.integrationsr   r   r	   $sentry_sdk.integrations._wsgi_commonr
   r   sentry_sdk.integrations.loggingr   sentry_sdk.tracingr   sentry_sdk.utilsr   r   r   r   r   r   r   typingr   collections.abcr   r   r   r   r   r   sanic.requestr   r   sanic.responser   sentry_sdk._typesr   r    r!   r"   sanic.routerr#   r+   r$   r%   r9   sanic.exceptionsr&   r'   sanic.handlersr(   ImportErrorre   r   rh   r   rj   r   rc   rp   AttributeErrorr*   rH   r=   r<   rm   rn   ro   rd   rg   ri   r   r   r>   r3   r1   <module>r      s=   
   !  %   U U R 9 0   !)8/FF".9/#+ (.. )) 	..K
-{ -`!$, !$H77(8=.W(D$< ,-3 .3#C	  .
,
--.  		s   "D1 !E 1D?E
	E
