
    lh%                     "   d dl 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
 d dlmZmZmZmZ d dlmZ er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Zd dlmZ 	 d dlZej:                  Zej>                  Z dZ!dZ%e!r e       5  d dl&m'Z% ddd        G d de      Z( G d d      Z)dZ* G d de      Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2y# e$ r	  ed      w xY w# e$ r! d dl"ZejF                  ZejH                  Z dZ!Y w xY w# 1 sw Y   {xY w)    N)_check_minimum_versionIntegrationDidNotEnable)RequestExtractor)SentryWsgiMiddleware)SOURCE_FOR_STYLE)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionparse_version)TYPE_CHECKING)Any)Dict)Optional)EventEventProcessor)__version__zFalcon not installedTF)_UNSETc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)FalconRequestExtractorc                 .    | j                   j                  S N)requestenvselfs    p/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/falcon.pyr   zFalconRequestExtractor.env5   s    ||    c                 .    | j                   j                  S r   )r   cookiesr   s    r   r    zFalconRequestExtractor.cookies9   s    ||###r   c                      y r    r   s    r   formzFalconRequestExtractor.form=       r   c                      y r   r"   r   s    r   fileszFalconRequestExtractor.filesA   r$   r   c                 0    | j                         }|dkD  ryy )Nr   z[REQUEST_CONTAINING_RAW_DATA])content_length)r   r(   s     r   raw_datazFalconRequestExtractor.raw_dataE   s      ,,.A2r   c                     d }t               5  | j                  j                  }d d d        |t        ur|S y # 1 sw Y   xY wr   )r	   r   _media_FALCON_UNSET)r   cached_medias     r   jsonzFalconRequestExtractor.jsonR   sH     (* 	/  <<..L	/ },	/ 	/s	   7A N)	__name__
__module____qualname__r   r    r#   r&   r)   r.   r"   r   r   r   r   4   s      $r   r   c                       e Zd ZdZd Zy)SentryFalconMiddlewarez9Captures exceptions in Falcon requests and send to Sentryc                     t        j                         j                  t              }|y t        j                         }d|_        |j                  t        ||             y )Nfalcon)
sentry_sdk
get_clientget_integrationFalconIntegrationget_isolation_scope_nameadd_event_processor_make_request_event_processor)r   reqrespargskwargsintegrationscopes          r   process_requestz&SentryFalconMiddleware.process_requesth   sP     ++-==>OP..0!!"?["QRr   N)r/   r0   r1   __doc__rD   r"   r   r   r3   r3   e   s    CSr   r3   uri_templatepathc                   6    e Zd ZdZde ZdZddZed        Zy)r9   r5   z
auto.http. c                 N    |t         vrt        d|dt         d      || _        y )Nz%Invalid value for transaction_style: z (must be in ))TRANSACTION_STYLE_VALUES
ValueErrortransaction_style)r   rO   s     r   __init__zFalconIntegration.__init__|   s.    $<<$&>@  "3r   c                  ~    t        t              } t        t        |        t	                t                t                y r   )r   FALCON_VERSIONr   r9   _patch_wsgi_app_patch_handle_exception_patch_prepare_middleware)versions    r   
setup_oncezFalconIntegration.setup_once   s+      /0':!!#r   N)rG   )	r/   r0   r1   
identifieroriginrO   rP   staticmethodrW   r"   r   r   r9   r9   v   s2    J*&F3 $ $r   r9   c                  F    t         j                  fd} | t         _        y )Nc                      t        j                         j                  t              }|
  ||      S t	         fdt        j
                        } |||      S )Nc                      | |      S r   r"   )envi
