
    fi9*                        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rmd 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* Z7dS ).    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dS )StartResponseNc                     d S N )selfstatusresponse_headersexc_infos       l/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/sentry_sdk/integrations/wsgi.py__call__zStartResponse.__call__,   s    D    r'   )__name__
__module____qualname__r.   r(   r/   r-   r%   r%   +   s(        	 	 	 	 	 	r/   r%   sentry_wsgi_middleware_appliedutf-8replacec                 T    |                      d                              ||          S )Nlatin1)encodedecode)scharseterrorss      r-   wsgi_decoding_dancer=   4   s$    88H$$Wf555r/   Fc                 J   |                      dd                              d          }|                      dd                              d          }| d| }|                      d          dt          | |          dt	          |                              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_urlrK   9   s     ++mR0077<<KK,,33C88I''I''D 	%&&&&-....D!!((--- r/   c                   &    e Zd ZdZddefdZd ZdS )SentryWsgiMiddlewareapprG   span_originhttp_methods_to_captureFmanualc                 >    || _         || _        || _        || _        d S r'   rN   )r)   rO   rG   rP   rQ   s        r-   __init__zSentryWsgiMiddleware.__init__P   s)     #6 &'>$$$r/   c                    t                               d          r|                     ||          S t                               d           	 t	          j                    5 }t          |d          5  t                      5  |                                 d|_	        |
                    t          || j                             d d d            n# 1 swxY w Y   |                    dd                                          }d }|| j        v r-t          |t           j        dt$          j        | j        	          }|t	          j        |d
|i          nt-                      }|5  	 |                     |t/          t0          ||                    }n%# t2          $ r t5          t7                        Y nw xY wd d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t                               d           n# t                               d           w xY wt9          ||          S )NFTrequest)session_modewsgiREQUEST_METHODr@   zgeneric WSGI request)opnamesourceoriginwsgi_environ)custom_sampling_context)_wsgi_middleware_appliedrC   rO   set
sentry_sdkisolation_scoper   r   clear_breadcrumbs_nameadd_event_processor_make_wsgi_event_processorrG   upperrQ   r   r   HTTP_SERVERr   ROUTErP   start_transactionr   r   _sentry_start_responseBaseExceptionr   _capture_exception_ScopedResponse)r)   rF   start_responsescopemethodtransactiontransaction_contextresponses           r-   r.   zSentryWsgiMiddleware.__call__]   sZ   #''.. 	588G^444 $$T****	0+-- ';"5yAAA &; &;466  //111&,116 ')A                  %[[)92>>DDFFF"&K!===&4#!~!7#4#:#'#3' ' ' '2	 #4'5CW4M   
 )]] ( - 	; 	;;'+xx ' '$:NK!" !"( (HH  - ; ; ;#%7%9%9::::;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;;&; &; &; &; &; &; &; &; &; &; &; &; &; &; &;'; '; '; '; '; '; '; '; '; '; '; '; '; '; ';R %((////$((////uh///s   H G11G ACGCGCBG%G'*FGF4	1G3F4	4G7GGG
GGG1G	G1!G	"G1%H 1G55H 8G59H H3N)r0   r1   r2   	__slots__r
   rT   r.   r(   r/   r-   rM   rM   H   sI        I " ?? ? ? ?20 20 20 20 20r/   rM   c                    t                      5  t          |                    dd          d                   }||                    |           d d d            n# 1 swxY w Y   | | ||          S  | |||          S )N    r   )r   intsplitset_http_status)old_start_responsers   r*   r+   r,   
status_ints         r-   rl   rl      s     
%	&	& 4 4c1--a011
"''
3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  "!&*:;;;!!&*:HEEEs   AAA #A c              #   d   K   ddg}t                      r|dgz  }|D ]}|| v r|| |         fV  dS )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   )rF   keyskeys      r-   _get_environr      sf       =)D     	 $ $'>>ws|####$ $r/   c                     	 | d                              d          d                                         S # t          t          f$ r Y nw xY w	 | d         S # t          $ r Y nw xY w|                     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   )r{   stripKeyError
IndexErrorrC   )rF   s    r-   get_client_ipr      s    -.44S99!<BBDDDj!   '((    ;;}%%%s!   25 A	A	A 
A"!A"c                     t          j                    } | d         }t          |t                    o|j        dv }|sDt          | 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.
    ry   )r   NrX   F)typehandled)client_options	mechanism)hint)
