<!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
    \2                     @   s  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 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 d	d
 ZedZdadd ZG dd de Z!dd Z"G dd de#Z$G dd de Z%G dd de Z&G dd de	e$Z'e' Z(e)e( dS )    N)datetime)contextmanager)warn)with_metaclassScope)Client)exc_info_from_errorevent_from_exceptionlogger
ContextVarc                 C   s   | S N )xr   r   ?/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/hub.pyoverload    s    r   Zsentry_current_hubc                  C   s   t jj} | sdS | jd S )NFZsend_default_pii)Hubcurrentclientoptions)r   r   r   r   _should_send_default_pii(   s    r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )
_InitGuardc                 C   s
   || _ d S r   )_client)selfr   r   r   r   __init__1   s    z_InitGuard.__init__c                 C   s   | S r   r   r   r   r   r   	__enter__4   s    z_InitGuard.__enter__c                 C   s   | j }|d k	r|  d S r   )r   close)r   exc_type	exc_valuetbcr   r   r   __exit__7   s    z_InitGuard.__exit__N__name__
__module____qualname__r   r   r"   r   r   r   r   r   0   s   r   c                  O   s4   t | |}tj| t|}|dk	r0t|a|S )zsInitializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    N)r   r   r   bind_clientr   weakrefref_initial_client)argskwargsr   rvr   r   r   init=   s    

r.   c                   @   s$   e Zd Zedd Zedd ZdS )HubMetac                 C   s(   t d}|dkr$tt}t | |S )z(Returns the current instance of the hub.N)_localgetr   
GLOBAL_HUBsetr   r-   r   r   r   r   L   s
    

zHubMeta.currentc                 C   s   t S )z%Returns the main instance of the hub.)r2   r   r   r   r   mainV   s    zHubMeta.mainN)r$   r%   r&   propertyr   r5   r   r   r   r   r/   K   s   
	r/   c                   @   s   e Zd Zdd Zdd ZdS )_HubManagerc                 C   s   t j| _t| d S r   )r   r   _oldr0   r3   r   hubr   r   r   r   ]   s    z_HubManager.__init__c                 C   s   t | j d S r   )r0   r3   r8   )r   r   r   r    r   r   r   r"   a   s    z_HubManager.__exit__N)r$   r%   r&   r   r"   r   r   r   r   r7   \   s   r7   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )_ScopeManagerc                 C   s"   || _ t|j| _|jd | _d S N)_hublen_stack_original_len_layerr9   r   r   r   r   f   s    z_ScopeManager.__init__c                 C   s   | j d }|d k	st|S )N   )rB   AssertionError)r   scoper   r   r   r   k   s    
z_ScopeManager.__enter__c                 C   s   t | jj}|| jk r,td| j|  d S || jkrXtd|| j | jj| jd   | jj| jd  }| jj| jd d = |d | jd krtd|d | jd  n |d | jd krd}t| d S )Nz1Scope popped too soon. Popped %s scopes too many.zLeaked %s scopes: %srC   z2Wrong scope found. Meant to pop %s, but popped %s.r   zinit() called inside of pushed scope. This might be entirely legitimate but usually occurs when initializing the SDK inside a request handler or task/job function. Try to initialize the SDK as early as possible instead.)r?   r>   r@   rA   r   errorwarningrB   )r   r   r   r    Zcurrent_lenZlayerrG   r   r   r   r"   q   s2    

z_ScopeManager.__exit__Nr#   r   r   r   r   r;   e   s   r;   c                   @   s   e Zd ZdZdZd)ddZdd Zdd Zd	d
 Zdd Z	e
dd Zdd Zdd Zd*ddZd+ddZd,ddZdd Zd-ddZedd Zedd Zd.d dZeZd!d" Zed#d$ Zed%d$ Zd/d&d$Zd0d'd(ZdS )1r   zThe hub wraps the concurrency management of the SDK.  Each thread has
    its own hub but the hub might transfer with the flow of execution if
    context vars are available.

    If the hub is used with a with statement it's temporarily activated.
    Nc                 C   s^   t |tr0|}|jd \}}|d kr4t|}n|}|d krBt }||fg| _d | _g | _d S r<   )
isinstancer   r@   copyr   _last_event_id	_old_hubs)r   Zclient_or_hubrE   r:   r   Zother_scoper   r   r   r      s    
zHub.__init__c                 C   s   | j tj t|  | S r   )rK   appendr   r   r0   r3   r   r   r   r   r      s    
zHub.__enter__c                 C   s   | j  }t| d S r   )rK   popr0   r3   )r   r   r   r    oldr   r   r   r"      s    
zHub.__exit__c              
   C   s"   |  | W  5 Q R  S Q R X dS )z~Runs a callback in the context of the hub.  Alternatively the
        with statement can be used on the hub directly.
        Nr   r   callbackr   r   r   run   s    zHub.runc                 C   s   t |tr|}n|jdk	r"|j}ntd| jd d }|dk	rX|j|}|dk	rX|S t}|dk	rj| }|dk	r||k	r|j|dk	rd|f }tt	|dd t
| dS )a  Returns the integration for this hub by name or class.  If there
        is no client bound or the client does not have that integration
        then `None` is returned.

        If the return value is not `None` the hub is guaranteed to have a
        client attached.
        NzIntegration has no namer=   r   zIntegration %r attempted to run but it was only enabled on init() but not the client that was bound to the current flow.  Earlier versions of the SDK would consider these integrations enabled but this is no longer the case.   )