start_resporiginal_wsgi_appr   s     r   <lambda>zB_patch_wsgi_app.<locals>.sentry_patched_wsgi_app.<locals>.<lambda>   s    %6tT:%N r   )span_origin)r6   r7   r8   r9   r   rY   )r   r   start_responserB   sentry_wrappedr`   s   `    r   sentry_patched_wsgi_appz0_patch_wsgi_app.<locals>.sentry_patched_wsgi_app   sW     ++-==>OP$T3??-N)00

 c>22r   )falcon_app_class__call__)re   r`   s    @r   rS   rS      s    (113 !8r   c                  l    t         j                  t        t              fd       } | t         _        y )Nc                 Z   d x}}t               5  t        d |D              }t        d |D              }d d d         | g| }|||S t        ||      rGt        |t	        j
                         j                  ddd      \  }}t	        j                  ||       |S # 1 sw Y   mxY w)Nc              3   B   K   | ]  }t        |t              s|  y wr   )
isinstance	Exception.0arguments     r   	<genexpr>zS_patch_handle_exception.<locals>.sentry_patched_handle_exception.<locals>.<genexpr>   s     W8z(I7VhWs   c              3   V   K   | ]!  }t        |t        j                        s| # y wr   )rk   r5   Responserm   s     r   rp   zS_patch_handle_exception.<locals>.sentry_patched_handle_exception.<locals>.<genexpr>   s"      %Hfoo1Vs   ))r5   F)typehandled)client_options	mechanism)hint)r	   next_exception_leads_to_http_5xxr   r6   r7   optionscapture_event)r   r@   exresponsewas_handledeventrw   original_handle_exceptions          r   sentry_patched_handle_exceptionz@_patch_handle_exception.<locals>.sentry_patched_handle_exception   s     X(* 	WtWWB )- H	 0<t<:) 'H5.)446>>#+>KE4
 $$U6-	 	s   %B!!B*)rf   _handle_exceptionr
   r9   )r   r   s    @r   rT   rT      s7     0 B B 13LM N< *I&r   c                  J    t         j                  	 dfd	} | t         _        y )Nc                     |r
 | ||      S t        j                         j                  t              }|t	               g| xs g z   }  | |      S r   )r6   r7   r8   r9   r3   )
middlewareindependent_middlewareasgirB   original_prepare_middlewares       r   !sentry_patched_prepare_middlewarezD_patch_prepare_middleware.<locals>.sentry_patched_prepare_middleware   s^     .z;QSWXX ++-==>OP"023z7GRHJ +:7MNNr   )NFF)falcon_helpersprepare_middleware)r   r   s    @r   rU   rU      s&    "0"C"C =BO  )JN%r   c                    t        | t        j                        xr | j                  xs dj	                  d      }t        | t        j                  t        j
                  j                  f       }|xs |xr t         xs t        |      S )NrJ   5)	rk   r5   	HTTPErrorstatus
startswithhttp_status
HTTPStatusFALCON3_has_http_5xx_status)r|   r}   is_server_erroris_unhandled_errors       r   ry   ry      s     V%5%56 BIIO;W;W<O (
Vv11<<=  11 5+H5r   c                 8    | j                   j                  d      S )Nr   )r   r   )r}   s    r   r   r      s    ??%%c**r   c                 b    |j                   |j                  d}||   | d<   dt        |   i| d<   y )NrF   transactionsourcetransaction_info)rG   rH   r   )r   rO   r   name_for_styles       r    _set_transaction_name_and_sourcer      sD      ,,N **;<E-!)+;<M+N OE
r   c                       fd}|S )Nc                     t        | j                         t               5  t              j	                  |        d d d        | S # 1 sw Y   | S xY wr   )r   rO   r	   r   extract_into_event)r   rw   rB   r>   s     r   event_processorz6_make_request_event_processor.<locals>.event_processor  sO    (0M0MsS(* 	B"3'::5A	B 	B s   AAr"   )r>   rB   r   s   `` r   r=   r=     s     r   )3r6   sentry_sdk.integrationsr   r   r   $sentry_sdk.integrations._wsgi_commonr   sentry_sdk.integrations.wsgir   sentry_sdk.tracingr   sentry_sdk.utilsr	   r
   r   r   typingr   r   r   r   sentry_sdk._typesr   r   r5   r   rR   ImportErrorfalcon.app_helpersapp_helpersr   Apprf   r   falcon.api_helpersapi_helpersAPIr,   falcon.requestr   r   r3   rM   r9   rS   rT   rU   ry   r   r   r=   r"   r   r   <module>r      s*    U U A = /  !7
/4''NzzG 
	$	& ;:;.- .bS S 4 $ $68(#ILJ.&+
PO  /
-
../  ''NzzG; ;s*   
C C DC#DDD