a
    xdX                     @   sF  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 d dlmZ d dlmZ erd 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 z d dlmZm Z m!Z"m#Z#m$Z% W n e&y   edY n0 dZ'G dd deZ(G dd deZ)dd Z*dd Z+dS )    )absolute_import)Hub)SOURCE_FOR_STYLE)capture_internal_exceptionsevent_from_exceptiontransaction_from_function)IntegrationDidNotEnable)SentryWsgiMiddleware)RequestExtractor)MYPY)_ScopedResponse)Any)Dict)Callable)Optional)
FileUpload	FormsDictLocalRequest)EventProcessorEvent)BottleRouterequestHTTPResponse__version__zBottle not installed)endpointurlc                   @   s*   e Zd ZdZdZd	ddZedd ZdS )
BottleIntegrationbottle r   c                 C   s"   |t vrtd|t f || _d S )Nz7Invalid value for transaction_style: %s (must be in %s))TRANSACTION_STYLE_VALUES
ValueErrortransaction_style)selfr#    r%   V/var/www/html/Ranjet/env/lib/python3.9/site-packages/sentry_sdk/integrations/bottle.py__init__.   s    zBottleIntegration.__init__c               	      s   z t tttddd} W n$ ttfyD   td	| Y n0 | dk rVtdt
j  fdd}|t
_t
jfd	d
}|t
_tjfdd}|t_d S )Nz-devr    .zUnparsable Bottle version: {})r      zBottle 0.12 or newer required.c                    s<   t j}|t}|d u r$ ||S t fdd||S )Nc                     s    g| R i |S Nr%   )akw)old_appr$   r%   r&   <lambda>O       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_appG   s    
z=BottleIntegration.setup_once.<locals>.sentry_patched_wsgi_appc              	      s   t j}|t}|d u r" | |S | }|^ | }| (}d|_|t|t	| W d    n1 sj0    Y   | |}W d    n1 s0    Y  |S )Nr   )
r   r0   r1   r   Z
push_scopeZconfigure_scope_nameZadd_event_processor_make_request_event_processorbottle_request)r$   r2   r3   r4   Zscope_managerappZscoperes)
old_handler%   r&   _patched_handleX   s    



"(z5BottleIntegration.setup_once.<locals>._patched_handlec                    sL   t jt}| g|R i ||d u r2S j  fdd}|S )Nc               
      sz   z| i |}W nb t y&    Y nP tyt } z8t| jdddd\}}j||d |W Y d }~n
d }~0 0 |S )Nr   F)typeZhandled)Zclient_optionsZ	mechanism)hint)r   	Exceptionr   optionsZcapture_event)argskwargsr;   	exceptioneventr?   clientr3   Zprepared_callbackr%   r&   wrapped_callback~   s    
zUBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callback)r   r0   r1   r   rG   )r$   rB   rC   r4   rH   )old_make_callbackrF   r&   patched_make_callbacks   s    
z;BottleIntegration.setup_once.<locals>.patched_make_callback)tuplemapintBOTTLE_VERSIONreplacesplit	TypeErrorr"   r	   formatr   __call___handler   Z_make_callback)versionr6   r=   rJ   r%   )r-   r<   rI   r&   
setup_once8   s     zBottleIntegration.setup_onceN)r   )__name__
__module____qualname__
identifierr#   r'   staticmethodrV   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   r2   r5   r%   r%   r&   env   s    zBottleRequestExtractor.envc                 C   s   | j jS r*   )r   cookiesr5   r%   r%   r&   r^      s    zBottleRequestExtractor.cookiesc                 C   s   | j j S r*   )r   bodyreadr5   r%   r%   r&   raw_data   s    zBottleRequestExtractor.raw_datac                 C   s   |   rd S | jj S r*   )is_jsonr   Zformsdecoder5   r%   r%   r&   form   s    zBottleRequestExtractor.formc                 C   s   |   rd S | jjS r*   )rb   r   filesr5   r%   r%   r&   re      s    zBottleRequestExtractor.filesc                 C   s   |j S r*   )content_length)r$   filer%   r%   r&   size_of_file   s    z#BottleRequestExtractor.size_of_fileN)	rW   rX   rY   r]   r^   ra   rd   re   rh   r%   r%   r%   r&   r\      s   r\   c                 C   sV   d}|dkr|j jpd}n |dkr:|j jp8t|j jp8d}|| d< dt| i| d< d S )Nr    r   r   ZtransactionsourceZtransaction_info)ZrouteZrulenamer   callbackr   )rE   r#   r   rj   r%   r%   r&    _set_transaction_name_and_source   s    
rl   c                    s    fdd}|S )Nc                    sF   t |  j t  t|  W d    n1 s80    Y  | S r*   )rl   r#   r   r\   Zextract_into_event)rE   r?   r4   r   r%   r&   event_processor   s    ,z6_make_request_event_processor.<locals>.event_processorr%   )r:   r   r4   rn   r%   rm   r&   r8      s    	r8   N),
__future__r   Zsentry_sdk.hubr   Zsentry_sdk.tracingr   Zsentry_sdk.utilsr   r   r   Zsentry_sdk.integrationsr   r	   Zsentry_sdk.integrations.wsgir
   Z$sentry_sdk.integrations._wsgi_commonr   Zsentry_sdk._typesr   r   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r9   r   r   rN   ImportErrorr!   r   r\   rl   r8   r%   r%   r%   r&   <module>   s0    l