
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    „á§\™  ã                   @   sÜ   d dl Z d dlZd dlmZ d dlmZ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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 G dd„ deƒZ&dd„ Z'dd„ Z(G dd„ deƒZ)dS )é    N)Úisawaitable)ÚurlparseÚreraise)ÚHub)Úcapture_internal_exceptionsÚevent_from_exceptionÚHAS_REAL_CONTEXTVARS)ÚIntegration)ÚRequestExtractorÚ_filter_headers)Úignore_logger)ÚSanicÚ__version__)ÚSanicException)ÚRouter)ÚErrorHandlerc                   @   s   e Zd ZdZedd„ ƒZdS )ÚSanicIntegrationÚsanicc                     sj   t stdƒ‚t d¡rtdƒ tj‰‡fdd„} | t_tj‰‡fdd„}|t_t	j
‰ ‡ fdd	„}|t	_
d S )
NzPThe sanic integration for Sentry requires Python 3.7+  or aiocontextvars packagez0.8.Úrootc              
   Ÿ   s¢   t j}| t¡d kr&ˆ | |f|ž|ŽS t |¡}t |ƒ�`}| ¡ �}| ¡  | t	|ƒ¡ W 5 Q R X ˆ | |f|ž|Ž}t
|ƒrˆ|I d H }|W  5 Q R £ S Q R X d S ©N)r   ÚcurrentÚget_integrationr   ÚweakrefÚrefÚconfigure_scopeZclear_breadcrumbsZadd_event_processorÚ_make_request_processorr   )ÚselfÚrequestÚargsÚkwargsÚhubÚweak_requestÚscopeÚresponse)Úold_handle_request© úN/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/integrations/sanic.pyÚsentry_handle_request=   s    



z:SanicIntegration.setup_once.<locals>.sentry_handle_requestc              
      sT   ˆ | |ƒ}t j}| t¡d k	rPtƒ �& | ¡ �}|d j|_W 5 Q R X W 5 Q R X |S ©Nr   )r   r   r   r   r   r   Ú__name__Ztransaction)r   r   Úrvr    r"   )Úold_router_getr%   r&   Úsentry_router_getT   s    

 z6SanicIntegration.setup_once.<locals>.sentry_router_getc                    sB   t |ƒ ˆ| |ƒ‰ ˆ d krd S tj t¡d kr2ˆ S ‡ fdd„}|S )Nc                 “   sT   z"ˆ | |ƒ}t |ƒr|I d H }|W S  tk
rN   t ¡ }t|ƒ t|Ž  Y nX d S r   )r   Ú	ExceptionÚsysÚexc_infoÚ_capture_exceptionr   )r   Ú	exceptionr#   r/   ©Zold_error_handlerr%   r&   Úsentry_wrapped_error_handlerm   s    

zfSanicIntegration.setup_once.<locals>.sentry_error_handler_lookup.<locals>.sentry_wrapped_error_handler)r0   r   r   r   r   )r   r1   r3   )Úold_error_handler_lookupr2   r&   Úsentry_error_handler_lookupb   s    
z@SanicIntegration.setup_once.<locals>.sentry_error_handler_lookup)r   ÚRuntimeErrorÚVERSIONÚ
startswithr   r   Zhandle_requestr   Úgetr   Úlookup)r'   r,   r5   r%   )r4   r$   r+   r&   Ú
setup_once$   s    ÿ


zSanicIntegration.setup_onceN)r)   Ú
__module__Ú__qualname__Ú
identifierÚstaticmethodr;   r%   r%   r%   r&   r   !   s   r   c              	   C   s\   t j}| t¡}|d krd S tƒ �0 t| |jjdddœd�\}}|j||d� W 5 Q R X d S )Nr   F)ÚtypeZhandled)Zclient_optionsZ	mechanism)Úhint)	r   r   r   r   r   r   ZclientÚoptionsZcapture_event)r1   r    ZintegrationÚeventrA   r%   r%   r&   r0   �   s    
ý
r0   c                    s   ‡ fdd„}|S )Nc              	      sÌ   zt |d d tƒrW d S W n tk
r0   Y nX ˆ ƒ }|d krD| S tƒ �x t|ƒ}| | ¡ | d }t |j¡}d|j	|j
|jf |d< |j|d< |j|d< d|ji|d	< tt|jƒƒ|d
< W 5 Q R X | S )Nr/   r   r   z	%s://%s%sÚurlZquery_stringÚmethodZREMOTE_ADDRÚenvÚheaders)Ú
issubclassr   ÚKeyErrorr   ÚSanicRequestExtractorZextract_into_eventr   ÚurlsplitrD   ÚschemeÚnetlocÚpathÚqueryrE   Zremote_addrr   ÚdictrG   )rC   rA   r   Z	extractorZrequest_infoZurlparts©r!   r%   r&   Úsanic_processor“   s.    

ý


z0_make_request_processor.<locals>.sanic_processorr%   )r!   rR   r%   rQ   r&   r   ‘   s    !r   c                   @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )rJ   c                 C   s   | j jd krdS t| j jƒS r(   )r   ÚbodyÚlen©r   r%   r%   r&   Úcontent_length¸   s    z$SanicRequestExtractor.content_lengthc                 C   s   t | jjƒS r   )rP   r   ÚcookiesrU   r%   r%   r&   rW   ¾   s    zSanicRequestExtractor.cookiesc                 C   s   | j jS r   )r   rS   rU   r%   r%   r&   Úraw_dataÁ   s    zSanicRequestExtractor.raw_datac                 C   s   | j jS r   )r   ÚformrU   r%   r%   r&   rY   Å   s    zSanicRequestExtractor.formc                 C   s
   t ƒ ‚d S r   )ÚNotImplementedErrorrU   r%   r%   r&   Úis_jsonÉ   s    zSanicRequestExtractor.is_jsonc                 C   s   | j jS r   )r   ÚjsonrU   r%   r%   r&   r\   Ì   s    zSanicRequestExtractor.jsonc                 C   s   | j jS r   )r   ÚfilesrU   r%   r%   r&   r]   Ð   s    zSanicRequestExtractor.filesc                 C   s   t |jp
dƒS )Nr%   )rT   rS   )r   Úfiler%   r%   r&   Úsize_of_fileÔ   s    z"SanicRequestExtractor.size_of_fileN)r)   r<   r=   rV   rW   rX   rY   r[   r\   r]   r_   r%   r%   r%   r&   rJ   ·   s   rJ   )*r.   r   Úinspectr   Zsentry_sdk._compatr   r   Zsentry_sdk.hubr   Zsentry_sdk.utilsr   r   r   Zsentry_sdk.integrationsr	   Z$sentry_sdk.integrations._wsgi_commonr
   r   Zsentry_sdk.integrations.loggingr   r   r   r   r7   Zsanic.exceptionsr   Zsanic.routerr   Zsanic.handlersr   ÚRequestZAnyÚCallableÚDictÚOptionalÚUnionZTupleZRequestParametersr   r0   r   rJ   r%   r%   r%   r&   Ú<module>   s    `&