o
    Zh                     @   s4  d dl Z d dlmZ d dlm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 d dlmZ d d	lmZ d dlZd d
lmZmZ d dlmZ erpd 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zd dlm Z! W n e"y   edw G dd deZdd Z#G dd deZ$dS )    N)reraise)Hub)IntegrationDidNotEnable)_make_request_event_processor)TRANSACTION_SOURCE_COMPONENT)capture_internal_exceptionsevent_from_exceptionparse_version)TYPE_CHECKINGwraps)ChaliceChaliceViewError)EventSourceHandler)Any)Dict)TypeVar)CallableF.)bound)__version__zChalice is not installedc                   @   s   e Zd Zdd ZdS )r   c           	   
   C   s   t j}|j}| b}t  | }|t||| W d    n1 s&w   Y  zt	| ||W W  d    S  t
yc   t }t||jdddd\}}|j||d |  t|  Y nw W d    d S 1 sow   Y  d S )NchaliceFtypeZhandledZclient_optionsZ	mechanismhint)r   currentclient
push_scoper   get_remaining_time_in_millisadd_event_processorr   ChaliceEventSourceHandler__call__	Exceptionsysexc_infor	   optionscapture_eventflushr   )	selfeventcontexthubr   scopeconfigured_timer'   r    r1   V/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/chalice.pyr$   #   s2   


	"zEventSourceHandler.__call__N)__name__
__module____qualname__r$   r1   r1   r1   r2   r   "   s    r   c                    s   t  fdd}|S )Nc            	         s  t j}|j}| n}t #  j }|j jjt	d |
t j  j| W d    n1 s4w   Y  zdi | W W  d    S  tyw } z#t|trV t }t||jdddd\}}|j||d |   d }~ww 1 s{w   Y  d S )N)sourcer   Fr   r   r   r1   )r   r   r   r    r   Zlambda_contextr!   Zset_transaction_nameZfunction_namer   r"   r   Zcurrent_requestto_dictr%   
isinstancer   r&   r'   r	   r(   r)   r*   )	function_argsr.   r   r/   r0   excr'   r,   r   appview_functionr1   r2   wrapped_view_function>   sF   



z:_get_view_function_response.<locals>.wrapped_view_functionr   r<   r=   r9   r>   r1   r;   r2   _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_responser1   r2   sentry_event_responsey   s   z<ChaliceIntegration.setup_once.<locals>.sentry_event_response)r
   CHALICE_VERSIONr   formatr   r@   chalice.apprD   r   r   r<   )versionrD   rF   r1   rE   r2   
setup_onceg   s   
zChaliceIntegration.setup_onceN)r3   r4   r5   
identifierstaticmethodrK   r1   r1   r1   r2   rA   d   s    rA   )%r&   Zsentry_sdk._compatr   Zsentry_sdk.hubr   Zsentry_sdk.integrationsr   r   Z"sentry_sdk.integrations.aws_lambdar   Zsentry_sdk.tracingr   Zsentry_sdk.utilsr   r	   r
   Zsentry_sdk._typesr   Zsentry_sdk._functoolsr   r   r   r   rI   r   r#   typingr   r   r   r   r   r   rG   ImportErrorr@   rA   r1   r1   r1   r2   <module>   s4    (