
    lh                      ^   d Z ddlZddlZddl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 ddlmZmZ ddlmZ er/dd	lmZmZmZmZ dd
lmZ ddlmZ ddlmZmZ  ededef         Z eed      rej>                  Zej@                  Z nej>                  ZddZ d Z!d Z"d Z#d Z$d Z%d Z&y)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    t         j                  j                  | _        | S N)asyncio
coroutines_is_coroutine)funcs    u/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/django/asgi.pyr   r   1   s    $//==    c                       fd}|S )Nc                    ddl m}m} | S t              t        k(  r| S t               5   |      j                  |        d d d        t               rt               5   ||        d d d        | S | S # 1 sw Y   3xY w# 1 sw Y   | S xY w)Nr   )DjangoRequestExtractor_set_user_info)sentry_sdk.integrations.djangor   r    typer   r   extract_into_eventr   )eventhintr   r    requests       r   asgi_request_event_processorzH_make_asgi_request_event_processor.<locals>.asgi_request_event_processor8   s    
	

 ?L=K'L(* 	F"7+>>uE	F #$,. /w./ u	F 	F/ s   A6 
B6A?B )r&   r'   s   ` r   "_make_asgi_request_event_processorr)   6   s    2 ('r   c                      ddl m  j                   fd}| _        t         d      }|r( j                  t              fd       }| _        y y )Nr   DjangoIntegrationc                 "  K   t        j                         j                        }| | |||       d {   S t        j	                  |       dj
                  |j                        j                  } ||||       d {   S 7 S7 w)NTunsafe_context_dataspan_originhttp_methods_to_capture)
sentry_sdk
get_clientget_integrationr   __get__originr1   
_run_asgi3)	selfscopereceivesendintegration
middlewarer,   clsold_apps	         r   sentry_patched_asgi_handlerzCpatch_django_asgi_handler_impl.<locals>.sentry_patched_asgi_handler[   s      ++-==>OP ugt<<<)OOD#& $)00$/$G$G	

 * 	  w555 = 6s"   4BBABBBBcreate_requestc                      | g|i |\  }}t        j                         }|j                  t        |             ||fS r   )r2   get_isolation_scopeadd_event_processorr)   )r8   argskwargsr&   error_responser9   old_create_requests         r   sentry_patched_create_requestzEpatch_django_asgi_handler_impl.<locals>.sentry_patched_create_requestp   sK     '9&O&O&O#G^224E%%&H&QRN**r   )r!   r,   __call__hasattrrA   r   )r>   r@   modern_django_asgi_supportrI   r,   r?   rH   s   `   @@@r   patch_django_asgi_handler_implrM   T   sh     AllG6 /CL!(.>!?! //	#$57I	J	+ 
K	+ ; "r   c                 :    | j                   fd}|| _         y )Nc                 B   K    |        | |       d {   S 7 wr   r(   )r8   r&   _before_get_responseold_get_response_asyncs     r   !sentry_patched_get_response_asynczCpatch_get_response_async.<locals>.sentry_patched_get_response_async   s"     W%+D'::::s   )get_response_async)r>   rP   rR   rQ   s    ` @r   patch_get_response_asyncrT   |   s     33;
 ?Cr   c                      dd l }ddlm |j                  dk  r j                   fd}| _        y t                y )Nr   r+   z3.0.0c                    K   t        j                         j                        }|  ||       d {   S t         fddj                  |j
                        }  | j                        ||       d {   S 7 M7 w)Nc                 (    j                        S r   )r5   )_scoper>   r?   r8   s    r   <lambda>zWpatch_channels_asgi_handler_impl.<locals>.sentry_patched_asgi_handler.<locals>.<lambda>   s    wtS9 r   Tr.   )r2   r3   r4   r   r6   r1   r9   )r8   r:   r;   r<   r=   r,   r>   r?   s   `    r   r@   zEpatch_channels_asgi_handler_impl.<locals>.sentry_patched_asgi_handler   s     $//1AABSTK"$T7D999-9$(-44(3(K(K	J 0DJJ/>>> : ?s"   3B	BAB	 BB	B	)channelsr!   r,   __version__rJ   rM   )r>   rZ   r@   r,   r?   s   `  @@r    patch_channels_asgi_handler_implr\      s8    @g%,,	? 3
 	's+r   c                 R     ddl m t        j                          fd       }|S )Nr   r+   c                   K   t        j                         }|j                  |j                  j                          t        j                         }|j
                  |j
                  j                          t        j                  t        j                  | j                  j                  j                        5   | g|i | d {   cd d d        S 7 # 1 sw Y   y xY ww)N)opnamer6   )r2   get_current_scopetransactionupdate_active_threadrC   profileupdate_active_thread_id
start_spanr   VIEW_RENDERresolver_match	view_namer6   )r&   rE   rF   current_scopesentry_scoper,   callbacks        r   sentry_wrapped_callbackz0wrap_async_view.<locals>.sentry_wrapped_callback   s      #446$$0%%::<!557+  88:""~~''11$++
 	<
 "';D;F;;	< 	<
 <	< 	<s0   B9C(<CCC
C(CC%!C()r!   r,   	functoolswraps)rl   rm   r,   s   ` @r   wrap_async_viewrp      s)    @__X< <" #"r   c                        G  fdd      }|S )zh
    Mixin class factory that generates a middleware mixin for handling requests
    in async mode.
    c                   2    e Zd ZerdZd Zd Zd Z fdZy)7_asgi_middleware_mixin_factory.<locals>.SentryASGIMixinNc                 @    || _         d | _        | j                          y r   )get_response_acall_method_async_check)r8   ru   s     r   __init__z@_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin.__init__   s     ,D!%Dr   c                 F    t        | j                        rt        |        yy)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)iscoroutinefunctionru   r   r8   s    r   rw   zD_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin._async_check   s     #4#4#45%d+ 6r   c                 ,    t        | j                        S )z
            Function that checks if we are in async mode,
            and if we are forwards the handling of requests to __acall__
            )rz   ru   r{   s    r   async_route_checkzI_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin.async_route_check   s     't'8'899r   c                 D  K   | j                   }|Gt        | j                  d      r| j                  j                  x| _         }n| j                  x| _         } |      }| ||i | d {   S |5   ||i | d {   cd d d        S 7  7 # 1 sw Y   y xY ww)N	__acall__)
old_method)rv   rK   _innerr   )r8   rE   rF   fmiddleware_span_check_middleware_spans        r   r   zA_asgi_middleware_mixin_factory.<locals>.SentryASGIMixin.__acall__   s     ""Ay4;;4-1[[-B-BBD&-1[[8D&4BO&////  0///0 0 0 00 0s<   A,B /B0B 6BBBB BBB )	__name__
__module____qualname__r	   r   rx   rw   r}   r   )r   s   r   SentryASGIMixinrs      s    F	 	,	:	0r   r   r(   )r   r   s   ` r   _asgi_middleware_mixin_factoryr      s    +0 +0Z r   )r   r   returnr   )'__doc__r   rn   inspectdjango.core.handlers.wsgir   r2   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   rK   rz   r   r)   rM   rT   r\   rp   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   