
    gh                      n   S r SSKrSSKrSSK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  SSKJrJr  SSKJr  \(       a,  SS	KJrJrJrJr  SS
KJr  SSKJr  SSKJrJr  \" S\S\4   S9r\" \S5      (       a  \R>                  r\R@                  r O\R>                  rSS jr S r!S r"S r#S r$S r%S r&g)z
Instrumentation for Django 3.0

Since this file contains `async def` it is conditionally imported in
`sentry_sdk.integrations.django` (depending on the existence of
`django.core.handlers.asgi`.
    N)WSGIRequest)OP)SentryAsgiMiddleware)should_send_default_pii)capture_internal_exceptionsensure_integration_enabled)TYPE_CHECKING)AnyCallableUnionTypeVar)ASGIRequest)HttpResponse)EventEventProcessor_F.)boundmarkcoroutinefunctionc                 D    [         R                  R                  U l        U $ N)asyncio
coroutines_is_coroutine)funcs    f/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/django/asgi.pyr   r   1   s    $//==    c                    ^  U 4S jnU$ )Nc                 @  > SSK JnJn  Tc  U $ [        T5      [        :X  a  U $ [        5          U" T5      R                  U 5        S S S 5        [        5       (       a  [        5          U" TU 5        S S S 5        U $ U $ ! , (       d  f       N== f! , (       d  f       U $ = f)Nr   )DjangoRequestExtractor_set_user_info)sentry_sdk.integrations.djangor   r    typer   r   extract_into_eventr   )eventhintr   r    requests       r   asgi_request_event_processorH_make_asgi_request_event_processor.<locals>.asgi_request_event_processor8   s    
	

 ?L=K'L(*"7+>>uE + #$$,.w. / u +* /. s   A='
B=
B
B )r&   r'   s   ` r   "_make_asgi_request_event_processorr*   6   s    2 ('r   c                    ^ ^^^ SSK Jm  T R                  mUU U4S jnUT l        [        T S5      nU(       a)  T R                  m[        TT5      U4S j5       nUT l        g g )Nr   DjangoIntegrationc                   >#    [         R                  " 5       R                  T5      nUc  T" XX#5      I S h  vN $ [        TR	                  U T5      STR
                  UR                  S9R                  nU" XU5      I S h  vN $  NO N7f)NTunsafe_context_dataspan_originhttp_methods_to_capture)
sentry_sdk
get_clientget_integrationr   __get__originr2   
_run_asgi3)	selfscopereceivesendintegration
middlewarer-   clsold_apps	         r   sentry_patched_asgi_handlerCpatch_django_asgi_handler_impl.<locals>.sentry_patched_asgi_handler[   s      ++-==>OP g<<<)OOD#& $)00$/$G$G	

 * 	  555 = 6s"   4BBA
