
    gh0)                        S SK r S SK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  S SKJrJrJr   S SKJrJr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J r   S SK!J"r"  S SK$J%r%  \%(       a.  S SK$J&r&J'r'J(r(  S SK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r2J3r3J4r4  S SKJ5r5  S SK6J7r7  Sr8 " S S\5      r9 " S S\5      r:S r;S r<S r=S r>S r?\" \95      S 5       r@g! \# a	    \" S5      ef = f)     N)OP)DidNotEnableIntegration)SentryAsgiMiddleware)should_send_default_pii)SOURCE_FOR_STYLETransactionSource)ensure_integration_enabledevent_from_exceptiontransaction_from_function)RequestStarliteState)BaseRouteHandler)DefineMiddleware)get_plugin_for_value)	HTTPRoute)ConnectionDataExtractoris_async_callableRef)	BaseModelzStarlite is not installed)TYPE_CHECKING)AnyOptionalUnion)
ASGIAppHintHTTPReceiveMessage	HTTPScopeMessage
MiddlewareReceiveScopeSendWebSocketReceiveMessage)MiddlewareProtocol)Eventzgeneric Starlite requestc                   2    \ rS rSrSrS\ 3r\S 5       rSrg)StarliteIntegration/   starlitez
auto.http.c                  @    [        5         [        5         [        5         g N)patch_app_initpatch_middlewarespatch_http_route_handle     c/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/starlite.py
setup_onceStarliteIntegration.setup_once3   s     	!r2   r1   N)	__name__
__module____qualname____firstlineno__
identifieroriginstaticmethodr4   __static_attributes__r1   r2   r3   r)   r)   /   s%    J*&F" "r2   r)   c                   B   ^  \ rS rSr\R
                  4U 4S jjrSrU =r$ )SentryStarliteASGIMiddleware;   c           	      *   > [         TU ]  USSSUSS9  g )NFendpointasgi   )appunsafe_context_datatransaction_stylemechanism_typespan_originasgi_version)super__init__)selfrE   rI   	__class__s      r3   rL   %SentryStarliteASGIMiddleware.__init__<   s'     %(!# 	 	