stacklevel)rH   strZ
identifier
ValueErrorr@   Zintegrationsr1   r*   r   Warningr   rG   )r   Zname_or_classZintegration_namer   r-   Zinitial_clientrG   r   r   r   get_integration   s2    	

zHub.get_integrationc                 C   s   | j d d S )z&Returns the current client on the hub.r=   r   r@   r   r   r   r   r      s    z
Hub.clientc                 C   s   | j S )zReturns the last event ID.)rJ   r   r   r   r   last_event_id   s    zHub.last_event_idc                 C   s    | j d }||d f| j d< dS )zBinds a new client to the hub.r=   rC   NrX   )r   newtopr   r   r   r'      s    
zHub.bind_clientc                 C   s:   | j d \}}|dk	r6||||}|dk	r2|| _|S dS )ak  Captures an event.  The return value is the ID of the event.

        The event is a dictionary following the Sentry v7/v8 protocol
        specification.  Optionally an event hint dict can be passed that
        is used by processors to extract additional information from it.
        Typically the event hint object would contain exception information.
        r=   N)r@   capture_eventrJ   )r   eventhintr   rE   r-   r   r   r   r\      s    	zHub.capture_eventc                 C   s*   | j dkrdS |dkrd}| ||dS )zyCaptures a message.  The message is just a string.  If no level
        is provided the default level is `info`.
        Ninfo)messagelevel)r   r\   )r   r`   ra   r   r   r   capture_message  s
    
zHub.capture_messagec                 C   sv   | j }|dkrdS |dkr$t }nt|}t||jd\}}z| j||dW S  tk
rp   | t  Y nX dS )zCaptures an exception.

        The argument passed can be `None` in which case the last exception
        will be reported, otherwise an exception object or an `exc_info`
        tuple.
        N)Zclient_options)r^   )	r   sysexc_infor	   r
   r   r\   	Exception_capture_internal_exception)r   rF   r   rd   r]   r^   r   r   r   capture_exception  s    
zHub.capture_exceptionc                 C   s   t jd|d dS )zNCapture an exception that is likely caused by a bug in the SDK
        itself.zInternal error in sentry_sdk)rd   N)r   rF   )r   rd   r   r   r   rf   1  s    zHub._capture_internal_exceptionc                 K   s   | j d \}}|dkr$td dS t|p,d}|| |sBdS t|pJd}|ddkrht |d< |ddkr~d|d< |}|jd dk	r|jd ||}|dk	r|j	
| ntd	| |jd
 }t|j	|kr|j	  qdS )zAdds a breadcrumb.  The breadcrumbs are a dictionary with the
        data as the sentry v7/v8 protocol expects.  `hint` is an optional
        value that can be used by `before_breadcrumb` to customize the
        breadcrumbs that are emitted.
        r=   Nz*Dropped breadcrumb because no client boundr   Z	timestamptypedefaultZbefore_breadcrumbz)before breadcrumb dropped breadcrumb (%s)max_breadcrumbs)r@   r   r_   dictupdater1   r   Zutcnowr   Z_breadcrumbsrL   r?   popleft)r   Zcrumbr^   r,   r   rE   Zoriginal_crumbrj   r   r   r   add_breadcrumb6  s,    


zHub.add_breadcrumbc                 C   s   d S r   r   r   r   r   r   
push_scope[  s    zHub.push_scopec                 C   s   d S r   r   rO   r   r   r   ro   `  s    c              	   C   sX   |dk	r(|   }|| W 5 Q R X dS | jd \}}|t|f}| j| t| S )zPushes a new layer on the scope stack. Returns a context manager
        that should be used to pop the scope again.  Alternatively a callback
        can be provided that is executed in the context of the scope.
        Nr=   )ro   r@   rI   rL   r;   )r   rP   rE   r   Z	new_layerr   r   r   ro   e  s    
c                 C   s   | j  }| j std|S )zaPops a scope layer from the stack. Try to use the context manager
        `push_scope()` instead.z"stack must have at least one layer)r@   rM   rD   r4   r   r   r   pop_scope_unsafex  s    
zHub.pop_scope_unsafec                 C   s   d S r   r   r   r   r   r   configure_scope  s    zHub.configure_scopec                 C   s   d S r   r   rO   r   r   r   rq     s    c                    sB   | j d \ |dk	r* dk	r&| dS t fdd}| S )zReconfigures the scope.r=   Nc                   3   s    d k	rV  nt  V  d S r   r   r   r   rE   r   r   inner  s    z"Hub.configure_scope.<locals>.inner)r@   r   )r   rP   rs   r   rr   r   rq     s    c                 C   s(   | j d \}}|dk	r$|j||dS dS )zAlias for self.client.flushr=   N)timeoutrP   )r@   flush)r   rt   rP   r   rE   r   r   r   ru     s    z	Hub.flush)NN)N)N)N)NN)N)N)NN)r$   r%   r&   __doc__r@   r   r   r"   rQ   rW   r6   r   rY   r'   r\   rb   rg   rf   rn   r   ro   rE   rp   rq   ru   r   r   r   r   r      s:   

)




%





r   )*rc   rI   r(   r   
contextlibr   warningsr   Zsentry_sdk._compatr   Zsentry_sdk.scoper   Zsentry_sdk.clientr   Zsentry_sdk.utilsr	   r
   r   r   ZUnionZAnyZOptionalZDictZTupleZListCallabler   ZContextManagerZIntegrationr0   r*   r   objectr   r.   rh   r/   r7   r;   r   r2   r3   r   r   r   r   <module>   s.   	.  