BB	B	Bcreate_requestc                    > T" U /UQ70 UD6u  p4[         R                  " 5       nUR                  [        U5      5        X44$ r   )r3   get_isolation_scopeadd_event_processorr*   )r9   argskwargsr&   error_responser:   old_create_requests         r   sentry_patched_create_requestEpatch_django_asgi_handler_impl.<locals>.sentry_patched_create_requestp   sG     '9&O&O&O#G224E%%&H&QR**r   )r!   r-   __call__hasattrrC   r   )r?   rA   modern_django_asgi_supportrK   r-   r@   rJ   s   `   @@@r   patch_django_asgi_handler_implrP   T   sh     AllG6 /CL!(.>!?! //	#$57I	J	+ 
K	+ ; "r   c                 :   ^^ U R                   mUU4S jnX l         g )Nc                 @   >#    T" U5        T" X5      I S h  vN $  N7fr   r)   )r9   r&   _before_get_responseold_get_response_asyncs     r   !sentry_patched_get_response_asyncCpatch_get_response_async.<locals>.sentry_patched_get_response_async   s     W%+D::::s   )get_response_async)r?   rS   rU   rT   s    ` @r   patch_get_response_asyncrX   |   s     33;
 ?r   c                    ^ ^^ SS K nSSKJm  UR                  S:  a  T R                  mUU U4S jnUT l        g [        T 5        g )Nr   r,   z3.0.0c                   >^ #    [         R                  " 5       R                  T5      nUc  T" T X5      I S h  vN $ [        UUU 4S jSTR                  UR
                  S9nU" T R                  5      " X5      I S h  vN $  NJ N7f)Nc                 (   > TR                  TT5      $ r   )r6   )_scoper?   r@   r9   s    r   <lambda>Wpatch_channels_asgi_handler_impl.<locals>.sentry_patched_asgi_handler.<locals>.<lambda>   s    wtS9r   Tr/   )r3   r4   r5   r   r7   r2   r:   )r9   r;   r<   r=   r>   r-   r?   r@   s   `    r   rA   Epatch_channels_asgi_handler_impl.<locals>.sentry_patched_asgi_handler   s{     $//1AABSTK"$T7999-9$(-44(3(K(K	J $DJJ/>>> : ?s"   4BBAB>B?BB)channelsr!   r-   __version__rM   rP   )r?   r`   rA   r-   r@   s   `  @@r    patch_channels_asgi_handler_implrb      s8    @g%,,	? 3
 	's+r   c                 V   ^ ^ SSK Jm  [        R                  " T 5      UU 4S j5       nU$ )Nr   r,   c                   >#    [         R                  " 5       nUR                  b  UR                  R                  5         [         R                  " 5       nUR
                  b  UR
                  R                  5         [         R                  " [        R                  U R                  R                  TR                  S9   T" U /UQ70 UD6I S h  vN sS S S 5        $  N! , (       d  f       g = f7f)N)opnamer7   )r3   get_current_scopetransactionupdate_active_threadrE   profileupdate_active_thread_id
start_spanr   VIEW_RENDERresolver_match	view_namer7   )r&   rG   rH   current_scopesentry_scoper-   callbacks        r   sentry_wrapped_callback0wrap_async_view.<locals>.sentry_wrapped_callback   s      #446$$0%%::<!557+  88:""~~''11$++

 "';D;F;;
 

 <
 
s0   B;C/>CCC
C/C
C,(C/)r!   r-   	functoolswraps)rr   rs   r-   s   ` @r   wrap_async_viewrw      s)    @__X< <" #"r   c                 "   ^   " U 4S jS5      nU$ )z\
Mixin class factory that generates a middleware mixin for handling requests
in async mode.
c                   F   > \ rS rSr\(       a  SrS rS rS rU 4S jr	Sr
g)7_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin   Nc                 >    Xl         S U l        U R                  5         g r   )get_response_acall_method_async_check)r9   r}   s     r   __init__@_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin.__init__   s     ,!%Dr   c                 P    [        U R                  5      (       a  [        U 5        gg)z
If get_response is a coroutine function, turns us into async mode so
a thread is not consumed during a whole request.
Taken from django.utils.deprecation::MiddlewareMixin._async_check
N)iscoroutinefunctionr}   r   r9   s    r   r   D_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin._async_check   s"     #4#4#455%d+ 6r   c                 ,    [        U R                  5      $ )zl
Function that checks if we are in async mode,
and if we are forwards the handling of requests to __acall__
)r   r}   r   s    r   async_route_checkI_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin.async_route_check   s     't'8'899r   c                 V  >#    U R                   nUcL  [        U R                  S5      (       a  U R                  R                  =U l         nOU R                  =U l         nT" US9nUc  U" U0 UD6I S h  vN $ U   U" U0 UD6I S h  vN sS S S 5        $  N  N! , (       d  f       g = f7f)N	__acall__)
old_method)r~   rN   _innerr   )r9   rG   rH   fmiddleware_span_check_middleware_spans        r   r   A_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin.__acall__   s     ""Ay4;;44-1[[-B-BBD&-1[[8D&4BO&//// /// ! 0 0 !s<   A0B)3B4B):BBB
B)B
B&"B))r~   r}   )__name__
__module____qualname____firstlineno__r	   r   r   r   r   r   __static_attributes__)r   s   r   SentryASGIMixinrz      s$    F	 	,	:	0 	0r   r   r)   )r   r   s   ` r   _asgi_middleware_mixin_factoryr      s    +0 +0Z r   )r   r   returnr   )'__doc__r   ru   inspectdjango.core.handlers.wsgir   r3   sentry_sdk.constsr   sentry_sdk.integrations.asgir   sentry_sdk.scoper   sentry_sdk.utilsr   r   typingr	   r
   r   r   r   django.core.handlers.asgir   django.http.responser   sentry_sdk._typesr   r   r   rN   r   r   r*   rP   rX   rb   rw   r   r)   r   r   <module>r      s       1    = 4
 !44517	Xc3h/	0B 7+,,!55#99!55
(<%;P	?,@#24r   