Ë
    õ�Djœ%  ã                   ó  — 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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j8                  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„ Z/d„ Z0d„ Z1y# e$ r	  ed«      ‚w xY w# e$ r! d dl!ZejD                  ZejF                  ZdZ Y Œˆw xY w# 1 sw Y   Œ{xY w)é    N)Ú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    úbC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\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.   r/   r0   Ú__doc__rC   r!   r   r   r2   r2   e   s   „ ÙCóSr   r2   ©Úuri_templateÚpathc                   ó6   — e Zd ZdZde› �ZdZdd„Zed„ «       Zy)r8   r4   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   rN   s     r   Ú__init__zFalconIntegration.__init__|   s.   € àÔ$<Ñ<Ýâ$Ö&>ð@óð ð "3ˆÕr   c                  ó¾   — t        t        «      } | €t        dj                  t        «      «      ‚| dk  rt        d«      ‚t	        «        t        «        t        «        y )NzUnparsable Falcon version: {})é   é   zFalcon 1.4 or newer required.)r   ÚFALCON_VERSIONr   ÚformatÚ_patch_wsgi_appÚ_patch_handle_exceptionÚ_patch_prepare_middleware)Úversions    r   Ú
setup_oncezFalconIntegration.setup_once…   sP   € ô  ¤Ó/ˆàˆ?ÜÐ>×EÑEÄnÓUÓVÐVà�VÒÜÐ>Ó?Ð?äÔÜÔ!Ü!Õ#r   N)rF   )	r.   r/   r0   Ú
identifierÚoriginrN   rO   ÚstaticmethodrY   r!   r   r   r8   r8   v   s2   „ Ø€JØ˜*˜Ð&€FàÐó3ð ñ$ó ñ$r   r8   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   ø€ Ñ%6°t¸TÀ:Ó%N€ r   )Úspan_origin)r5   r6   r7   r8   r   r[   )r   r   Ústart_responserA   Úsentry_wrappedrb   s   `    €r   Úsentry_patched_wsgi_appz0_patch_wsgi_app.<locals>.sentry_patched_wsgi_appš   sW   ù€ ä ×+Ñ+Ó-×=Ñ=Ô>OÓPˆØÐÙ$ T¨3°Ó?Ð?ä-ÜNÜ)×0Ñ0ô
ˆñ
 ˜c >Ó2Ð2r   )Úfalcon_app_classÚ__call__)rg   rb   s    @r   rU   rU   –   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   è ø€ ÒW 8´zÀ(ÌIÕ7V”hÑWùs   ‚˜c              3   óV   K  — | ]!  }t        |t        j                  «      sŒ|–— Œ# y ­wr   )rm   r4   ÚResponsero   s     r   rr   zS_patch_handle_exception.<locals>.sentry_patched_handle_exception.<locals>.<genexpr>·   s"   è ø€ ò Ø%´¸HÄfÇoÁoÕ1V”ñùs   ‚)¢)r4   F)ÚtypeÚhandled)Úclient_optionsÚ	mechanism)Úhint)r   ÚnextÚ_exception_leads_to_http_5xxr
   r5   r6   ÚoptionsÚcapture_event)r   r?   ÚexÚresponseÚwas_handledÚeventry   Úoriginal_handle_exceptions          €r   Úsentry_patched_handle_exceptionz@_patch_handle_exception.<locals>.sentry_patched_handle_exception®   sÁ   ø€ ð ÐˆˆXÜ(Ó*ñ 	ÜÑW¨tÔWÓWˆBÜñ Ø)-ôó ˆH÷	ñ 0°Ð<°tÒ<ˆàˆ:˜Ð)ð Ðä'¨¨HÔ5Ü.ØÜ)×4Ñ4Ó6×>Ñ>Ø#+¸Ñ>ô‰KˆE�4ô
 ×$Ñ$ U°Õ6àÐ÷-	ð 	ús   �%B!Â!B*)rh   Ú_handle_exceptionr	   r8   )rƒ   r‚   s    @r   rV   rV   ª   s7   ø€ ä 0× BÑ BÐäÔ 1Ð3LÓ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   )r5   r6   r7   r8   r2   )Ú
middlewareÚindependent_middlewareÚasgirA   Úoriginal_prepare_middlewares       €r   Ú!sentry_patched_prepare_middlewarezD_patch_prepare_middleware.<locals>.sentry_patched_prepare_middlewareÔ   s^   ø€ ñ á.¨zÐ;QÐSWÓXÐXä ×+Ñ+Ó-×=Ñ=Ô>OÓPˆØÐ"Ü0Ó2Ð3°zÒ7GÀRÑHˆJñ +¨:Ð7MÓNÐNr   )NFF)Úfalcon_helpersÚprepare_middleware)r‹   rŠ   s    @r   rW   rW   Ð   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 )NrI   Ú5)	rm   r4   Ú	HTTPErrorÚstatusÚ
startswithÚhttp_statusÚ
HTTPStatusÚFALCON3Ú_has_http_5xx_status)r~   r   Úis_server_errorÚis_unhandled_errors       r   r{   r{   ç   s„   € ä  ¤V×%5Ñ%5Ó6ò ¸B¿I¹IºOÈ×;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 )NrE   ÚtransactionÚsourceÚtransaction_info)rF   rG   r   )r�   rN   r   Úname_for_styles       r   Ú _set_transaction_name_and_sourcerŸ   ÿ   sD   € ð  ×,Ñ,Ø—‘ñ€Nð *Ð*;Ñ<€Eˆ-ÑØ!)Ô+;Ð<MÑ+NÐ O€EÐ
Ò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Ÿ   rN   r   r   Úextract_into_event)r�   ry   rA   r=   s     €€r   Úevent_processorz6_make_request_event_processor.<locals>.event_processor  sO   ø€ ä(¨°×0MÑ0MÈsÔSä(Ó*ñ 	BÜ" 3Ó'×:Ñ:¸5ÔA÷	Bð ˆ÷	Bð ˆús   £AÁAr!   )r=   rA   r£   s   `` r   r<   r<   	  s   ù€ õð Ðr   )2r5   Úsentry_sdk.integrationsr   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   r4   r   rS   ÚImportErrorÚfalcon.app_helpersÚapp_helpersrŒ   ÚApprh   r•   Úfalcon.api_helpersÚapi_helpersÚAPIr+   Úfalcon.requestr   r   r2   rL   r8   rU   rV   rW   r{   r–   rŸ   r<   r!   r   r   ú<module>r³      s(  ðÛ ß =Ý AÝ =Ý /÷ó õ !áÝÝÝç7ð
/Ûå4ðÛà×'Ñ'€NØ—z‘zÐØ€Gð €Ù
Ù	$Ó	&ñ ;Ý:÷;ô.Ð-ô .÷bSñ Sð 4Ð ô$˜ô $ò@8ò(#IòLJò.ò&+ò
PóøðY ò /Ù
Ð-Ó
.Ð.ð/ûð ò Ûà×'Ñ'€NØ—z‘zÐØ‚Gðú÷;ð ;ús*   Á
C	 ÁC ÂDÃ	CÃ#D Ã?D ÄD