o
    h                     @   s  d dl Z d dlZd dlZd dl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 d dlmZ d dlmZmZmZmZ zd dlmZ d d	lmZ W n eyY   ed
w d dlmZ erd 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$ d dl%m&Z& d dlm'Z' d dl(m)Z)m*Z* e+eddrdd Z,nd dl-m,Z, dZ.G dd deZ/ee/dd Z0dd Z1G d d! d!e	Z2d"d# Z3dS )$    N)IntegrationDidNotEnable)RequestExtractor)SentryWsgiMiddleware)should_send_default_pii)SOURCE_FOR_STYLE)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionreraise)HTTPException)RequestzPyramid not installed)TYPE_CHECKING)Response)Any)_ScopedResponse)Callable)Dict)Optional)RequestCookies)_FieldStorageWithFile)ExcInfo)EventEventProcessorauthenticated_useridc                 C   s   | j S Nr   )request r   a/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/pyramid.pyr   +   s   r   
route_nameroute_patternc                   @   s4   e Zd ZdZde ZdZd
ddZedd Zd	S )PyramidIntegrationpyramidz
auto.http. r!   c                 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_style)selfr(   r   r   r   __init__=   s   
zPyramidIntegration.__init__c                     sz   ddl m}  | j t  fdd}|| _ttdr(tjfdd}|t_| jj	t
tfdd	}|| j_	d S )
Nr   )routerc                    sv   t  t}|d u r | |g|R i |S tt  |j| t  }|t	t
||  | |g|R i |S r   )
sentry_sdk
get_clientget_integrationr#    _set_transaction_name_and_sourceget_current_scoper(   get_isolation_scopeadd_event_processor_make_event_processorweakrefref)registryr   argskwargsintegrationscope)old_call_viewr   r   sentry_patched_call_viewM   s   z?PyramidIntegration.setup_once.<locals>.sentry_patched_call_viewinvoke_exception_viewc                    sP    | g|R i |}| j r&t| j r&|jdkr&t td ur&t| j  |S )Ni  )exc_infoall
status_intr,   r-   r.   r#   _capture_exception)r)   r7   r8   rv)old_invoke_exception_viewr   r   $sentry_patched_invoke_exception_viewc   s   

zKPyramidIntegration.setup_once.<locals>.sentry_patched_invoke_exception_viewc                    s&    fdd}t |tjd}|||S )Nc                    s<   z | |W S  t y   t }t| t|  Y d S w r   )	Exceptionsysr>   rA   r   )environstart_responseeinfo)old_wsgi_callr)   r   r   sentry_patched_inner_wsgi_cally   s   zgPyramidIntegration.setup_once.<locals>.sentry_patched_wsgi_call.<locals>.sentry_patched_inner_wsgi_call)span_origin)r   r#   origin)r)   rG   rH   rK   
middleware)rJ   r)   r   sentry_patched_wsgi_callv   s   	
z?PyramidIntegration.setup_once.<locals>.sentry_patched_wsgi_call)r$   r+   
_call_view	functoolswrapshasattrr   r=   Router__call__r	   r#   )r+   r<   rD   rP   r   )r;   rC   rJ   r   
setup_onceF   s   
zPyramidIntegration.setup_onceN)r!   )	__name__
__module____qualname__
identifierrM   r(   r*   staticmethodrW   r   r   r   r   r#   7   s    

	r#   c                 C   sN   | d d u st | d trd S t| t jdddd\}}tj||d d S )Nr   r$   F)typehandled)client_options	mechanism)hint)
issubclassr   r
   r,   r-   optionscapture_event)r>   eventra   r   r   r   rA      s   
rA   c                 C   sD   z|j j|j jd}| j|| t| d W d S  ty!   Y d S w )Nr    )source)matched_routenamepatternset_transaction_namer   rE   )r:   r(   r   name_for_styler   r   r   r/      s   r/   c                   @   sD   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S )PyramidRequestExtractorc                 C      | j jS r   )r   path_urlrO   r   r   r   url      zPyramidRequestExtractor.urlc                 C   rm   r   )r   rG   rO   r   r   r   env   rp   zPyramidRequestExtractor.envc                 C   rm   r   )r   cookiesrO   r   r   r   rr      rp   zPyramidRequestExtractor.cookiesc                 C   rm   r   )r   textrO   r   r   r   raw_data   rp   z PyramidRequestExtractor.raw_datac                 C      dd | j j D S )Nc                 S   s"   i | ]\}}t |d ds||qS filenameNgetattr.0keyvaluer   r   r   
<dictcomp>       
z0PyramidRequestExtractor.form.<locals>.<dictcomp>r   POSTitemsrO   r   r   r   form      
zPyramidRequestExtractor.formc                 C   ru   )Nc                 S   s"   i | ]\}}t |d dr||qS rv   rx   rz   r   r   r   r~      r   z1PyramidRequestExtractor.files.<locals>.<dictcomp>r   rO   r   r   r   files   r   zPyramidRequestExtractor.filesc                 C   s.   |j }z	t| jW S  ty   Y dS w )Nr   )fileosfstatfilenost_sizerE   )r)   postdatar   r   r   r   size_of_file   s   z$PyramidRequestExtractor.size_of_fileN)
rX   rY   rZ   ro   rq   rr   rt   r   r   r   r   r   r   r   rl      s    rl   c                    s    fdd}|S )Nc                    s     }|d u r	| S t   t||  W d    n1 sw   Y  t rHt   | di }|dt| W d    | S 1 sCw   Y  | S )Nuserid)r   rl   extract_into_eventr   
setdefaultr   )re   ra   r   	user_infoweak_requestr   r   pyramid_event_processor   s   
z6_make_event_processor.<locals>.pyramid_event_processorr   )r   r9   r   r   r   r   r3      s   r3   )4rR   r   rF   r4   r,   sentry_sdk.integrationsr   r   $sentry_sdk.integrations._wsgi_commonr   sentry_sdk.integrations.wsgir   sentry_sdk.scoper   sentry_sdk.tracingr   sentry_sdk.utilsr   r	   r
   r   pyramid.httpexceptionsr   pyramid.requestr   ImportErrortypingr   pyramid.responser   r   r   r   r   r   webob.cookiesr   webob.requestr   r   sentry_sdk._typesr   r   ry   r   pyramid.securityr&   r#   rA   r/   rl   r3   r   r   r   r   <module>   sN    
T
*