
    Dj                     f   d dl Z d dlZd dlmZ d dlmZmZmZmZ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 er6d 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mZ d dlm Z m!Z! 	 d dlm"Z"m#Z#m$Z$m%Z&m'Z( dZ* G d de      Z+ G d de      Z,d Z-d Z.d Z/y# e)$ r	  ed      w xY w)    N)SOURCE_FOR_STYLE)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionparse_versiontransaction_from_function)IntegrationDidNotEnable$_DEFAULT_FAILED_REQUEST_STATUS_CODES)SentryWsgiMiddleware)RequestExtractor)TYPE_CHECKING)Set)_ScopedResponse)Any)Dict)Callable)Optional)
FileUpload	FormsDictLocalRequest)EventProcessorEvent)BottleHTTPResponseRouterequest__version__zBottle not installed)endpointurlc                   >    e Zd ZdZde ZdZ	 deddZed        Z	y)	BottleIntegrationbottlez
auto.http. )failed_request_status_codesc                \    |t         vrt        d|dt         d      || _        || _        y )Nz%Invalid value for transaction_style: z (must be in ))TRANSACTION_STYLE_VALUES
ValueErrortransaction_styler%   )selfr*   r%   s      bC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\sentry_sdk/integrations/bottle.py__init__zBottleIntegration.__init__7   s8     $<<$&>@  "3+F(    c                     t        t              } | t        dj                  t                    | dk  rt        d      t        j
                  t        t              fd       }|t        _        t        j                  t        j                        fd       }|t        _        t        j                  t        j                        fd       }|t        _        y )NzUnparsable Bottle version: {})r      zBottle 0.12 or newer required.c                 V     t         fdt        j                        } |||      S )Nc                       g| i |S N )akwold_appr+   s     r,   <lambda>zOBottleIntegration.setup_once.<locals>.sentry_patched_wsgi_app.<locals>.<lambda>X   s    !8!8R!8 r.   )span_origin)r   r"   origin)r+   environstart_response
middlewarer7   s   `   r,   sentry_patched_wsgi_appz=BottleIntegration.setup_once.<locals>.sentry_patched_wsgi_appT   s*     .8-44J
 g~66r.   c                     t        j                         j                  t              }|	 | |      S t        j                         }d|_        |j                  t        | t        |              | |      }|S )Nr#   )	
sentry_sdk
get_clientget_integrationr"   get_isolation_scope_nameadd_event_processor_make_request_event_processorbottle_request)r+   r;   integrationscoperes
old_handles        r,   _patched_handlez5BottleIntegration.setup_once.<locals>._patched_handleb   st     %//1AABSTK"!$00224E"EK%%-dNKP T7+CJr.   c                      | g|i |t        j                         j                  t              S fd}|S )Nc                      	  | i |}t        |t              r%|j                  j
                  v rt        |d       |S # t         $ r}t        |d       |d }~ww xY w)NF)handledT)	Exception_capture_exception
isinstancer   status_coder%   )argskwargsrJ   	exceptionrH   prepared_callbacks       r,   wrapped_callbackzUBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callback   se    $+T<V<C sL1;+R+RR&sD9
 ! $&y%@#O$s   A 	AAA)r@   rA   rB   r"   )r+   rT   rU   rX   rH   rW   old_make_callbacks       @@r,   patched_make_callbackz;BottleIntegration.setup_once.<locals>.patched_make_callbackv   sM     !2$ H H H$//1AABSTK"((  $#r.   )r   BOTTLE_VERSIONr
   formatr   __call__r   r"   _handle	functoolswrapsr   _make_callback)versionr>   rL   rZ   r7   rK   rY   s       @@@r,   
setup_oncezBottleIntegration.setup_onceG   s      /?>EEnUVVW?@@//	#$5w	?	7 
@	7 2^^
		$	 
%	 )!00	*	+	$ 
,	$4  5r.   N)r   )
__name__
__module____qualname__
identifierr:   r*   r   r-   staticmethodrc   r4   r.   r,   r"   r"   1   sF    J*&F %G %I	G  I5 I5r.   r"   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)BottleRequestExtractorc                 .    | j                   j                  S r3   )r   r;   r+   s    r,   envzBottleRequestExtractor.env       ||###r.   c                 .    | j                   j                  S r3   )r   cookiesrl   s    r,   rp   zBottleRequestExtractor.cookies   rn   r.   c                 J    | j                   j                  j                         S r3   )r   bodyreadrl   s    r,   raw_datazBottleRequestExtractor.raw_data   s    ||  %%''r.   c                 l    | j                         ry | j                  j                  j                         S r3   )is_jsonr   formsdecoderl   s    r,   formzBottleRequestExtractor.form   s'    <<>||!!((**r.   c                 P    | j                         ry | j                  j                  S r3   )rv   r   filesrl   s    r,   r{   zBottleRequestExtractor.files   s    <<>||!!!r.   c                     |j                   S r3   )content_length)r+   files     r,   size_of_filez#BottleRequestExtractor.size_of_file   s    """r.   N)	rd   re   rf   rm   rp   rt   ry   r{   r   r4   r.   r,   rj   rj      s     $$(+"#r.   rj   c                     d}|dk(  r|j                   j                  xs d}n@|dk(  r;|j                   j                  xs# t        |j                   j                        xs d}|| d<   dt
        |   i| d<   y )Nr$   r    r   transactionsourcetransaction_info)routerulenamer   callbackr   )eventr*   r   r   s       r,    _set_transaction_name_and_sourcer      s    DE!}}!!'R	j	(MM ()?)?@ 	  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r3   )r   r*   r   rj   extract_into_event)r   hintrH   r   s     r,   event_processorz6_make_request_event_processor.<locals>.event_processor   sO    (0M0MwW(* 	F"7+>>uE	F 	F s   AAr4   )appr   rH   r   s    `` r,   rF   rF      s     r.   c                     t        | t        j                         j                  d|d      \  }}t        j                  ||       y )Nr#   )typerO   )client_options	mechanism)r   )r   r@   rA   optionscapture_event)rV   rO   r   r   s       r,   rQ   rQ      s?    &!,,.66#8KE4
 U.r.   )0r_   r@   sentry_sdk.tracingr   sentry_sdk.utilsr   r   r   r   r   sentry_sdk.integrationsr	   r
   r   sentry_sdk.integrations.wsgir   $sentry_sdk.integrations._wsgi_commonr   typingr   collections.abcr   r   r   r   r   r   r#   r   r   r   sentry_sdk._typesr   r   r   r   r   r   rG   r   r[   ImportErrorr(   r"   rj   r   rF   rQ   r4   r.   r,   <module>r      s      /  
 > A  #<::7	/  / `5 `5F#- #>P$/U  /
-
../s   2B" "B0