
    fi2                        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: n# e;$ r  ed          w xY we:j<        Z=e3j>        Z?e8j@        ZA	 e3jB        ZCn# eD$ r Y nw xY w G d de          ZE G d de          ZFd ZGd  ZHd! ZBd" ZId*d#ZJd$ ZKd% ZLd& ZMd' ZN eeE          d(             ZOd) ZPdS )+    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                   T    e Zd ZdZde ZdZ edh          fdZed             Z	dS )SanicIntegrationsanicz
auto.http.Ni  c                 0    |pt                      | _        dS )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     m/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/sentry_sdk/integrations/sanic.py__init__zSanicIntegration.__init__?   s     $6#>       c                  v   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                       d S t                       d S )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#?#? /1A1IJJJ# 	 24MN  
 #F++ 
	" &!!!#/4D4Lw4V4V!!!Fr3   )
__name__
__module____qualname__
identifieroriginr:   	frozensetr2   staticmethodr?   r>   r3   r1   r*   r*   :   si        J&*&&FG*3)SE*:*: ? ? ? ?   \  r3   r*   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
SanicRequestExtractorc                 P    | j         j        dS t          | j         j                  S )Nr   )requestbodylenr/   s    r1   content_lengthz$SanicRequestExtractor.content_lengthk   s%    <$14<$%%%r3   c                 4    t          | j        j                  S N)dictrJ   cookiesrM   s    r1   rR   zSanicRequestExtractor.cookiesq   s    DL()))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                 .    t          |j        pd          S )Nr>   )rL   rK   )r/   files     r1   size_of_filez"SanicRequestExtractor.size_of_file   s    49?###r3   N)r@   rA   rB   rN   rR   rT   rW   rZ   r\   r^   ra   r>   r3   r1   rH   rH   j   s        & & &* * *! ! !! ! !$ $ $! ! !" " "$ $ $ $ $r3   rH   c                  J    t           t          _         t          t          _        d S rP   )_startupr$   _sentry_error_handler_lookupr(   lookupr>   r3   r1   r=   r=      s    EN6Lr3   c                  l    t           t          _        t          t          _        t          t          _        d S rP   )	_legacy_handle_requestr$   handle_request_legacy_router_getr'   getrd   r(   re   r>   r3   r1   r<   r<      s    1E#FJ6Lr3   c                   K    |                      d          t                      |                      d          t                      |                      d          t                     t	          |            d {V  d S )Nzhttp.lifecycle.requestzhttp.lifecycle.responsezhttp.routing.after)signal_context_enter_context_exit_set_transactionold_startuprM   s    r1   rc   rc      s       *DKK()).999 +DKK)**=999 &DKK$%%&6777 d

