o
    h                     @   s\  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rrd 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" zd dlm#Z#m$Z$m%Z%m&Z'm(Z) W n e*y   edw dZ+G dd deZ,G dd deZ-dd Z.dd Z/dd Z0d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                   @   s<   e Zd ZdZde ZdZ	dedddZedd	 Z	d
S )BottleIntegrationbottlez
auto.http. r   )failed_request_status_codesc                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_styler$   )selfr'   r$    r)   `/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/bottle.py__init__8   s   
zBottleIntegration.__init__c                     s|   t t} tt|  tj tt  fdd}|t_tjt	fdd}|t_t
jt	fdd}|t
_d S )Nc                    s"   t  fddtjd}|||S )Nc                     s    g| R i |S Nr)   )akw)old_appr(   r)   r*   <lambda>T   s    zOBottleIntegration.setup_once.<locals>.sentry_patched_wsgi_app.<locals>.<lambda>)span_origin)r   r!   origin)r(   environstart_response
middleware)r/   r(   r*   sentry_patched_wsgi_appP   s
   
z=BottleIntegration.setup_once.<locals>.sentry_patched_wsgi_appc                    sN   t  t}|d u r | |S t  }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(   r3   integrationscoperes)
old_handler)   r*   _patched_handle^   s   


z5BottleIntegration.setup_once.<locals>._patched_handlec                    sB   | g|R i |t  t  d u rS  fdd}|S )Nc               
      sb   z	| i |}W n t y } zt|dd |d }~ww t|tr/|j jv r/t|dd |S )NF)handledT)	Exception_capture_exception
isinstancer   status_coder$   )argskwargsrB   	exceptionr@   prepared_callbackr)   r*   wrapped_callback{   s   zUBottleIntegration.setup_once.<locals>.patched_make_callback.<locals>.wrapped_callback)r8   r9   r:   r!   )r(   rJ   rK   rO   )old_make_callbackrM   r*   patched_make_callbackr   s   z;BottleIntegration.setup_once.<locals>.patched_make_callback)r   BOTTLE_VERSIONr   r!   r   __call__r   _handle	functoolswrapsr   _make_callback)versionr7   rD   rQ   r)   )r/   rC   rP   r*   
setup_onceH   s   
	
zBottleIntegration.setup_onceN)r   )
__name__
__module____qualname__
identifierr2   r'   r
   r+   staticmethodrY   r)   r)   r)   r*   r!   2   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      | j jS r,   )r   r3   r6   r)   r)   r*   env      zBottleRequestExtractor.envc                 C   r`   r,   )r   cookiesr6   r)   r)   r*   rc      rb   zBottleRequestExtractor.cookiesc                 C   s   | j j S r,   )r   bodyreadr6   r)   r)   r*   raw_data   s   zBottleRequestExtractor.raw_datac                 C   s   |   rd S | jj S r,   )is_jsonr   formsdecoder6   r)   r)   r*   form   s   zBottleRequestExtractor.formc                 C   s   |   rd S | jjS r,   )rg   r   filesr6   r)   r)   r*   rk      s   zBottleRequestExtractor.filesc                 C   s   |j S r,   )content_length)r(   filer)   r)   r*   size_of_file   s   z#BottleRequestExtractor.size_of_fileN)	rZ   r[   r\   ra   rc   rf   rj   rk   rn   r)   r)   r)   r*   r_      s    r_   c                 C   s   d}|dkrz|j jpd}W n% ty   Y nw |dkr4z|j jp(t|j jp(d}W n	 ty3   Y nw || d< dt| i| d< d S )Nr#   r    r   transactionsourcetransaction_info)routeruleRuntimeErrornamer   callbackr   )eventr'   r   ru   r)   r)   r*    _set_transaction_name_and_source   s&   
rx   c                    s    fdd}|S )Nc                    sH   t |  j t  t|  W d    | S 1 sw   Y  | S r,   )rx   r'   r   r_   extract_into_event)rw   hintr@   r   r)   r*   event_processor   s   
z6_make_request_event_processor.<locals>.event_processorr)   )appr   r@   r|   r)   r{   r*   r>      s   	r>   c                 C   s0   t | t jd|dd\}}tj||d d S )Nr"   )typerE   )client_options	mechanism)rz   )r   r8   r9   optionscapture_event)rL   rE   rw   rz   r)   r)   r*   rG      s   
rG   )1rU   r8   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   r?   r   rR   ImportErrorr%   r!   r_   rx   r>   rG   r)   r)   r)   r*   <module>   s8     ^