<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</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    `&