
    tni                        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) n# e*$ r  ed          w xY w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&Z3dS )(    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                   V    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
d
S )BottleIntegrationbottlez
auto.http. r    )failed_request_status_codestransaction_styler&   zSet[int]returnNc                j    |t           vrt          d|dt           d          || _        || _        d S )Nz%Invalid value for transaction_style: z (must be in ))TRANSACTION_STYLE_VALUES
ValueErrorr'   r&   )selfr'   r&   s      [/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/integrations/bottle.py__init__zBottleIntegration.__init__8   sT     $<<<*$$$&>&>&>@   "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          _        d S )Nr-   r   environDict[str, str]start_responseCallable[..., Any]r(   r   c                 \     t           fdt          j                  } |||          S )Nc                       g| R i |S N )akwold_appr-   s     r.   <lambda>zOBottleIntegration.setup_once.<locals>.sentry_patched_wsgi_app.<locals>.<lambda>R   s!    !8!8!8!8R!8!8 r0   )span_origin)r   r#   origin)r-   r2   r4   
middlewarer<   s   `   r.   sentry_patched_wsgi_appz=BottleIntegration.setup_once.<locals>.sentry_patched_wsgi_appM   sC     .88888-4  J
 :g~666r0   r   Dict[str, Any]c                    t          j                                        t                    }| | |          S t          j                    }d|_        |                    t          | t          |                      | |          }|S )Nr$   )	
sentry_sdk
get_clientget_integrationr#   get_isolation_scope_nameadd_event_processor_make_request_event_processorbottle_request)r-   r2   integrationscoperes
old_handles        r.   _patched_handlez5BottleIntegration.setup_once.<locals>._patched_handle\   s    $/11AABSTTK"!z$000244E"EK%%-dNKPP   *T7++CJr0   r   argskwargsc                      | g|R i |t          j                                        t                    S dt          dt          ddffd}|S )NrQ   rR   r(   r   c                      	  | i |}n%# t           $ r}t          |d           |d }~ww xY wt          |t                    r|j        j        v rt          |d           |S )NF)handledT)	Exception_capture_exception
isinstancer   status_coder&   )rQ   rR   rN   	exceptionrL   prepared_callbacks       r.   wrapped_callbackzUBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callbacky   s    $++T<V<<CC  $ $ $&y%@@@@#O$
 sL11:;+RRR&sD9999
s    
.).)rD   rE   rF   r#   object)r-   rQ   rR   r\   rL   r[   old_make_callbacks       @@r.   patched_make_callbackz;BottleIntegration.setup_once.<locals>.patched_make_callbacko   s     !2 1$ H H H H H H$/11AABSTTK"(( & U        $#r0   )r-   r   r2   r3   r4   r5   r(   r   )r-   r   r2   rB   r(   r   )r   BOTTLE_VERSIONr   r#   r   __call__r   _handle	functoolswrapsr   _make_callbackr]   )versionrA   rP   r_   r<   rO   r^   s       @@@r.   
setup_oncezBottleIntegration.setup_onceF   s8   //0':::/	#$5w	?	?	7	7"2	7DX	7	7 	7 	7 	7 	7 
@	?	7 2^
		$	$	 	 	 	 	 
%	$	 )!0	*	+	+	$	$"(	$4:	$	$ 	$ 	$ 	$ 	$ 
,	+	$4  5r0   )r    )r(   N)__name__
__module____qualname__
identifierr?   r'   r   strr/   staticmethodrg   r9   r0   r.   r#   r#   2   s        J&*&&F ",G 3W	G G GG &0	G
 
G G G G C5 C5 C5 \C5 C5 C5r0   r#   c                   J    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
dS )BottleRequestExtractorr(   r3   c                     | j         j        S r8   )r   r2   r-   s    r.   envzBottleRequestExtractor.env       |##r0   c                     | j         j        S r8   )r   cookiesrq   s    r.   ru   zBottleRequestExtractor.cookies   rs   r0   c                 >    | j         j                                        S r8   )r   bodyreadrq   s    r.   raw_datazBottleRequestExtractor.raw_data   s    | %%'''r0   r   c                 j    |                                  rd S | j        j                                        S r8   )is_jsonr   formsdecoderq   s    r.   formzBottleRequestExtractor.form   s.    <<>> 	4|!((***r0   Optional[Dict[str, str]]c                 F    |                                  rd S | j        j        S r8   )r{   r   filesrq   s    r.   r   zBottleRequestExtractor.files   s"    <<>> 	4|!!r0   filer   c                     |j         S r8   )content_length)r-   r   s     r.   size_of_filez#BottleRequestExtractor.size_of_file   s    ""r0   N)r(   r3   )r(   r   )r(   r   )rh   ri   rj   rr   ru   bytesry   r~   r   intr   r9   r0   r.   ro   ro      s        $ $ $ $$ $ $ $(% ( ( ( (+ + + +
" " " "# ## # # # # # #r0   ro   eventr   r'   r   r   r(   c                    d}|dk    r 	 |j         j        pd}nO# t          $ r Y nCw xY w|dk    r9	 |j         j        pt	          |j         j                  pd}n# t          $ r Y nw xY w|| d<   dt          |         i| d<   d S )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!!	=%+DD 	 	 	D	 
j	(	(	" ,W]-CDD D
  	 	 	D	  E-!)+;<M+N OE
s    
&&'A 
A%$A%appr   r   rL   r   c                     dfd}|S )Nr   r   hintdict[str, Any]r(   c                     t          | j                   t                      5  t                                        |            d d d            n# 1 swxY w Y   | S r8   )r   r'   r   ro   extract_into_event)r   r   rL   r   s     r.   event_processorz6_make_request_event_processor.<locals>.event_processor   s    (0MwWWW(** 	F 	F"7++>>uEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F s   #AAA)r   r   r   r   r(   r   r9   )r   r   rL   r   s    `` r.   rJ   rJ      s/           r0   rZ   rU   c                     t          | t          j                    j        d|d          \  }}t          j        ||           d S )Nr$   )typerU   )client_options	mechanism)r   )r   rD   rE   optionscapture_event)rZ   rU   r   r   s       r.   rW   rW      sU    &!,..6#88  KE4
 U......r0   )r   r   r   r   rL   r#   r(   r   )4rc   rD   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   rK   r   r`   ImportErrorr+   r#   ro   rl   r   rJ   BaseExceptionboolrW   r9   r0   r.   <module>r      s           / / / / / /                         > = = = = = A A A A A A             
8######<<<<<<::::::::::77777777	/                / / /
,-
.
../ / X5 X5 X5 X5 X5 X5 X5 X5v# # # # #- # # #2PP'*P5:P	P P P P2	*9L   /- /$ /4 / / / / / /s   4B B