
    lh)                        d dl Z d dlmZ d dlZd dlmZmZ d dlm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 d d	lmZ d d
lmZmZ d dlmZmZmZmZ d dlmZ erad 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$ d dlm%Z% d dlm&Z& d dl'm(Z(m)Z)  e$d      Z* e$d      Z+ e$d      Z, G d de%      Z- ed      Z.d(dZ/d)dZ0 G d d       Z1	 d*d!Z2d" Z3d# Z4d$ Z5 G d% d&      Z6d' Z7y)+    N)partial)get_host_get_headers)continue_trace)OPshould_send_default_pii)DEFAULT_HTTP_METHODS_TO_CAPTURE_filter_headersnullcontext)track_session)use_isolation_scope)TransactionTransactionSource)
ContextVarcapture_internal_exceptionsevent_from_exceptionreraise)TYPE_CHECKING)Callable)Dict)Iterator)Any)Tuple)Optional)TypeVar)Protocol)ExcInfo)EventEventProcessorWsgiResponseIterWsgiResponseHeadersWsgiExcInfoc                       e Zd ZddZy)StartResponseNc                      y N )selfstatusresponse_headersexc_infos       n/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/wsgi.py__call__zStartResponse.__call__,   s        r'   )__name__
__module____qualname__r.   r(   r/   r-   r%   r%   +   s    	r/   r%   sentry_wsgi_middleware_appliedc                 D    | j                  d      j                  ||      S )Nlatin1)encodedecode)scharseterrorss      r-   wsgi_decoding_dancer;   4   s    88H$$Wf55r/   c                 
   | j                  dd      j                  d      }| j                  dd      j                  d      }| d| }| j                  d      dt        | |      dt	        |      j                  d      S )zPReturn the absolute URL without query string for the given WSGI
    environment.SCRIPT_NAME /	PATH_INFOzwsgi.url_schemez://)getrstriplstripr   r;   )environuse_x_forwarded_forscript_name	path_infopaths        r-   get_request_urlrI   9   s     ++mR077<KK,33C8I]!I;'D 	%&-.D!((- r/   c                   $    e Zd ZdZddefdZd Zy)SentryWsgiMiddlewareapprE   span_originhttp_methods_to_captureFmanualc                 <    || _         || _        || _        || _        y r'   rL   )r)   rM   rE   rN   rO   s        r-   __init__zSentryWsgiMiddleware.__init__P   s#     #6 &'>$r/   c                     t         j                  d      r| j                  ||      S t         j                  d       	 t	        j
                         5 }t        |d      5  t               5  |j                          d|_	        |j                  t        || j                               d d d        |j                  dd      j                         }d }|| j                  v r6t        |t         j"                  dt$        j&                  | j(                  	      }|t	        j*                  |d
|i      n	t-               5  	 | j                  |t/        t0        ||            }d d d        d d d        d d d        t         j                  d       t9              S # 1 sw Y   xY w# t2        $ r t5        t7                 Y `w xY w# 1 sw Y   exY w# 1 sw Y   ixY w# 1 sw Y   mxY w# t         j                  d       w xY w)NFTrequest)session_modewsgiREQUEST_METHODr>   zgeneric WSGI request)opnamesourceoriginwsgi_environ)custom_sampling_context)_wsgi_middleware_appliedrA   rM   set
sentry_sdkisolation_scoper   r   clear_breadcrumbs_nameadd_event_processor_make_wsgi_event_processorrE   upperrO   r   r   HTTP_SERVERr   ROUTErN   start_transactionr   r   _sentry_start_responseBaseExceptionr   _capture_exception_ScopedResponse)r)   rD   start_responsescopemethodtransactionresponses          r-   r.   zSentryWsgiMiddleware.__call__]   s   #''.88G^44 $$T*)	0++- &;"5yA %;46 //1&,116 ')A)A %[[)92>DDFF"&K!=!==&4#!~~!7#4#:#:#'#3#3' '2	 #44'5CW4M
 )];;'+xx ' '$:NK!"(H;+%;&;P %((/uh//Q F  - ;#%7%9:;; ;+%; %;&; &;P %((/s   G& G G+=F(BG;G=!F#G&G.G& F G#F?	<G>F?	?GGGG	GG#G& &G=N)r0   r1   r2   	__slots__r
   rR   r.   r(   r/   r-   rK   rK   H   s    I " ??10r/   rK   c                     t               5  t        |j                  dd      d         }||j                  |       d d d        |	 | ||      S  | |||      S # 1 sw Y   xY w)N    r   )r   intsplitset_http_status)old_start_responserq   r*   r+   r,   
status_ints         r-   rj   rj      su     
%	& 4c1-a01
"''
34
  "&*:;;!&*:HEE4 4s   2AA#c              #   ^   K   ddg}t               r|dgz  }|D ]  }|| v s|| |   f  yw)z
    Returns our explicitly included environment variables we want to
    capture (server name, port and remote addr if pii is enabled).
    SERVER_NAMESERVER_PORTREMOTE_ADDRNr   )rD   keyskeys      r-   _get_environr      sK      =)D  	 $'>ws|##$s   --c                     	 | d   j                  d      d   j                         S # t        t        f$ r Y nw xY w	 | d   S # t        $ r Y nw xY w| j	                  d      S )z
    Infer the user IP address from various headers. This cannot be used in
    security sensitive situations since the value may be forged from a client,
    but it's good enough for the event payload.
    HTTP_X_FORWARDED_FOR,r   HTTP_X_REAL_IPr   )rx   stripKeyError
