
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    „á§\—  ã                   @   s”   d dl mZ d dl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 d dlmZmZmZmZ G dd	„ d	e	ƒZG d
d„ deƒZdd„ ZdS )é    )Úabsolute_import)ÚHub)Úcapture_internal_exceptionsÚevent_from_exceptionÚtransaction_from_function)ÚIntegration)ÚSentryWsgiMiddleware)ÚRequestExtractor)ÚBottleÚRouteÚrequestÚHTTPResponsec                   @   s*   e Zd ZdZdZddd„Zedd„ ƒZdS )	ÚBottleIntegrationÚbottleNÚendpointc                 C   s&   d}||krt d||f ƒ‚|| _d S )N)r   Úurlz7Invalid value for transaction_style: %s (must be in %s))Ú
ValueErrorÚtransaction_style)Úselfr   ZTRANSACTION_STYLE_VALUES© r   úO/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/integrations/bottle.pyÚ__init__"   s    ÿÿzBottleIntegration.__init__c                     sL   t j‰ ‡ fdd„} | t _t j‰‡fdd„}|t _tj‰‡fdd„}|t_d S )Nc                    s<   t j}| t¡}|d kr$ˆˆ ||ƒS t‡‡ fdd„ƒ||ƒS )Nc                     s   ˆ ˆf| ž|ŽS ©Nr   )ÚaÚkw)Úold_appr   r   r   Ú<lambda>;   ó    zOBottleIntegration.setup_once.<locals>.sentry_patched_wsgi_app.<locals>.<lambda>)r   ÚcurrentÚget_integrationr   r   )r   ÚenvironZstart_responseÚhubÚintegration)r   ©r   r   Úsentry_patched_wsgi_app3   s    
 ÿz=BottleIntegration.setup_once.<locals>.sentry_patched_wsgi_appc              
      sx   t j}| t¡}|d kr"ˆ | |ƒS | ¡ }|�@ | }| ¡ �}d|_| t|t	|ƒ¡ W 5 Q R X ˆ | |ƒ}W 5 Q R X |S )Nr   )
r   r   r   r   Z
push_scopeZconfigure_scopeÚ_nameZadd_event_processorÚ_make_request_event_processorÚbottle_request)r   r    r!   r"   Zscope_managerÚappZscopeÚres)Ú
old_handler   r   Ú_patched_handleD   s    



ÿz5BottleIntegration.setup_once.<locals>._patched_handlec                    s>   t j‰ ˆ  t¡}ˆ| f|ž|Ž‰|d kr,ˆS ‡ ‡fdd„}|S )Nc               
      sb   ‡ fdd„}zˆ| |Ž}W nB t k
r0   ‚ Y n. tk
r\ } z||ƒ |‚W 5 d }~X Y nX |S )Nc                    s.   t | ˆ jjdddœd�\}}ˆ j||d� d S )Nr   F)ÚtypeZhandled)Zclient_optionsZ	mechanism)Úhint)r   ZclientÚoptionsZcapture_event)Ú	exceptionÚeventr-   )r!   r   r   Úcapture_exceptionf   s    ý
zpBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callback.<locals>.capture_exception)r   Ú	Exception)ÚargsÚkwargsr1   r)   r/   ©r!   Zprepared_callbackr   r   Úwrapped_callbacke   s    zUBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callback)r   r   r   r   )r   r3   r4   r"   r6   )Úold_make_callbackr5   r   Úpatched_make_callback^   s    
z;BottleIntegration.setup_once.<locals>.patched_make_callback)r
   Ú__call__Z_handler   Z_make_callback)r$   r+   r8   r   )r   r*   r7   r   Ú
setup_once,   s    zBottleIntegration.setup_once)r   )Ú__name__Ú
__module__Ú__qualname__Z
identifierr   r   Ústaticmethodr:   r   r   r   r   r      s
   

r   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚBottleRequestExtractorc                 C   s   | j jS r   )r   r    r#   r   r   r   Úenv~   s    zBottleRequestExtractor.envc                 C   s   | j jS r   )r   Úcookiesr#   r   r   r   rA   ‚   s    zBottleRequestExtractor.cookiesc                 C   s   | j j ¡ S r   )r   ZbodyÚreadr#   r   r   r   Úraw_data†   s    zBottleRequestExtractor.raw_datac                 C   s   |   ¡ rd S | jj ¡ S r   )Úis_jsonr   ZformsÚdecoder#   r   r   r   ÚformŠ   s    zBottleRequestExtractor.formc                 C   s   |   ¡ rd S | jjS r   )rD   r   Úfilesr#   r   r   r   rG   �   s    zBottleRequestExtractor.filesc                 C   s   |j S r   )Zcontent_length)r   Úfiler   r   r   Úsize_of_file—   s    z#BottleRequestExtractor.size_of_fileN)	r;   r<   r=   r@   rA   rC   rF   rG   rI   r   r   r   r   r?   }   s   r?   c                    s   ‡ ‡fdd„}|S )Nc              	      sx   z>ˆ j dkr&ˆjjptˆjjƒ| d< nˆ j dkr<ˆjj| d< W n tk
rR   Y nX tƒ � tˆƒ 	| ¡ W 5 Q R X | S )Nr   Ztransactionr   )
r   ZrouteÚnamer   ÚcallbackZruler2   r   r?   Zextract_into_event)r0   r-   ©r"   r   r   r   Úinnerž   s    

ÿ

z,_make_request_event_processor.<locals>.innerr   )r(   r   r"   rM   r   rL   r   r&   œ   s    r&   N)Z
__future__r   Zsentry_sdk.hubr   Zsentry_sdk.utilsr   r   r   Zsentry_sdk.integrationsr   Zsentry_sdk.integrations.wsgir   Z$sentry_sdk.integrations._wsgi_commonr	   Z_ScopedResponseZAnyZDictÚCallableZOptionalZ
FileUploadZ	FormsDictZLocalRequestr   r
   r   r   r'   r   r   r?   r&   r   r   r   r   Ú<module>   s   
`