o
    0 i[                     @   s(  d dl Z d dlmZ d dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ zd dlZd dlmZ d dlmZmZ d d	lmZ W n eyS   ed
w d dlmZ er~d dlmZ d dlmZ d dlmZ d dlmZ ededef dZG dd deZdd Z G dd deZ!dS )    Nwraps)IntegrationDidNotEnable)_make_request_event_processor)TransactionSource)capture_internal_exceptionsevent_from_exceptionparse_versionreraise)__version__)ChaliceChaliceViewError)EventSourceHandlerzChalice is not installed)TYPE_CHECKING)Any)Dict)TypeVar)CallableF.)boundc                   @   s   e Zd Zdd ZdS )r   c              
   C   s   t  }t  b}t  | }|t||| W d    n1 s$w   Y  zt| ||W W  d    S  t	ya   t
 }t||jdddd\}}t j||d |  t|  Y nw W d    d S 1 smw   Y  d S )NchaliceFtypeZhandledZclient_optionsZ	mechanismhint)
sentry_sdk
get_clientisolation_scoper   get_remaining_time_in_millisadd_event_processorr   ChaliceEventSourceHandler__call__	Exceptionsysexc_infor	   optionscapture_eventflushr   )selfeventcontextclientscopeconfigured_timer&   r    r0   k/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/chalice.pyr#   #   s0   


	"zEventSourceHandler.__call__N)__name__
__module____qualname__r#   r0   r0   r0   r1   r   "   s    r   c                    s   t  fdd}|S )Nc                     s  t  }t  o}t $  j }|j jjtj	d |
t j  j| W d    n1 s3w   Y  zdi | W W  d    S  tyv } z#t|trU t }t||jdddd\}}t j||d |   d }~ww 1 szw   Y  d S )N)sourcer   Fr   r   r   r0   )r   r   r   r   Zlambda_contextr    Zset_transaction_nameZfunction_namer   Z	COMPONENTr!   r   Zcurrent_requestto_dictr$   
isinstancer   r%   r&   r	   r'   r(   r)   )function_argsr-   r.   r/   excr&   r+   r   appview_functionr0   r1   wrapped_view_function=   sD   



z:_get_view_function_response.<locals>.wrapped_view_functionr   r;   r<   r8   r=   r0   r:   r1   _get_view_function_response;   s   !r?   c                   @   s   e Zd ZdZedd ZdS )ChaliceIntegrationr   c                     sn   t t} | d u rtdt| dk rtj n	ddlm} |j  fdd}| dk r.|t_n||_tt	j
_d S )NzUnparsable Chalice version: {})      r   )RestAPIEventHandlerc                    s   t | ||} | ||S )N)r?   r>   Zold_get_view_function_responser0   r1   sentry_event_responsew   s   z<ChaliceIntegration.setup_once.<locals>.sentry_event_response)r
   CHALICE_VERSIONr   formatr   r?   chalice.apprC   r   r   r;   )versionrC   rE   r0   rD   r1   
setup_oncee   s   
zChaliceIntegration.setup_onceN)r2   r3   r4   
identifierstaticmethodrJ   r0   r0   r0   r1   r@   b   s    r@   )"r%   	functoolsr   r   Zsentry_sdk.integrationsr   r   Z"sentry_sdk.integrations.aws_lambdar   Zsentry_sdk.tracingr   Zsentry_sdk.utilsr   r	   r
   r   r   r   rF   r   r   rH   r   r"   ImportErrortypingr   r   r   r   r   r   r?   r@   r0   r0   r0   r1   <module>   s2    '