
    gh2                        S SK r S SKrS SKJr  S SKJr  S SKrS SKJr  S SKJ	r	  S SK
JrJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJrJrJrJrJrJrJr  S SKJr  \(       aD  S SKJ r   S SKJ!r!  S SKJ"r"  S SKJ#r#  S SKJ$r$  S SKJ%r%  S SK&J'r'J(r(  S SK)J*r*  S SK+J,r,J-r-J.r.J/r/  S SK0J1r1   S SK2J3r3J4r5  S SK6J7r7  S SK0J8r8  S SK9J:r:  \:Rx                  r=\3R|                  r?\8R                  rA \3R                  rC " S S\5      rE " S S\5      rFS rGS  rHS! rBS" rIS*S# jrJS$ rKS% rLS& rMS' rN\" \E5      S( 5       rOS) rPg! \; a	    \" S5      ef = f! \D a     N_f = f)+    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                   P    \ rS rSrSrS\ 3rSr\" S15      4S jr\	S 5       r
Srg)	SanicIntegration:   sanicz
auto.http.Ni  c                 4    U=(       d
    [        5       U l        g)a  
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     `/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/sanic.py__init__SanicIntegration.__init__?   s     $6#>     c                  j   [        [        5      [        l        [	        [        [        R                  5        [
        (       d  [        S[        -   5      e[        R                  " S5      (       a  [        S5        [        R                  b  [        R                  S:  a  [        5         g [        5         g )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 r5   r2   
setup_onceSanicIntegration.setup_onceI   s     $1#? /1A1I1IJ## 24MN 
 ##F++ &!##/4D4L4Lw4V!r5   )r/   )__name__
__module____qualname____firstlineno__
identifieroriginr<   	frozensetr3   staticmethodrA   __static_attributes__r@   r5   r2   r*   r*   :   s;    J*&FG*3SE*: ?  r5   r*   c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)SanicRequestExtractorj   c                 p    U R                   R                  c  g[        U R                   R                  5      $ )Nr   )requestbodylenr0   s    r2   content_length$SanicRequestExtractor.content_lengthk   s*    <<$4<<$$%%r5   c                 @    [        U R                  R                  5      $ N)dictrP   cookiesrS   s    r2   rY   SanicRequestExtractor.cookiesq   s    DLL(())r5   c                 .    U R                   R                  $ rW   )rP   rQ   rS   s    r2   raw_dataSanicRequestExtractor.raw_datau       ||   r5   c                 .    U R                   R                  $ rW   )rP   formrS   s    r2   r`   SanicRequestExtractor.formy   r^   r5   c                     [        5       erW   )NotImplementedErrorrS   s    r2   is_jsonSanicRequestExtractor.is_json}   s    !##r5   c                 .    U R                   R                  $ rW   )rP   jsonrS   s    r2   rg   SanicRequestExtractor.json   r^   r5   c                 .    U R                   R                  $ rW   )rP   filesrS   s    r2   rj   SanicRequestExtractor.files   s    ||!!!r5   c                 >    [        UR                  =(       d    S5      $ )Nr@   )rR   rQ   )r0   files     r2   size_of_file"SanicRequestExtractor.size_of_file   s    499?##r5   r@   N)rC   rD   rE   rF   rT   rY   r\   r`   rd   rg   rj   rn   rK   r@   r5   r2   rM   rM   j   s*    &*!!$!"$r5   rM   c                  @    [         [        l         [        [        l        g rW   )_startupr$   _sentry_error_handler_lookupr(   lookupr@   r5   r2   r?   r?      s    EN6Lr5   c                  ^    [         [        l        [        [        l        [        [        l        g rW   )	_legacy_handle_requestr$   handle_request_legacy_router_getr'   getrr   r(   rs   r@   r5   r2   r>   r>      s    1E#FJ6Lr5   c                    #    U R                  S5      " [        5        U R                  S5      " [        5        U R                  S5      " [        5        [	        U 5      I S h  vN   g  N7f)Nzhttp.lifecycle.requestzhttp.lifecycle.responsezhttp.routing.after)signal_context_enter_context_exit_set_transactionold_startuprS   s    r2   rq   rq      sR      	KK().9 	KK)*=9 	KK$%&67 d
s   A A*"A(#A*c                   #    [         R                  " 5       R                  [        5      S LU R                  l        U R                  R
                  (       d  g [        R                  " U 5      n[         R                  " 5       U R                  l	        U R                  R                  R                  5       nUR                  5         UR                  [        U5      5        [        [        U R                   5      ["        R$                  U R&                  [(        R*                  [        R,                  S9n[         R.                  " U5      R                  5       U R                  l        g 7f)N)opnamesourcerH   )
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   rX   headersr   HTTP_SERVERpathr   URLrH   start_transaction_sentry_transaction)rP   weak_requestscopetransactions       r2   r{   r{      s      	//0@AM KK& ;;--;;w'L * : : <GKKKK%%//1E		5lCD W__>>\\ $$&&K '1&B&B'ik KK#s   E&E(c                   #    [        5          U R                  R                  (       d
   S S S 5        g [        R                  " 5       R                  [        5      nUc  S OUR                  n[        5          U R                  R                  R                  U5        U R                  R                  =R                  [        U[        5      =(       a    X2R                  ;  -  sl
        U R                  R                  R                  S S S 5        S S S 5        U R                  R                  R                  S S S 5        S S S 5        g ! , (       d  f       N>= f! , (       d  f       g = f7frW   )r   r   r   r   r   r   r*   statusr   set_http_statussampled
isinstancer/   __exit__r   )rP   responseintegrationresponse_statuss       r2   r|   r|      s    	$	&{{11 
'	& !++-==>NO"*"2$ )*KK++;;OLKK++33;(89 K#+J+JJ3 KK++44T4F + 	!!**4t<% 
'	& +* 
'	&s@   E)E	E)AE6BE/E>	E)
E	E
E&"E)c                 p  #    U R                   R                  (       a  [        5          [        R                  " 5       nUR
                  R                  U R                  R
                  S5      R                  S5      nUR                  U[        R                  S9  S S S 5        g g ! , (       d  f       g = f7f)N .r   )r   r   r   r   get_current_scoper   replaceappstripset_transaction_namer   	COMPONENT)rP   route_r   
route_names        r2   r}   r}      s~     {{))(*002E++GKK,<,<bAGGLJ&&z:K:U:U&V +* ***s   &B6A3B%
B6%
B3/B6c                    ^ [        U5        [        X/UQ70 UD6mTc  g [        R                  " 5       R	                  [
        5      c  T$ U4S jnU$ )Nc                 T  >#     T" X5      n[        U5      (       a
  UI S h  vN nU[        R                  (       a)  [        R                  S:X  a  [        U 5      I S h  vN   $ $ $  ND N	! [         a+    [
        R                  " 5       n[        U5        [        U6    Of = f [        R                  (       a*  [        R                  S:X  a  [        U 5      I S h  vN    g g g ! [        R                  (       a*  [        R                  S:X  a  [        U 5      I S h  vN    f f f = f7f)Nr8   )	r   r*   r<   r|   	Exceptionsysexc_info_capture_exceptionr   )rP   	exceptionr   r   old_error_handlers       r2   sentry_wrapped_error_handlerB_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+ 7D(A) D('A+ )D(+2B C$ B  C$ $7D(CD($8D%DD%%D()r   old_error_handler_lookupr   r   r   r*   )r0   r   argskwargsr   r   s        @r2   rr   rr      sW    y!0R4R6R ../?@H  -( ('r5   c                   #    [         R                  " 5       R                  [        5      c  [	        X/UQ70 UD6I S h  vN $ [
        R                  " U5      n[         R                  " 5        nUR                  5         UR                  [        U5      5        [	        X/UQ70 UD6n[        U5      (       a
  UI S h  vN nUsS S S 5        $  N N! , (       d  f       g = f7frW   )r   r   r   r*   old_handle_requestr   r   r   r   r   r   r   )r0   rP   r   r   r   r   r   s          r2   ru   ru     s     ../?@H'GGGGG;;w'L		#	#	%!!!"9,"GH%dEdEfEx  %~H 
&	%	 H & 
&	%s:   <C"C/C".AC=C>CC"C
CC"c                    [        U /UQ76 n[        R                  " 5       R                  [        5      b  [        5          [        R                  " 5       n[        R                  (       a  [        R                  S:  ax  U R                  R                  R                  nUS   R                  nUR                  SU-  5      (       a  U[        U5      S-   S  nUR                  U[        R                  S9  O+UR                  US   R                   [        R                  S9  S S S 5        U$ U$ ! , (       d  f       U$ = f)N)r9      r   z%s.   r   )old_router_getr   r   r   r*   r   get_isolation_scoper<   r   r   r   r=   rR   r   r   r   rC   )r0   r   rvr   sanic_app_namesanic_routes         r2   rw   rw     s   		$t	$B../?@L(*224E'',<,D,D,O "&!2!2 ejj))%.*@AA #.c..AA.E.G"HK**(9(C(C +  **qENN+<+F+F + ' +. I2I/ +*. Is    C"D..
D=c                 L   [        5          [        U [        R                  " 5       R                  SSS.S9u  pU(       a8  [        US   S   S5      (       a!  US   S   R                  (       a
   S S S 5        g [        R                  " XS9  S S S 5        g ! , (       d  f       g = f)	Nr,   F)typehandled)client_options	mechanismr   r   quiet)hint)r   r   r   r   optionshasattrr   capture_event)r   eventr   s      r2   r   r   =  s     
%	&*%002::&59
 GD,Q/99d:>Nq>Q>W>W 
'	& 	  2 
'	&	&s   A$B8B
B#c                    ^  U 4S jnU$ )Nc                 8  >  U(       a  [        US   S   [        5      (       a  g T" 5       nUc  U $ [        5          [	        U5      nUR                  U 5        U S   n[        UR                  5      nUR                  < SUR                  < UR                  < 3US'   UR                  US'   UR                  US'   SUR                  0US	'   [        [        UR                   5      5      US
'   S S S 5        U $ ! [         a     Nf = f! , (       d  f       U $ = f)Nr   r   rP   z://urlquery_stringmethodREMOTE_ADDRenvr   )
issubclassr&   KeyErrorr   rM   extract_into_eventr   r   schemenetlocr   queryr   remote_addrr   rX   r   )r   r   rP   	extractorrequest_infourlpartsr   s         r2   sanic_processor0_make_request_processor.<locals>.sanic_processorO  s   	
4
#3A#6GG .?L(*-g6I((/ +L,H #L ,4>>L(%,^^L"#0'2E2E"FL&5d7??6K&LL#! +$ 3  		 +*$ s   "C: B4D
:
DD

Dr@   )r   r   s   ` r2   r   r   M  s    B r5   rW   )Qr   r   inspectr   urllib.parser   r   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%   r;   sanic.exceptionsr&   r'   sanic.handlersr(   ImportErrorrs   r   rv   r   rx   r   rq   r~   AttributeErrorr*   rM   r?   r>   r{   r|   r}   rr   ru   rw   r   r   r@   r5   r2   <module>r      s=   
   !  %   U U R 9 0   !)8/FF".9/#+ (.. )) 	..K
-{ -`!$, !$H77(8=.W(D$< ,-3 .3#C	  .
,
--.  		s   'D7 &E	 7E	EE