sysr,   
isinstance
SystemExitcoder   rb   
get_clientoptionscapture_event)r,   eshould_skip_captureeventr   s        r-   rn   rn      s     |~~HA %Q
33K)8K 3*%022:%%88
 
 
t
 	 T2222Or/   c                   (    e Zd ZdZdZd Zd Zd ZdS )ro   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                 "    || _         || _        d S r'   )r   r   )r)   rq   ru   s      r-   rT   z_ScopedResponse.__init__   s    !r/   c              #   ,  K   t          | j                  }	 t          | j                  5  	 t	          |          }n<# t
          $ r Y d d d            d S t          $ r t          t                        Y nw xY wd d d            n# 1 swxY w Y   |V  ~r'   )	iterr   r   r   nextStopIterationrm   r   rn   )r)   iteratorchunks      r-   __iter__z_ScopedResponse.__iter__   s     ''		$T[11 3 33 NNEE$   	3 3 3 3 3 3 3 3
 % 3 3 3/11222233 3 3 3 3 3 3 3 3 3 3 3 3 3 3 KKK		s=   B>B
A7BA74B6A77BB
B
c                     t          | j                  5  	 | j                                         n0# t          $ r Y n$t
          $ r t          t                        Y nw xY wd d d            d S # 1 swxY w Y   d S r'   )r   r   r   closeAttributeErrorrm   r   rn   )r)   s    r-   r   z_ScopedResponse.close  s     -- 	/ 	//$$&&&&!     / / /+--..../	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s;   A.1A.
AA.AA.AA..A25A2N)r0   r1   r2   __doc__rv   rT   r   r   r(   r/   r-   ro   ro      sR          (I" " "
  / / / / /r/   ro   c                 B   t          |           t          | |          |                     d          |                     d          t          t	          |                     t          t          t          |                               fd}|S )NQUERY_STRINGrY   c                 *   t                      5  |                     di           }t                      r.|                     di           }r|                    d           	|d<   |d<   |d<   |d<   |d<   d d d            n# 1 swxY w Y   | S )	NrV   user
ip_addressurlquery_stringrr   envheaders)r   
setdefaultr	   )
r   r   request_info	user_info	client_ipr   r   rr   r   request_urls
       r-   event_processorz3_make_wsgi_event_processor.<locals>.event_processor$  s    (** 	. 	. ++Ir::L&(( B!,,VR88	 B((yAAA"-L+7L(%+L""%L&-L#	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. s   A,BBB)r   rK   rC   dictr   r   r   )	rF   rG   r   r   r   r   rr   r   r   s	      @@@@@@r-   rg   rg     s     g&&I!'+>??K;;~..L[[)**F
|G$$
%
%Cd<#8#899::G         & r/   )r4   r5   )Fr'   )8r   	functoolsr   rb   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=   rK   rM   rl   r   r   rn   ro   rg   r(   r/   r-   <module>r      sO   



           7 7 7 7 7 7 7 7 ) ) ) ) ) )             4 4 4 4 4 4         
 . - - - - - 0 0 0 0 0 0 = = = = = = = =            !           ((((((77777777w122!'"788'-((K        &:&FGG 6 6 6 6
   G0 G0 G0 G0 G0 G0 G0 G0^ F F F F,$ $ $"& & &(  ,)/ )/ )/ )/ )/ )/ )/ )/X( ( ( ( (r/   