r3   c                   K   t          j                                        t                    d u| j        _        | j        j        sd S t          j        |           }t          j                    | j        _	        | j        j	        
                                }|                                 |                    t          |                     t          t          | j                  t"          j        | j        t(          j        t          j                  }t          j        |          
                                | j        _        d S )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AM K& ;- ;w''L * : < <GKK%//11E		5lCCDDD W_>\ $&  K '1&B' 'ikk K###r3   c                 r  K   t                      5  | j        j        s	 d d d            d S t          j                                        t                    }|d n|j        }t                      5  | j        j        	                    |           | j        j        xj
        t          |t                    o||j        vz  c_
        | j        j                            d d d            d d d            n# 1 swxY w Y   | j        j                            d d d            d d d            d S # 1 swxY w Y   d S 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 	= = = = = = = = !+--==>NOO"*"2$$ )** 	G 	GK+;;OLLLK+33;(899 K#;+JJ33 K+44T4FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	!**4t<<<%= = = = = = = = = = = = = = = = = =s<   D,AD,0A7C3'D,3C7	7D,:C7	;$D,,D03D0c                 L  K   | j         j        rt                      5  t          j                    }|j                            | j        j        d                              d          }|	                    |t          j                   d d d            d S # 1 swxY w Y   d S d S )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(** 	W 	W022E++GK,<bAAGGLLJ&&z:K:U&VVV	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	W 	WW Ws   A-BBBc                     t          |           t          | |g|R i |d S t          j                                        t
                    S fd}|S )Nc                   K   	  | |          }t          |          r| d {V }|t          j        r&t          j        dk    rt          |            d {V  S S S # t          $ r. t          j                    }t          |           t          |  Y nw xY w	 t          j        r't          j        dk    rt          |            d {V  d S d S d S # t          j        r&t          j        dk    rt          |            d {V  w w w xY 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   so     	-(()<<H8$$ *!)>>>>>>  ' -,<,D,O,O#G,,,,,,,,,,-,O  	 	 	 |~~Hx(((X	   ' -,<,D,O,O#G,,,,,,,,,,,- -,O,O' -,<,D,O,O#G,,,,,,,,,,-,Os#   $A 5BC BC 5D)r   old_error_handler_lookupru   rv   rw   r*   )r/   r   argskwargsr   r   s        @r1   rd   rd      s    y!!!0yR4RRR6RR t../?@@H  - - - - -( ('r3   c                   K   t          j                                        t                    t	          | |g|R i | d {V S t          j        |          }t          j                    5 }|                                 |	                    t          |                     t	          | |g|R i |}t          |          r| d {V }|cd d d            S # 1 swxY w Y   d S 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     sG     ../?@@H'gGGGGGGGGGGGGG;w''L		#	%	% !!!!!"9,"G"GHHH%dGEdEEEfEEx   	&%~~~~~~H                 s   ,A CC Cc                 \   t          | g|R  }t          j                                        t                    t                      5  t          j                    }t          j        rt          j        dk    rr| j        j	        j
        }|d         j
        }|                    d|z            r|t          |          dz   d          }|                    |t          j                   n,|                    |d         j        t          j                   d d d            n# 1 swxY w Y   |S )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     sq   		$t	$	$	$B../?@@L(** 	 	244E' ,<,D,O,O "&!2 ej))%.*@AA I #.c..A.AA.E.G.G"HK**(9(C +     **qEN+<+F +   '	 	 	 	 	 	 	 	 	 	 	 	 	 	 	. Is   CD!!D%(D%c                 Z   t                      5  t          | t          j                    j        ddd          \  }}|r=t          |d         d         d          r!|d         d         j        r	 d d d            d S t          j        ||           d d d            d S # 1 swxY w Y   d S )	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 
3*%022:&599
 
 
t  	GD,Q/99 	d:>Nq>Q>W 	
3 
3 
3 
3 
3 
3 
3 
3 	 T2222
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3 
3s   A!B =B  B$'B$c                       fd}|S )Nc                    	 |r#t          |d         d         t                    rd S n# t          $ r Y nw xY w             }|| S t                      5  t	          |          }|                    |            | d         }t          |j                  }|j        d|j	        |j
        |d<   |j        |d<   |j        |d<   d|j        i|d	<   t          t          |j                            |d
<   d d d            n# 1 swxY w Y   | S )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G t 	 	 	D	 ,..?L(** 	M 	M-g66I((/// +L,,H #L ,4>L(%,^L"#0'2E"FL&5d7?6K6K&L&LL#!	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M$ s   #) 
66B DD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 U U U U U U U U R R R R R R R R 9 9 9 9 9 9 0 0 0 0 0 0                  !           #))))))88888888//////FFFFFFFFFFFF"""""".99999999//////######+++++++ . . .
,,
-
--. (. ) 	.KK 	 	 	D	- - - - -{ - - -`!$ !$ !$ !$ !$, !$ !$ !$H7 7 77 7 7  (  8= = = =.W W W( ( (D  $  < ,--3 3 .-3# # # # #s   "B= =C'C/ /C76C7