<!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 mZ d dlZd dlZ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mZ d dlmZ d dlmZ d d	lmZ d d
lmZ e eddrdd Z!nd dl"m!Z! G dd deZ#dd Z$G dd deZ%dd Z&dS )    )absolute_importN)HTTPException)Request)Hub_should_send_default_pii)capture_internal_exceptionsevent_from_exception)reraise)Integration)RequestExtractor)SentryWsgiMiddlewareauthenticated_useridc                 C   s   | j S Nr   )request r   P/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/integrations/pyramid.pyr   !   s    r   c                   @   s*   e Zd ZdZdZdddZedd ZdS )	PyramidIntegrationpyramidN
route_namec                 C   s&   d}||krt d||f || _d S )N)r   route_patternz7Invalid value for transaction_style: %s (must be in %s))
ValueErrortransaction_style)selfr   ZTRANSACTION_STYLE_VALUESr   r   r   __init__0   s    zPyramidIntegration.__init__c                     s@   ddl m}  | j  fdd}|| _| jfdd}|| _d S )Nr   )Routerc              	      s   t j}|t}|d kr* | |f||S | }|tt|| W 5 Q R X z | |f||W S  t	k
r   t
 }t| t|  Y nX d S r   )r   currentget_integrationr   Zconfigure_scopeZadd_event_processor_make_event_processorweakrefref	Exceptionsysexc_info_capture_exceptionr	   )r   r   argskwargshubintegrationZscoper#   )old_handle_requestr   r   sentry_patched_handle_requestA   s    

zDPyramidIntegration.setup_once.<locals>.sentry_patched_handle_requestc                    s<   t j}|t}|d kr$ ||S t fdd||S )Nc                     s    f| |S r   r   )akw)old_wsgi_callr   r   r   <lambda>_       zQPyramidIntegration.setup_once.<locals>.sentry_patched_wsgi_call.<locals>.<lambda>)r   r   r   r   r   )r   environZstart_responser'   r(   )r-   r   r   sentry_patched_wsgi_callX   s    
 z?PyramidIntegration.setup_once.<locals>.sentry_patched_wsgi_call)Zpyramid.routerr   Zhandle_request__call__)r   r*   r2   r   )r)   r-   r   
setup_once:   s    zPyramidIntegration.setup_once)r   )__name__
__module____qualname__
identifierr   r   staticmethodr4   r   r   r   r   r   +   s
   

r   c                 K   sd   | d d kst | d trd S tj}|td kr6d S t| |jjdddd\}}|j	||d d S )Nr   r   F)typeZhandled)Zclient_optionsZ	mechanism)hint)

issubclassr   r   r   r   r   r   ZclientoptionsZcapture_event)r#   r&   r'   eventr;   r   r   r   r$   f   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   s   | j jS r   )r   Zpath_urlr1   r   r   r   urlw   s    zPyramidRequestExtractor.urlc                 C   s   | j jS r   )r   r0   r1   r   r   r   envz   s    zPyramidRequestExtractor.envc                 C   s   | j jS r   )r   cookiesr1   r   r   r   rB   ~   s    zPyramidRequestExtractor.cookiesc                 C   s   | j jS r   )r   textr1   r   r   r   raw_data   s    z PyramidRequestExtractor.raw_datac                 C   s   dd | j j D S )Nc                 S   s"   i | ]\}}t |d ds||qS filenameNgetattr.0keyvaluer   r   r   
<dictcomp>   s    z0PyramidRequestExtractor.form.<locals>.<dictcomp>r   ZPOSTitemsr1   r   r   r   form   s    
zPyramidRequestExtractor.formc                 C   s   dd | j j D S )Nc                 S   s"   i | ]\}}t |d dr||qS rE   rG   rI   r   r   r   rM      s    z1PyramidRequestExtractor.files.<locals>.<dictcomp>rN   r1   r   r   r   files   s    
zPyramidRequestExtractor.filesc                 C   s4   |j }zt| jW S  tk
r.   Y dS X d S )Nr   )fileosfstatfilenost_sizer!   )r   ZpostdatarR   r   r   r   size_of_file   s
    z$PyramidRequestExtractor.size_of_fileN)
r5   r6   r7   r@   rA   rB   rD   rP   rQ   rW   r   r   r   r   r?   v   s   r?   c                    s    fdd}|S )Nc              	      s    }|d kr| S z2 j dkr,|jj| d< n j dkrB|jj| d< W n tk
rX   Y nX t  t||  W 5 Q R X t rt  | 	di }t
||d< W 5 Q R X | S )Nr   Ztransactionr   userid)r   Zmatched_routenamepatternr!   r   r?   Zextract_into_eventr   
setdefaultr   )r>   r;   r   Z	user_infor(   weak_requestr   r   event_processor   s"    

z._make_event_processor.<locals>.event_processorr   )r^   r(   r_   r   r]   r   r      s    r   )'
__future__r   rS   r"   r   Zpyramid.httpexceptionsr   Zpyramid.requestr   Zsentry_sdk.hubr   r   Zsentry_sdk.utilsr   r   Zsentry_sdk._compatr	   Zsentry_sdk.integrationsr
   Z$sentry_sdk.integrations._wsgi_commonr   Zsentry_sdk.integrations.wsgir   ZResponseZAnyZ_ScopedResponseCallableDictOptionalZRequestCookiesZcgi_FieldStorageZExcInforH   r   Zpyramid.securityr   r$   r?   r   r   r   r   r   <module>   s$   
;)