IndexErrorrA   )rD   s    r-   get_client_ipr      sw    -.44S9!<BBDDj! '((  ;;}%%s   $' 99A 	AAc                  
   t        j                         } | d   }t        |t              xr |j                  dv }|sGt        | t        j                         j                  ddd      \  }}t        j                  ||       | S )z
    Captures the current exception and sends it to Sentry.
    Returns the ExcInfo tuple to it can be reraised afterwards.
    rv   )r   NrV   F)typehandled)client_options	mechanism)hint)
sysr,   
isinstance
SystemExitcoder   r`   
get_clientoptionscapture_event)r,   eshould_skip_captureeventr   s        r-   rl   rl      sz     ||~HA %Q
3K)8K*%002::%%8
t
 	  T2Or/   c                   &    e Zd ZdZdZd Zd Zd Zy)rm   aY  
    Users a separate scope for each response chunk.

    This will make WSGI apps more tolerant against:
    - WSGI servers streaming responses from a different thread/from
      different threads than the one that called start_response
    - close() not being called
    - WSGI servers streaming responses interleaved from the same thread
    )	_response_scopec                      || _         || _        y r'   )r   r   )r)   ro   rr   s      r-   rR   z_ScopedResponse.__init__   s    !r/   c              #     K   t        | j                        }	 t        | j                        5  	 t	        |      }d d d         /# t
        $ r Y d d d        y t        $ r t        t                 Y :w xY w# 1 sw Y   ?xY wwr'   )	iterr   r   r   nextStopIterationrk   r   rl   )r)   iteratorchunks      r-   __iter__z_ScopedResponse.__iter__   s     '$T[[1 33 NE3 K  % 	3 3
 % 3/1233 3sJ   ,BA9AB	A6A9	BA63A95A66A99B>Bc                     t        | j                        5  	 | j                  j                          d d d        y # t        $ r Y t
        $ r t        t                 Y .w xY w# 1 sw Y   y xY wr'   )r   r   r   closeAttributeErrorrk   r   rl   )r)   s    r-   r   z_ScopedResponse.close  se     - 	//$$&	/ 	/ "   /+-./	/ 	/s2   A$;	A!A$A!A$ A!!A$$A-N)r0   r1   r2   __doc__rs   rR   r   r   r(   r/   r-   rm   rm      s     (I"
/r/   rm   c                     t        |       t        | |      | j                  d      | j                  d      t        t	        |             t        t        t        |                   fd}|S )NQUERY_STRINGrW   c                     t               5  | j                  di       }t               r&| j                  di       }r|j                  d       	|d<   |d<   |d<   |d<   |d<   d d d        | S # 1 sw Y   | S xY w)	NrT   user
ip_addressurlquery_stringrp   envheaders)r   
setdefaultr	   )
r   r   request_info	user_info	client_ipr   r   rp   r   request_urls
       r-   event_processorz3_make_wsgi_event_processor.<locals>.event_processor#  s    (* 	. ++Ir:L&(!,,VR8	((yA"-L+7L(%+L""%L&-L#	. 	. s   AA22A<)r   rI   rA   dictr   r   r   )	rD   rE   r   r   r   r   rp   r   r   s	      @@@@@@r-   re   re     sn     g&I!'+>?K;;~.L[[)*F
|G$
%Cd<#89:G & r/   )zutf-8replace)Fr'   )8r   	functoolsr   r`   sentry_sdk._werkzeugr   r   sentry_sdk.apir   sentry_sdk.constsr   sentry_sdk.scoper	   $sentry_sdk.integrations._wsgi_commonr
   r   r   sentry_sdk.sessionsr   r   sentry_sdk.tracingr   r   sentry_sdk.utilsr   r   r   r   typingr   r   r   r   r   r   r   r   r   r   sentry_sdk._typesr   r    r!   r"   r#   r%   r^   r;   rI   rK   rj   r   r   rl   rm   re   r(   r/   r-   <module>r      s    
   7 )   4 
 . 0 =  !(712!"78-(K  &&FG 6
F0 F0\ F,$"&(,)/ )/X(r/   