r2   r1   )	r6   r7   r8   r9   r)   r;   rL   r=   __classcell__)rN   s   @r3   r?   r?   ;   s    (;(B(B 	
 	
r2   r?   c                  n   ^ [         R                  m[        [        T5      U4S j5       n U [         l        g)ar  
Replaces the Starlite class's `__init__` function in order to inject `after_exception` handlers and set the
`SentryStarliteASGIMiddleware` as the outmost middleware in the stack.
See:
- https://starlite-api.github.io/starlite/usage/0-the-starlite-app/5-application-hooks/#after-exception
- https://starlite-api.github.io/starlite/usage/7-middleware/0-middleware-intro/
c                    > UR                  S/ 5      nUR                  [        /[        U[        5      (       a  UOU/QS9  UR                  S5      =(       d    / n[        /UQUS'   T" U /UQ70 UD6  g )Nafter_exception)rS   
middleware)popupdateexception_handler
isinstancelistgetr?   )rM   argskwargsrS   rT   old__init__s        r3   injection_wrapper)patch_app_init.<locals>.injection_wrapperS   s     !**%6;! "/488 $)* 	 		
 ZZ-3
 <JzJ|D*4*6*r2   N)r   rL   r
   r)   )r^   r]   s    @r3   r.   r.   H   s5     ##K 3[A+ B+$ *Hr2   c                  n   ^ [         R                  m[        [        T5      U4S j5       n U [         l        g )Nc                 R   > T" U 5       Vs/ s H  n[        U5      PM     sn$ s  snf r-   )enable_span_for_middleware)rM   rT   old_resolve_middleware_stacks     r3   resolve_middleware_wrapper5patch_middlewares.<locals>.resolve_middleware_wrapperm   s4    
 ;4@
@
 'z2@
 	
 
s   $)r   resolve_middlewarer
   r)   )rd   rc   s    @r3   r/   r/   i   s7    #3#F#F  35QR
 S
 +E'r2   c                 B  ^ [        U S5      (       a	  U [        L a  U $ [        U [        5      (       a  U R                  R
                  mOU R
                  mU4S jnTR                  S;  nU(       a-  [        U [        5      (       a  XR                  l        U $ Xl        U $ )N__call__c                 P  >^^^#    [         R                  " 5       R                  [        5      c  T" XTT5      I S h  vN $ U R                  R
                  m[         R                  " [        R                  T[        R                  S9 nUR                  ST5        UU4S jn[        TS[        T5      5      nUS:H  nU(       d  UOTnUU4S jn	[        TS[        T5      5      n
U
S:H  nU(       d  U	OTnT" XX5      I S h  vN sS S S 5        $  N N! , (       d  f       g = f7f)Nopnamer;   starlite.middleware_namec            
        >#    [         R                  " 5       R                  [        5      c  T" U 0 UD6I S h  vN $ [         R                  " [
        R                  [        TS[        T5      5      [        R                  S9 nUR                  ST5        T" U 0 UD6I S h  vN sS S S 5        $  Nv N! , (       d  f       g = f7fNr8   rj   rm   )
sentry_sdk
get_clientget_integrationr)   
start_spanr   MIDDLEWARE_STARLITE_RECEIVEgetattrstrr;   set_tag)r[   r\   spanmiddleware_namereceives      r3   _sentry_receiveNenable_span_for_middleware.<locals>._create_span_call.<locals>._sentry_receive   s     ((*::;NOW!($!9&!999**55 .#g,G.55 LL!;_M!($!9&!99  : : :   5CB/A
CB3!B1"B3%C1B33
C=Cr6   r{   c           
        >#    [         R                  " 5       R                  [        5      c  T" U 5      I S h  vN $ [         R                  " [
        R                  [        TS[        T5      5      [        R                  S9 nUR                  ST5        T" U 5      I S h  vN sS S S 5        $  Nv N! , (       d  f       g = f7fro   )rp   rq   rr   r)   rs   r   MIDDLEWARE_STARLITE_SENDru   rv   r;   rw   )messagerx   ry   sends     r3   _sentry_sendKenable_span_for_middleware.<locals>._create_span_call.<locals>._sentry_send   s     ((*::;NOW!%g..**22 ~s4yA.55 LL!;_M!%g.  / / r}   r   )rp   rq   rr   r)   rN   r6   rs   r   MIDDLEWARE_STARLITEr;   rw   ru   rv   )rM   scoperz   r   middleware_spanr{   receive_namereceive_patchednew_receiver   	send_namesend_patchednew_sendry   old_calls     ``         @r3   _create_span_call5enable_span_for_middleware.<locals>._create_span_call   s      "223FGO!$w===..11""%% &--
 ##$>P
: #7JGEL*.??O1@/gK
/  j#d)<I$6L+7|TH!${EES
 
 >X FS
 
s;   7D&DAD&
A9DDDD&D
D#D&)r   )hasattrr?   rX   r   rT   rh   r6   )rT   r   not_yet_patchedr   s      @r3   rb   rb   x   s     J
++55*.//((11&&/Fb ''/DDOj"233->!!*  #4r2   c                  H   ^ [         R                  mU4S jn U [         l        g )Nc                   >^^^	#    [         R                  " 5       R                  [        5      c  T
" U TX#5      I S h  vN $ [         R                  " 5       nTS   R                  TX#S9n[        SSS9" U5      mTR                  S5      nUI S h  vN m	UU	U4S jn[        R                  Ul	        UR                  U5        T
" U TX#5      I S h  vN $  N NF N7f)NrE   )r   rz   r   T)
parse_bodyparse_querybodyc                   > T	R                  S5      nU R                  S0 5      n[        T	R                  SS5      5      US'   [        5       (       a  TS   US'   Tb  TUS'   S nUR                  b  UR                  nOB[	        UR
                  [        5      (       a  UR
                  R                  nOUR
                  nUb  [        U5      nS[        S	   0nW(       d  [        nS[        R                  0nU R                  UUUS
.5        U $ )Nroute_handlerrequest_bodyr2   content_lengthcookiesdatasourcerB   )r   transactiontransaction_info)rZ   lenr   rl   rX   fnr   valuer   r   _DEFAULT_TRANSACTION_NAMEr	   ROUTErV   )
event_r   request_infofunctx_nametx_infoextracted_request_datarequest_datar   s
          r3   event_processorHpatch_http_route_handle.<locals>.handle_wrapper.<locals>.event_processor   s	   !IIo6M 99Y3L-07C1H-IL)*&((*@*KY'''3V$D!!-',,M,,c22$''--$''3D9!1*!=>G3#%6%<%<=LL+#*(/ Lr2   )rp   rq   rr   r)   get_isolation_scoperequest_classr   rU   r:   _nameadd_event_processor)rM   r   rz   r   sentry_scoper   r   r   r   r   
old_handles    `      @@r3   handle_wrapper/patch_http_route_handle.<locals>.handle_wrapper   s       "223FGO#D%???!557,,, - 
 "9"

" &))&1!z"	H 1;;((9eW;;;i @ "R <s4   7CCACC?CCCCC)r   handle)r   r   s    @r3   r0   r0      s    !!J7<r &Ir2   c                 j   U R                  S5      nU(       d  g [        U[        5      (       a  U$ [        U[        5      (       a  UR                  5       $ [	        US5      (       a  UR                  5       $ [        U5      nU(       a+  [        UR                  5      (       d  UR                  U5      $ g )Nuserasdict)	rZ   rX   dictr   r   r   r   r   to_dict)r   
scope_userplugins      r3   retrieve_user_from_scoper     s    6"J*d##*i((  z8$$  ""!*-F'77~~j))r2   c                 ^   S n[        5       (       a  [        U5      nU(       a;  [        U[        5      (       a&  [        R
                  " 5       nUR                  U5        [        U [        R                  " 5       R                  [        R                  SS.S9u  pV[        R                  " XVS9  g )NF)typehandled)client_options	mechanism)hint)r   r   rX   r   rp   r   set_userr   rq   optionsr)   r:   capture_event)excr   r   	user_infor   r   r   s          r3   rW   rW     s     I  ,U3	Z	400!557i(&!,,.66.99eLKE U.r2   )Arp   sentry_sdk.constsr   sentry_sdk.integrationsr   r   sentry_sdk.integrations.asgir   sentry_sdk.scoper   sentry_sdk.tracingr   r	   sentry_sdk.utilsr
   r   r   r+   r   r   r   starlite.handlers.baser   starlite.middlewarer   starlite.plugins.baser   starlite.routes.httpr   starlite.utilsr   r   r   pydanticr   ImportErrortypingr   r   r   r   starlite.typesr   r   r   r   r    r!   r"   r#   StarliteScoper$   r%   r&   sentry_sdk._typesr'   r   r)   r?   r.   r/   rb   r0   r   rW   r1   r2   r3   <module>r      s       = = 4 B 	41174:.NN" !++   ,' 7 	"+ 	"

#7 

*BEFR=&@& /0/ 1/A  4
2
334s   2C C$