
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    „á§\  ã                   @   st   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
 g Zdd„ Zdd	„ Zd
d„ ZG dd„ deƒZdS )é    )Úcopy)Údeque©Úwraps)Úchain)ÚloggerÚcapture_internal_exceptionsÚobject_to_jsonc                 C   s   t  | ¡ d S ©N)Úglobal_event_processorsÚappend)Ú	processor© r   úA/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/scope.pyÚadd_global_event_processor   s    r   c                 C   s   t | | jd�S )N)ÚfsetÚdoc)ÚpropertyÚ__doc__©Úfnr   r   r   Ú_attr_setter   s    r   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )Nc                    s2   | j s
d S zd| _ ˆ | f|ž|ŽW ¢S d| _ X d S )NTF)Ú_should_capture)ÚselfÚargsÚkwargsr   r   r   Úwrapper   s    z!_disable_capture.<locals>.wrapperr   )r   r   r   r   r   Ú_disable_capture   s    
r   c                   @   s¼   e Zd ZdZdZdd„ Zedd„ ƒZedd„ ƒZed	d
„ ƒZ	e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d„ Zdd„ Zd(d d!„Zed)d"d#„ƒZd$d%„ Zd&d'„ ZdS )*ÚScopezaThe scope holds extra information that should be sent with all
    events that belong to it.
    )Ú_levelÚ_nameÚ_fingerprintÚ_transactionÚ_userÚ_tagsÚ	_contextsÚ_extrasÚ_breadcrumbsÚ_event_processorsÚ_error_processorsr   c                 C   s   g | _ g | _d | _|  ¡  d S r
   )r(   r)   r    Úclear©r   r   r   r   Ú__init__@   s    zScope.__init__c                 C   s
   || _ dS )z"When set this overrides the level.N)r   ©r   Úvaluer   r   r   ÚlevelG   s    zScope.levelc                 C   s
   || _ dS )z0When set this overrides the default fingerprint.N)r!   r-   r   r   r   ÚfingerprintL   s    zScope.fingerprintc                 C   s
   || _ dS )z;When set this forces a specific transaction name to be set.N)r"   r-   r   r   r   ÚtransactionQ   s    zScope.transactionc                 C   s
   || _ dS )z/When set a specific user is bound to the scope.N)r#   r-   r   r   r   ÚuserV   s    z
Scope.userc                 C   s   || j |< dS )z)Sets a tag for a key to a specific value.N)r$   ©r   Úkeyr.   r   r   r   Úset_tag[   s    zScope.set_tagc                 C   s   | j  |d¡ dS )zRemoves a specific tag.N)r$   Úpop©r   r4   r   r   r   Ú
remove_tag_   s    zScope.remove_tagc                 C   s   || j |< dS )z5Binds a context at a certain key to a specific value.N)r%   r3   r   r   r   Úset_contextc   s    zScope.set_contextc                 C   s   | j  |d¡ dS )zRemoves a context.N)r%   r6   r7   r   r   r   Úremove_contextg   s    zScope.remove_contextc                 C   s   || j |< dS )z&Sets an extra key to a specific value.N)r&   r3   r   r   r   Ú	set_extrak   s    zScope.set_extrac                 C   s   | j  |d¡ dS )zRemoves a specific extra key.N)r&   r6   r7   r   r   r   Úremove_extrao   s    zScope.remove_extrac                 C   s<   d| _ d| _d| _d| _i | _i | _i | _|  ¡  d| _dS )zClears the entire scope.NT)	r   r!   r"   r#   r$   r%   r&   Úclear_breadcrumbsr   r+   r   r   r   r*   s   s    zScope.clearc                 C   s   t ƒ | _dS )zClears breadcrumb buffer.N)r   r'   r+   r   r   r   r=   ‚   s    zScope.clear_breadcrumbsc                 C   s   | j  |¡ dS )zq"Register a scope local event processor on the scope.

        This function behaves like `before_send.`
        N)r(   r   )r   Úfuncr   r   r   Úadd_event_processor‡   s    zScope.add_event_processorNc                    s*   ˆ dk	r|‰‡ ‡fdd„}| j  |¡ dS )zÒ"Register a scope local error processor on the scope.

        The error processor works similar to an event processor but is
        invoked with the original exception info triple as second argument.
        Nc                    s>   zt |d ˆ ƒ}W n tk
r*   d}Y nX |r:ˆ| |ƒS | S )Né   F)Ú
isinstanceÚ	Exception)ÚeventÚexc_infoZis_inst©ÚclsZ	real_funcr   r   r>   ™   s    

z'Scope.add_error_processor.<locals>.func)r)   r   )r   r>   rF   r   rE   r   Úadd_error_processor�   s    	zScope.add_error_processorc              
   C   s”  dd„ }| j dk	r| j |d< | dg ¡ | j¡ | d¡dkrR| jdk	rR| j|d< | d¡dkrt| jdk	rt| j|d< | d¡dkr–| jdk	r–| j|d< | jr´| d	i ¡ 	t
| jƒ¡ | jrÎ| d
i ¡ 	| j¡ | jrè| di ¡ 	| j¡ |dk	rú| d¡nd}|dk	�r>| jD ].}|||ƒ}|dk�r6|||dƒ  S |}�qtt| jƒD ]D}|}tƒ � |||ƒ}W 5 Q R X |dk�rˆ|||dƒ  S |}�qJ|S )zBApplies the information contained on the scope to the given event.c                 S   s   t  d||| ¡ d S )Nz%s (%s) dropped event (%s))r   Úinfo)rC   ÚcauseÚtyr   r   r   Ú_drop©   s    z#Scope.apply_to_event.<locals>._dropNr/   Zbreadcrumbsr2   r1   r0   ÚextraZtagsZcontextsrD   zerror processorzevent processor)r   Ú
setdefaultÚextendr'   Úgetr#   r"   r!   r&   Úupdater	   r$   r%   r)   r   r   r(   r   )r   rC   ZhintrK   rD   r   Z	new_eventr   r   r   Úapply_to_event¤   s>    









zScope.apply_to_eventc                 C   sˆ   t  | j¡}| j|_| j|_| j|_| j|_| j|_t| j	ƒ|_	t| j
ƒ|_
t| jƒ|_t| jƒ|_t| jƒ|_t| jƒ|_| j|_|S r
   )ÚobjectÚ__new__Ú	__class__r   r    r!   r"   r#   Údictr$   r%   r&   r   r'   Úlistr(   r)   r   )r   Úrvr   r   r   Ú__copy__Ö   s    zScope.__copy__c                 C   s   d| j jtt| ƒƒ| jf S )Nz<%s id=%s name=%s>)rT   Ú__name__ÚhexÚidr    r+   r   r   r   Ú__repr__ì   s
    
ýzScope.__repr__)N)N)rY   Ú
__module__Ú__qualname__r   Ú	__slots__r,   r   r/   r0   r1   r2   r5   r8   r9   r:   r;   r<   r*   r=   r?   rG   r   rQ   rX   r\   r   r   r   r   r   ,   s2   




1r   N)r   Úcollectionsr   Ú	functoolsr   Ú	itertoolsr   Zsentry_sdk.utilsr   r   r	   ZAnyÚCallableÚDictÚOptionalZDequeZListr   r   r   r   rR   r   r   r   r   r   Ú<module>   s   