
    \j                        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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dde.ddddfdZ/	 	 	 	 	 	 	 	 d"dZ0de1d e2ddfd!Z3y# 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_check_minimum_version)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                   N    e Zd ZdZde ZdZ	 deddedddd	fd
Ze	dd       Z
y	)BottleIntegrationbottlez
auto.http. )failed_request_status_codestransaction_styler&   zSet[int]returnNc                \    |t         vrt        d|dt         d      || _        || _        y )Nz%Invalid value for transaction_style: z (must be in ))TRANSACTION_STYLE_VALUES
ValueErrorr'   r&   )selfr'   r&   s      H/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/bottle.py__init__zBottleIntegration.__init__8   s8     $<<$&>@  "3+F(    c            	         t        t              } t        t        |        t        j
                  t        t              	 	 	 	 	 	 	 	 d
fd       }|t        _        t        j                  t        j                        dfd       }|t        _        t        j                  t        j                        dddt        dt        ddffd	       }|t        _        y )Nr-   r   r(   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>R   s    !8!8R!8 r0   )span_origin)r   r#   origin)r-   environstart_response
middlewarer8   s   `   r.   sentry_patched_wsgi_appz=BottleIntegration.setup_once.<locals>.sentry_patched_wsgi_appM   s*     .8-44J
 g~66r0   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_handle\   sr    $//1AABSTK"!$00224E"EK%%-dNKP T7+CJr0   r   argskwargsc                      | g|i |t        j                         j                  t              S dt        dt        ddffd}|S )NrN   rO   r(   r   c                      	  | 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&   )rN   rO   rK   	exceptionrI   prepared_callbacks       r.   wrapped_callbackzUBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callbacky   se    $+T<V<C sL1;+R+RR&sD9
 ! $&y%@#O$s   A 	AAA)rA   rB   rC   r#   object)r-   rN   rO   rY   rI   rX   old_make_callbacks       @@r.   patched_make_callbackz;BottleIntegration.setup_once.<locals>.patched_make_callbacko   sb     !2$ H H H$//1AABSTK"(( & U  $#r0   )r-   r   r<   Dict[str, str]r=   zCallable[..., Any]r(   r   )r-   r   r<   zDict[str, Any]r(   r   )r   BOTTLE_VERSIONr   r#   r   __call__r   _handle	functoolswrapsr   _make_callbackrZ   )versionr?   rM   r\   r8   rL   r[   s       @@@r.   
setup_oncezBottleIntegration.setup_onceF   s    /0'://	#$5w	?	7	7"2	7DX	7	7 
@	7 2^^
		$	 
%	 )!00	*	+	$	$"(	$4:	$	$ 
,	$4  5r0   )r    )r(   N)__name__
__module____qualname__
identifierr;   r'   r   strr/   staticmethodre   r5   r0   r.   r#   r#   2   se    J*&F ",G 3W	GG &0	G
 
G C5 C5r0   r#   c                   H    e Zd ZddZddZdefdZddZddZddde	fd	Z
y
)BottleRequestExtractorr(   c                 .    | j                   j                  S r4   )r   r<   r-   s    r.   envzBottleRequestExtractor.env       ||###r0   c                 .    | j                   j                  S r4   )r   cookiesro   s    r.   rs   zBottleRequestExtractor.cookies   rq   r0   c                 J    | j                   j                  j                         S r4   )r   bodyreadro   s    r.   raw_datazBottleRequestExtractor.raw_data   s    ||  %%''r0   c                 l    | j                         ry | j                  j                  j                         S r4   )is_jsonr   formsdecodero   s    r.   formzBottleRequestExtractor.form   s'    <<>||!!((**r0   c                 P    | j                         ry | j                  j                  S r4   )ry   r   filesro   s    r.   r~   zBottleRequestExtractor.files   s    <<>||!!!r0   filer   c                     |j                   S r4   )content_length)r-   r   s     r.   size_of_filez#BottleRequestExtractor.size_of_file   s    """r0   N)r(   r]   )r(   r   )r(   zOptional[Dict[str, str]])rf   rg   rh   rp   rs   bytesrw   r|   r~   intr   r5   r0   r.   rm   rm      s5    $$(% (+
"# ## #r0   rm   eventr   r'   r   r   r(   c                 .   d}|dk(  r	 |j                   j                  xs d}nA|dk(  r<	 |j                   j                  xs# t	        |j                   j
                        xs d}|| d<   dt        |   i| d<   y # t        $ r Y w xY w# t        $ r Y .w xY w)Nr%   r!   r    transactionsourcetransaction_info)routeruleRuntimeErrornamer   callbackr   )r   r'   r   r   s       r.    _set_transaction_name_and_sourcer      s     DE!	==%%+D 
j	(	"" ,W]]-C-CD   E-!)+;<M+N OE
  		  		s"   A9 ;B 9	BB	BBc                     dfd}|S )Nc                     t        | j                         t               5  t              j	                  |        d d d        | S # 1 sw Y   | S xY wr4   )r   r'   r   rm   extract_into_event)r   hintrI   r   s     r.   event_processorz6_make_request_event_processor.<locals>.event_processor   sO    (0M0MwW(* 	F"7+>>uE	F 	F s   AA)r   r   r   zdict[str, Any]r(   r   r5   )appr   rI   r   s    `` r.   rG   rG      s     r0   rW   rR   c                     t        | t        j                         j                  d|d      \  }}t        j                  ||       y )Nr$   )typerR   )client_options	mechanism)r   )r   rA   rB   optionscapture_event)rW   rR   r   r   s       r.   rT   rT      s?    &!,,.66#8KE4
 U.r0   )r   r   r   r   rI   r#   r(   r   )4ra   rA   sentry_sdk.tracingr   sentry_sdk.utilsr   r   r   r   r   sentry_sdk.integrationsr	   r
   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   rH   r   r^   ImportErrorr+   r#   rm   rj   r   rG   BaseExceptionboolrT   r5   r0   r.   <module>r      s     /   > A  #<::7	/  / X5 X5v#- #2PP'*P5:P	P2	*9L/- /$ /4 /E  /
-
../s   4B= =C