
    j                    
   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZ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 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mZm Z m!Z! 	 d d	l"m#Z# n# e$$ r dZ#Y nw xY wd d
l%m&Z& d dl'Z'd dl(m)Z) d dl*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2 e&r\d dl3m4Z4m5Z5 d dl%m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dl*mIZImJZJmKZKmLZLmMZMmNZNmOZO  e?d          ZP eCd          ZQ eddd          ZR ejS        d          ZTdaU ejV        dd          ZWdeXfdZYed	d            ZZ e	j[        d          Z\ e]d          Z^ e]d           Z_d!Z`	 dd"d
d(Zad)d$debfd*Zcdd,Zddd-Zed.d/deffd0Zg G d1 d2          Zh eh            Zidd4Zjdd7Zkd#d8delfd9Zmd#d8deffd:Zn e]d;          Zod#efdd8fd<Zp	 d	 	 	 dd?Zq G d@ dAer          Zs G dB dC          Zt G dD dE          ZuddHZvddIZwdJdKdeXfdLZxddPZy	 	 	 ddQefdRezdSdTdUdVdWd+ddXfdYZ{	 d	 	 	 	 	 	 	 dd\Z|d#d$deffd]Z}d#d$deffd^Z~	 	 	 	 	 	 dd`Z	 	 	 	 	 ddJdKdZdTdbeXdceXd[dTdddeddffdgZ	 	 	 ddbeXdceXd[dTddffdhZdieddVfdjZdidkdeffdlZ	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddvZ eedw          ZerddyZnddzZ	 	 	 	 	 	 	 	 ddmdGdidkdMdNdndodpdodqezdrezdsd+dtdud{d|d}d~ddfdZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZd#efdeffdZddZddZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 	 	 ddZd dZ	 	 	 	 	 	 	 	 d!dZ	 	 d"	 	 	 	 	 	 	 d#dZdd+dddeXfdZd_d+deXfdZd_d+dd+deXfdZdefdezdeffdZd#efddTfdZ	 dd#efdSdTddfdZdefddfdZdeXfdZdedefdZd$dZ e            \  ZZVdZd%dZd%dZ eVd          Z G d de          Z G d dej                  Zdefdd+fdZdefdd+fdZ edg d          Z	 	 	 d&defdeXdeXdeXddf
dZ edg d          Zd'defdeXddfdÄZdd$dsefdeXfdńZ	 	 d(defdddeXdeXfdɄZdddefdeXfd̄Zd)d΄ZdefdeffdτZdefdeffdЄZd*d҄ZdefddfdԄZ	 d	 	 	 	 	 	 	 d+d؄Zd,dۄZe&r$eF	 	 	 	 	 	 d-d            ZeF	 	 	 	 d.d            Zef	 	 	 	 	 d/dZe)rdezfdZndezfdZdelfdZ	 d dlmZ d dlmZ n# e$$ r d0dZdefdeXfdZY nw xY wdeXfdZ	 d	 	 	 d1dZdd$d#d$deXfdZe&r eCd          Zd2dZd)d$deffdZdddeXfdZ	 	 	 	 d3d ZdddeXfdZ	 	 	 	 d4dZȐd5dZɐd6dZdS (7      N)
namedtuple)contextmanager)datetimetimezone)Decimal)partialpartialmethodwraps)Real)parse_qsunquote	urlencodeurlsplit
urlunsplit)BaseExceptionGroup)TYPE_CHECKING)PY37)SENSITIVE_DATA_SUBSTITUTE	AnnotatedAnnotatedValue)DEFAULT_ADD_FULL_STACKDEFAULT_MAX_STACK_FRAMESDEFAULT_MAX_VALUE_LENGTHEndpointType)	FrameTypeTracebackType)AnyCallableContextManagerDict	GeneratorIteratorListNoReturnOptional	ParamSpecSetTupleTypeTypeVarUnioncastoverload)Hub)AttributeValueSerializedAttributeValueEventExcInfoHintLogMetricPRi     zsentry_sdk.errorsis_sentry_internal_taskFdefaultreturnc                  4    t                                           S N)_is_sentry_internal_taskget     [/DATA/AppData/hermes/projects/honcho/.venv/lib/python3.11/site-packages/sentry_sdk/utils.pyis_internal_taskrD   \   s    #'')))rB   Generator[None, None, None]c               #      K   t                               d          } 	 dV  t                               |            dS # t                               |            w xY w)z2Context manager to mark a task as Sentry internal.TN)r?   setreset)tokens    rC   mark_sentry_task_internalrJ   `   s^       %((..E. &&u----- &&u----s	   > Az^[a-zA-Z0-9/+=]*$)falsefnnooff0)truetyyeson1i  )strictvaluer   rW   Optional[bool]bool | Nonec                    | !t          |                                           nd}|t          v rdS |t          v rdS |rdnt	          |           S )zCasts an ENV variable value to boolean using the constants defined above.
    In strict mode, it may return None if the value doesn't match any of the predefined values.
    NFT)strlowerFALSY_ENV_VALUESTRUTHY_ENV_VALUESbool)rX   rW   
normalizeds      rC   env_to_boolrb   y   s\     (-'8U!!###dJ%%%u&&&t*44tE{{*rB   datac                 V    t          j        | dd                              d          S )zCSerialize data into a compact JSON representation encoded as UTF-8.F),:)	allow_nan
separatorsutf-8)jsondumpsencode)rc   s    rC   
json_dumpsrm      s'    :de
CCCJJ7SSSrB   Optional[str]c                     	 t          t          j        j        d          5 } d }t          j        dk    st          j        dk    r-t          j                    }|xj        t          j	        z  c_        t          j
        g d|t          j        | |                                           d                                                             d          }d d d            n# 1 swxY w Y   n# t          t           t"          f$ r Y d S w xY w|S )Nzw+win32cygwin)gitz	rev-parseHEAD)startupinfostdoutstderrstdinr   ri   )openospathdevnullsysplatform
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWPopenPIPEcommunicatestripdecodeOSErrorIOErrorFileNotFoundError)nullrt   revisions      rC   get_git_revisionr      s?   "'/4(( 	DK|w&&#,(*B*B(466##z'FF##  000 +%?   q"  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	& W/0   tt Os5   C+ B2CC+ C##C+ &C#'C+ +DDc                      t           j                            d          } | r| S t                      } | r| S dD ]'}t           j                            |          } | r| c S (dS )zTry to guess a default release.SENTRY_RELEASE)HEROKU_BUILD_COMMITHEROKU_SLUG_COMMITSOURCE_VERSION!CODEBUILD_RESOLVED_SOURCE_VERSIONCIRCLE_SHA1GAE_DEPLOYMENT_ID
K_REVISIONN)ry   environr@   r   )releasevars     rC   get_default_releaser      s|    jnn-..G   G    *..%% 	NNN	4rB   installed_integrationsz	List[str]c                 N    g d}|D ]}|| v rd                     |          c S dS )zAReturn the SDK name including the name of the used web framework.)djangoflaskfastapibottlefalconquartsanic	starlettelitestarstarlitechalice
serverlesspyramidtornadoaiohttp
aws_lambdagcpbeamasgiwsgizsentry.python.{}zsentry.python)format)r   framework_integrationsintegrations      rC   get_sdk_namer      sW    
  . . : :000%,,[99999 1 ?rB   c                   2    e Zd ZdZddZddddd	d
defdZdS )CaptureInternalExceptionrA   r<   ContextManager[Any]c                     | S r>   rA   selfs    rC   	__enter__z"CaptureInternalException.__enter__   s    rB   tyOptional[Type[BaseException]]rX   Optional[BaseException]tbOptional[TracebackType]c                 2    ||t          |||f           dS )NT)capture_internal_exception)r   r   rX   r   s       rC   __exit__z!CaptureInternalException.__exit__   s'     >e/&E2777trB   Nr<   r   )__name__
__module____qualname__	__slots__r   r`   r   rA   rB   rC   r   r      sg        I   	+	 )	 &		
 
	 	 	 	 	 	rB   r   r   c                      t           S r>   )_CAPTURE_INTERNAL_EXCEPTIONrA   rB   rC   capture_internal_exceptionsr      s    &&rB   exc_infor2   c                     t          j                                                    rt                              d|            dS dS )z
    Capture an exception that is likely caused by a bug in the SDK
    itself.

    These exceptions do not end up in Sentry and are just logged instead.
    zInternal error in sentry_sdkr   N)
sentry_sdk
get_client	is_activeloggererrorr   s    rC   r   r      sK     ((** H3hGGGGGH HrB   r   c                 :    | t           z
                                  S r>   )epochtotal_secondsrX   s    rC   to_timestampr     s    EM((***rB   c                 j    |                      t          j                  }|                    d          S )zFormats a timestamp in RFC 3339 format.

    Any datetime objects with a non-UTC timezone are converted to UTC, so that all timestamps are formatted in UTC.
    z%Y-%m-%dT%H:%M:%S.%fZ)
astimezoner   utcstrftime)rX   utctimes     rC   format_timestampr     s0    
 x|,,G 3444rB   )+-c                    	 t          j        |           }n# t          t          f$ r d| v rdnd}|                     d          r| d d         dz   } | d         t
          v r|dz  }| d d	         | d
d          z   } n| d         t
          v r|dz  }t          j        | |          }Y nw xY w|                    t          j	                  S )N.z%Y-%m-%dT%H:%M:%S.%fz%Y-%m-%dT%H:%M:%SZz+0000iz%z)
r   fromisoformatAttributeError
ValueErrorendswithISO_TZ_SEPARATORSstrptimer   r   r   )rX   resulttimestamp_formats      rC   datetime_from_isoformatr     s    <'..J' < < < '*Ull""8K 	 >># 	)#2#J(E9)))$#2#Jrss+EE2Y+++$"5*:;;< X\***s    BB('B(Optional[ExcInfo]Dict[str, Optional[ExcInfo]]c                 h    | t          j                    } nt          |           } | d         d} d| iS )z+Creates a hint with the exc info filled in.Nr   r   )r|   r   exc_info_from_errorr   s    rC   event_hint_with_exc_infor   0  s>     <>>&x00{!!rB   c                       e Zd ZdZdS )BadDsnzRaised on invalid DSNs.Nr   r   r   __doc__rA   rB   rC   r   r   =  s        !!!!rB   r   c                   z    e Zd ZdZ ej        d          Z	 d	 	 	 	 	 dd	Zede	fd
            Z
dddZde	fdZdS )DsnzRepresents a DSN.z	^o(\d+)\.NrX   Union[Dsn, str]org_idrn   r<   c                    t          |t                    rt          |j                  | _        d S t	          t          |                    }|j        dvrt          d|j        z            |j        | _        |j        t          d          |j        | _	        ||| _
        nBt          j                            | j	                  }|r|                    d          nd | _
        |j        | j        dk    rdpd| _        n|j        | _        |j        st          d          |j        | _        |j        | _        |j                            d	d          }	 t          t+          |                                                    | _        n6# t0          t2          f$ r" t          d
|j        pddd          z            w xY wd	                    |          d	z   | _        d S )N)httphttpszUnsupported scheme %rzMissing hostnamer8   r     P   zMissing public key/zInvalid project in DSN (%r) )
isinstancer   dict__dict__r   r\   schemer   hostnamehostr   ORG_ID_REGEXmatchgroupportusername
public_keypassword
secret_keyrz   rsplitintpop
project_idr   	TypeErrorjoin)r   rX   r   partsorg_id_matchrz   s         rC   __init__zDsn.__init__F  s    eS!! 	 00DMFU$$<00005<?@@@l>!+,,,N	+1DKK+11$)<<L3?I,,,Q///TDK:![G3;ArDII
DI~ 	/-.....z  a((	Q!#dhhjj//22DOOI& 	Q 	Q 	Q6%*:JABB9OOPPP	Q HHTNNS(			s   3F 3G c                 L    | j         }| j        | j        fdvr|d| j        }|S )zThe netloc part of a DSN.))r   r  )r   r   rf   )r	  r  r  r   rvs     rC   netlocz
Dsn.netlocq  s7     YK#+IIIBB		*B	rB   clientOptional[Any]Authc           	      j    t          | j        | j        | j        | j        | j        | j        |          S )z*Returns the auth info object for this dsn.)r  r	  rz   r  r  r  r  )r!  r  r  rz   r  r  r  )r   r  s     rC   to_authzDsn.to_authy  s:    ;
 
 
 	
rB   c                 v    | j         d| j        | j        r
d| j        z   pdd| j        | j        | j        S )N://@r  )r  r  r  r  rz   r  r   s    rC   __str__zDsn.__str__  sM    KKKOOO5do 5;;;KKIIOO
 	
rB   r>   )rX   r   r   rn   r<   N)r  r   r<   r!  )r   r   r   r   recompiler
  r  propertyr\   r  r#  r'  rA   rB   rC   r   r   A  s        2:l++L CG))&))0?))	)) )) )) ))V     X

 

 

 

 


 
 
 
 
 
 
rB   r   c                   r    e Zd ZdZ	 	 	 	 ddedededed	d
dedddeddfdZej        fdddefdZ	defdZ
dS )r!  z,Helper object that represents the auth info.N   r  r  r	  r  r  r  rn   versionr  r   rz   r<   c	                 v    || _         || _        || _        || _        || _        || _        || _        || _        d S r>   )r  r	  rz   r  r  r  r-  r  )	r   r  r	  r  r  r  r-  r  rz   s	            rC   r  zAuth.__init__  s@     		$$$rB   typer   c           	      T    | j         d| j        | j        d| j        d|j        d	S )z'Returns the API url for storing events.r%  zapi/r  )r  r	  rz   r  rX   )r   r/  s     rC   get_api_urlzAuth.get_api_url  s9     KKKIIIIIOOOJJJ
 	
rB   c                     d| j         fd| j        fg}| j        |                    d| j        f           | j        |                    d| j        f           dd                    d |D                       z   S )	z!Returns the auth header a string.
sentry_keysentry_versionNsentry_clientsentry_secretzSentry z, c              3   *   K   | ]\  }}|d |V  dS )=NrA   ).0keyrX   s      rC   	<genexpr>z!Auth.to_header.<locals>.<genexpr>  s1      $Q$Q
UUU%;$Q$Q$Q$Q$Q$QrB   )r  r-  r  appendr  r  r  s     rC   	to_headerzAuth.to_header  s    T_-0@$,/OP;"II4555?&II8999499$Q$Qb$Q$Q$QQQQQrB   )Nr,  Nr  )r   r   r   r   r\   r  r  r   ENVELOPEr1  r=  rA   rB   rC   r!  r!    s        66 '+"&   	
  $     
   ,  ,4
 

 

 
 
 
R3 R R R R R RrB   r!  clsOptional[type]c                 F    t          | dd           pt          | dd           S )Nr   r   getattr)r?  s    rC   get_type_namerD    s%    3--Oj$1O1OOrB   c                 4    t          | dd           }|dvr|S d S )Nr   )Nbuiltins__builtins__rB  )r?  mods     rC   get_type_modulerI    s)    
#|T
*
*C
444
4rB   framer   c                     	 | j         d         }|                    d          rdS n# t          t          f$ r Y nw xY wdD ]#}	 | j        |         r dS # t
          $ r Y  w xY wdS )Nr   zsentry_sdk.T)__traceback_hide____tracebackhide__F)	f_globals
startswithr   KeyErrorf_locals	Exception)rJ  rH  	flag_names      rC   should_hide_framerT    s    oj)>>-(( 	4	H%    ?  		~i( tt 	 	 	D	 5s   "' ;;A
A! A!r   r   Iterator[TracebackType]c              #   X   K   | }|#t          |j                  s|V  |j        }|!d S d S r>   )rT  tb_frametb_next)r   tb_s     rC   iter_stacksrZ    sA      %'C
/ .. 	IIIk /////rB   filenamelineno
max_lengthOptional[int]loaderr   moduleKTuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]c                    d}d }|Vt          |d          rF	 |                    |          }n# t          t          f$ r d }Y nw xY w||                                }|2	 t          j        |           }n# t          t          f$ r g d g fcY S w xY w|sg d g fS t          d||z
            }t          |dz   |z   t          |                    }		 fd|||         D             }
t          ||                             d                    }fd||dz   |	         D             }|
||fS # t          $ r g d g fcY S w xY w)	N   
get_sourcer   r8   c                 X    g | ]&}t          |                    d                     'S 
r]  strip_stringr   r9  liner]  s     rC   
<listcomp>z'get_lines_from_file.<locals>.<listcomp>  sB     
 
 
 F++
CCC
 
 
rB   rg  rh  c                 X    g | ]&}t          |                    d                     'S rf  ri  rk  s     rC   rm  z'get_lines_from_file.<locals>.<listcomp>  sB     
 
 
 F++
CCC
 
 
rB   )hasattrrd  ImportErrorr   
splitlines	linecachegetlinesr   maxminlenrj  r   
IndexError)r[  r\  r]  r_  r`  context_linessource
source_strlower_boundupper_boundpre_contextcontext_linepost_contexts     `          rC   get_lines_from_filer    s    MFgfl;;	*0*;*;F*C*CJJW% 	 	 	JJJ	!**,,F~	 '11FF! 	  	  	 tR<	   4|a-/00Kfqj=0#f++>>K
 
 
 
{612
 
 
 $F6N$8$8$@$@ZXXX
 
 
 

k9:
 
 
 L,66   4|s4   / AA!A6 6BBAD. .E ?E 	tb_linenomax_value_lengthc                    	 | j         j        }n# t          $ r d }Y nw xY w	 | j        d         }n# t          $ r g d g fcY S w xY w	 | j        d         }n# t          $ r d }Y nw xY w||r|dz
  }t	          |||||          S g d g fS )Nr   
__loader__r8   )r_  r`  )f_codeco_filenamerR  rN  r  )rJ  r  r  abs_pathr`  r_  r\  s          rC   get_source_contextr    s    
$)L$<   ,   4|.    Q"f.vf
 
 
 	
 tR<s-    0 AAA A#"A#c                 `    	 t          |           S # t          $ r t          |           cY S w xY wr>   )r\   rR  	safe_reprr   s    rC   safe_strr  +  sB     5zz       s    --c                 D    	 t          |           S # t          $ r Y dS w xY w)Nz<broken repr>)reprrR  r   s    rC   r  r  2  s5    E{{   s    
r  c                    |r| s|S 	 |                     d          r
|d d         }|                     dd          d         }|| k    rt          j                            |          S t
          j        |         j        }|s|S |                    |                    t          j	        d          d         d          d         
                    t          j	                  S # t          $ r |cY S w xY w)Nz.pycr   r   r8   r      )r   splitry   rz   basenamer|   modules__file__r  seplstriprR  )r`  r  base_modulebase_module_paths       rC   filename_for_moduler  9  s     6 V$$ 	%}Hll3**1-&  7##H---;{3< 	O~~.55bfa@@CQGGKRRF
 
 	
    s   AC  (C  AC   C/.C/Tinclude_local_variablesinclude_source_contextcustom_reprz&Optional[Callable[..., Optional[str]]]Dict[str, Any]c                    t          | dd           }|sd }d }n| j        j        }| j        j        }	 | j        d         }	n# t
          $ r d }	Y nw xY w|| j        }	 |rt          j        	                    |          nd }
n# t
          $ r d }
Y nw xY wt          |	|          pd |
|pd|	|d}|rt          | ||          \  |d<   |d<   |d<   |r)dd	lm}  |t          | j                  d
|          |d<   |S )Nr  r   z	<unknown>)r[  r  functionr`  r\  r}  r~  r  r   )	serializeT)is_varsr  vars)rC  r  r  co_namerN  rR  f_linenory   rz   abspathr  r  sentry_sdk.serializerr  r  rQ  )rJ  r  r  r  r  r  r  r  r  r`  os_abs_pathr  r  s                rC   serialize_framer  R  s    UHd++F (<+<',    N	3;Ebgooh///    (99AT+ B  
DV9.E
 E
A=2n-r./A  
333333Y  $K
 
 
6
 Is#   A   AA#B   BBc                     d}g }t          j                    }|>t          |          s&|                    t	          || ||                     |j        }|>|                                 d|iS )NT)r  r  r  frames)r|   	_getframerT  r<  r  f_backreverse)r  r  r  rM  r  rL   s         rC   current_stacktracer    s    
 F"}A
- ## 	MM,C+A%5	     H - NNfrB   	exc_valuec                 $    t          | dd           S )NerrnorB  )r  s    rC   	get_errnor    s    9gt,,,rB   r   c                 >   t          t          | dd          pt          | dd          pt          |                     }t          | dd           }t          |t                    r8t	          |          dk    r%|dd                    d |D                       z   z  }|S )Nmessager  detail	__notes__r   
c              3   D   K   | ]}t          |t                    |V  d S r>   )r  r\   )r9  notes     rC   r;  z$get_error_message.<locals>.<genexpr>  s1      #T#TTjs>S>S#TD#T#T#T#T#T#TrB   )r  rC  r  listrv  r  )r  r  notess      rC   get_error_messager    s    	9b)) 	9h++	I G I{D99E% U3u::>>4$))#T#TU#T#T#TTTTTNrB   exc_typeclient_optionsOptional[Dict[str, Any]]	mechanismexception_id	parent_idry  
full_stackOptional[list[dict[str, Any]]]c	                    i }	|r|                                 nddd|	d<   |||	d         d<   |t          |          }
nd}
|
D|	d                             di                               di                               d	|
           |||	d         d
<   |dk    }|s|||	d         d<   d|	d         d<   |rd|	d         vrd|	d         d<   t          duot	          |t                    }|rd|	d         d<   t          |           |	d<   t          |           |	d<   t          |          |	d<   |ddt          dn-|d         |d         |d         |	                    d          fdt          t          |          t          t          dz                       D             }t          |          t          k    rt          j        d          |	d<   n|r|s|}nt#          |||          }d|i|	d<   |	S )z
    Creates a dict that goes into the events `exception.values` list and is ingestible by Sentry.

    See the Exception Interface documentation for more details:
    https://develop.sentry.dev/sdk/event-payloads/exception/
    genericTr/  handledr  Nr  metar  numberry  r   r  chainedr/  is_exception_groupr`  rX   r  r  r  r  c           
      T    g | ]$\  }}t          |j        |j                   %S ))r  r  r  r  r  )r  rW  r  )r9  r   _r  r  r  r  s      rC   rm  z5single_exception_from_error_tuple.<locals>.<listcomp>  sT     & & & B 	Kl$;#9-#	
 	
 	
& & &rB   r8   r   
stacktracer  )copyr  
setdefaultr   r  rI  rD  r  r   r@   ziprZ  rangeMAX_STACK_FRAMESrv  r   removed_because_over_size_limitmerge_stack_frames)r  r  r   r  r  r  r  ry  r  exception_valuer  is_root_exceptionr  r  
new_framesr  r  r  r  s                  @@@@rC   !single_exception_from_error_tupler    s   " )+O%O	I$+O+O K  7C$^4)$$$//;;FFR	
 	

*Xu
%
%
%17$X.$) 9!64=$[1/8$V, 9V?;+GGG/8$V,+47 J%= =  B=A$%9: / 9 9OH+H55OF0;;OG"&!%3"01J"K!/0H!I)*<=$((77& & & & & & & R%0@10D*E*EFF& & &F 6{{%%% )7(V)
 )
 )
%% 
 ? 	PJJ+FJOOJ)1:(>%rB   __suppress_context__Iterator[ExcInfo]c              #     K   | \  }}}g }t                      }||t          |          |vr|||fV  |                    |           |                    t          |                     |j        r|j        }n|j        }|d S t          |          }|}t          |dd           }||t          |          |vd S d S d S d S d S d S )N__traceback__)	rG   idr<  addr  	__cause____context__r/  rC  )r   r  r  r   seen_exceptionsseen_exception_idscauses          rC   walk_exception_chainr    s     "*)R),  %9%777Ir))))
 ""9---""2i==111- .!+!-}E{{HI66B)  %9%77777 ! %%77 ! %%rB   c              #      K   | V  d S r>   rA   r   s    rC   r  r  >  s      rB   r  zOptional[list[BaseException]]r  zOptional[Set[int]]z Tuple[int, List[Dict[str, Any]]]c                    |
t                      }
|	g }	|t          |          |
v r|g fS |7|	                    |           |
                    t          |                     t	          | ||||||||	  	        }|g}|}|dz  }t          |d          o|j        }|rr|ot          |d          o|j        du}|rT|j        }t          t          |          |t          |dd          |||d||	|

  
        \  }}|                    |           nq|ot          |d          o|j        du}|rT|j        }t          t          |          |t          |dd          |||d||	|

  
        \  }}|                    |           |ot          |d	          }|rkt          |j                  D ]V\  }}t          t          |          |t          |dd          ||||d
|z  ||	|
          \  }}|                    |           W||fS )a.  
    Creates the list of exceptions.
    This can include chained exceptions and exceptions from an ExceptionGroup.

    See the Exception Interface documentation for more details:
    https://develop.sentry.dev/sdk/event-payloads/exception/

    Args:
        exception_id (int):

            Sequential counter for assigning ``mechanism.exception_id``
            to each processed exception. Is NOT the result of calling `id()` on the exception itself.

        parent_id (int):

            The ``mechanism.exception_id`` of the parent exception.

            Written into ``mechanism.parent_id`` in the event payload so Sentry can
            reconstruct the exception tree.

            Not to be confused with ``seen_exception_ids``, which tracks Python ``id()``
            values for cycle detection.
    N)	r  r  r   r  r  r  r  ry  r  r8   r  r  r  )
r  r  r   r  r  r  ry  r  r  r  r  
exceptionszexceptions[%s])r  r  r   r  r  r  r  ry  r  r  r  )rG   r  r<  r  r  ro  r  r  exceptions_from_errorr/  rC  extendr  	enumerater  )r  r  r   r  r  r  r  ry  r  r  r  parentr  should_supress_contextexception_has_causer  child_exceptionsexception_has_contentcontextr  idxes                         rC   r  r  B  s   J ! UUI2D!D!Db!!y)))r)}}---.%!
 
 
F JIAL 		122Uy7U   .0  0	;//0#4/ 	
  	0'E/De5/488-#)"% /#50 0 0,\+ .///  2	=112%T1 	
 ! 	0+G/Dg!7OT::-#)$% /#50 0 0,\+ ./// #Gwy,'G'G 0	 455 	0 	0FC/Da1ot44-#)#'#-% /#50 0 0,\+ .////*%%rB   List[Dict[str, Any]]c                 0   | \  }}}t           d uot          |t                     }|rt          |||||dd|          \  }}	n@g }	t          |           D ].\  }}}|	                    t          ||||||                     /|	                                 |	S )Nr   )r  r  r   r  r  r  r  r  )r  r  r   r  r  r  )r   r  r  r  r<  r  r  )
r   r  r  r  r  r  r   r  r  r  s
             rC   exceptions_from_error_tupler    s     'Hi+47 J%= =  /)!	
 	
 	
JJ 
';H'E'E 
	 
	#Hi1%'#1')  	 	 	 	 rB   c                 p    	 t          |           S # t          $ r t          |           dd         cY S w xY w)Nr8   r   )r\   UnicodeDecodeErrorr  r   s    rC   	to_stringr    sI    !5zz ! ! !E{{1R4    !s    !55eventr1   #Iterator[Annotated[Dict[str, Any]]]c              #     K   d| v r
| d         V  d| v r.| d                              d          pdD ]}d|v r
|d         V  d| v rC| d                              d          pdD ]'}t          |t                    rd|v r
|d         V  &d S d S )Nr  threadsvaluesrA   	exception)r@   r  r  )r  threadr  s      rC   iter_event_stacktracesr    s      uL!!!!EI&**844: 	+ 	+Fv%%\****e{+//99?R 	. 	.I)T** .|y/H/H---- 	. 	.rB   Iterator[Dict[str, Any]]c              #      K   t          |           D ]>}t          |t                    r	|j        pi }|                    d          pdD ]}|V  ?d S )Nr  rA   )r  r  r   rX   r@   )r  r  rJ  s      rC   iter_event_framesr    sv      ,U33  
j.11 	0#)/RJ^^H--3 	 	EKKKK		 rB   in_app_excludeOptional[List[str]]in_app_includeproject_rootc                     t          |           D ]F}t          |t                    r	|j        pi }t	          |                    d          |||           G| S )Nr  )r  r  r  )r  r  r   rX   set_in_app_in_framesr@   )r  r  r  r  r  s        rC   handle_in_appr    su     -U33 	
 	

j.11 	0#)/RJNN8$$))%		
 	
 	
 	
 	
 LrB   r  c                 P   | sd S | D ]}|                     d          }||                     d          }t          ||          rd|d<   Et          ||          rd|d<   [|                     d          }|st          |          rd|d<   t          ||          rd|d<   | S )Nin_appr`  TFr  )r@   _module_in_list_is_external_source_is_in_project_root)r  r  r  r  rJ  current_in_appr`  r  s           rC   r
  r
  )  s      t  8,,%8$$ 6>22 	"E(O 6>22 	#E(O 99Z((x(( 	#E(Ox66 	"E(O	 MrB   r   Union[BaseException, ExcInfo]c                    t          | t                    rt          |           dk    r| \  }}}nt          | t                    rTt	          | dd           }|t          |           }| }nNt          j                    \  }}}|| urd }| }t          |           }nt          dt          |           z            |||f}t          rt          t          |          }|S )N   r  z,Expected Exception object to report, got %s!)r  tuplerv  BaseExceptionrC  r/  r|   r   r   r   r,   r2   )r   r  r  r   r   s        rC   r   r   T  s    % WCJJ!OO"')RR	E=	)	) WUOT22>E{{HII&)lnn#Hi%%!	;; G$u++UVVV)R(H + **OrB   c                     d | D             fd|D             }|                     |            |r|                    dt                    nd}||t          |          |z
  d         }|S )zV
    Add the missing frames from full_stack to frames and return the merged list.
    c                 J    h | ] }|d          |d         |d         |d         f!S r  r~  r\  r  rA   )r9  rJ  s     rC   	<setcomp>z%merge_stack_frames.<locals>.<setcomp>x  sK         *.!(O*		
  rB   c                 T    g | ]$}|d          |d         |d         |d         fv"|%S r  rA   )r9  
stackframe	frame_idss     rC   rm  z&merge_stack_frames.<locals>.<listcomp>  s]     
 
 
z"~&x z"	
   	  rB   max_stack_framesN)r  r@   r   rv  )r  r  r  r  r  r  s        @rC   r  r  p  s        I
 
 
 
$
 
 
J f
 	-/GHHH 
 #J2B B D DE
rB   Tuple[Event, Dict[str, Any]]c                     t          |           } t          |           }|r?|                    dt                    r$t	          |d         |d                   d         }nd }ddt          | |||          id|fS )	Nadd_full_stackr  r  )r  r  r  r   r  )levelr  )r   r   r@   r   r  r  )r   r  r  hintr  s        rC   event_from_exceptionr$    s    
 #8,,H#H--D .,,-=?UVV '$23L$M+,>?
 
 
 


 
 5ni 	
 	
 	
 
rB   nameitemsc                 b    | dS |sdS |D ]#}|| k    s|                      |dz             r dS $dS )NFr   TrO  )r%  r&  items      rC   r  r    sX    |u u  4<<4??4#:66<44  5rB   c                 <    | dS t          j        d|           d u}|S )NFz [\\/](?:dist|site)-packages[\\/]r(  search)r  external_sources     rC   r  r    s1    u 		5x@@L  rB   c                 @    | |dS |                      |          rdS dS )NFTr(  )r  r  s     rC   r  r    s6     </u <(( t5rB   string	max_bytesc                 v    |                      d          d|dz
                               dd          }|dz   S )zd
    Truncate a UTF-8-encodable string to the last full codepoint so that it fits in max_bytes.
    ri   Nr  ignore)errors...)rl   r   )r/  r0  	truncateds      rC   _truncate_by_bytesr6    s@     g&&Q7>>wx>XXIurB   c                 x    	 t          |                     d                    S # t          t          f$ r Y d S w xY w)Nri   )rv  rl   UnicodeEncodeErrorr  r   s    rC   _get_size_in_bytesr9    sI    5<<(())) 23   tts   !$ 99zUnion[AnnotatedValue, str]c                     | s| S |t           }t          |           }t          |           }|||k    rt          | |          }n|||k    r| d |dz
           dz   }n| S t	          ||p|dd|dz
  |ggd          S )Nr  r4  z!limitx)rv  rem)rX   metadata)r   r9  rv  r6  r   )rX   r]  	byte_size	text_sizetruncated_values        rC   rj  rj    s      -
"5))IE

IZ!7!7,UJ??		9z#9#9 0*q. 01E9)	sJNJ?@
 
   rB   r-  zOptional[Tuple[int, ...]]c                    d}t          j        d|z   dz   t           j        t           j        z            }	 |                    |                                           d         }t          t          t          |	                    d          dd                             }n# t          t          t          f$ r Y dS w xY w|S )z
    Parses a version string into a tuple of integers.
    This uses the parsing loging from PEP 440:
    https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions
    a    # noqa: N806
        v?
        (?:
            (?:(?P<epoch>[0-9]+)!)?                           # epoch
            (?P<release>[0-9]+(?:\.[0-9]+)*)                  # release segment
            (?P<pre>                                          # pre-release
                [-_\.]?
                (?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
                [-_\.]?
                (?P<pre_n>[0-9]+)?
            )?
            (?P<post>                                         # post release
                (?:-(?P<post_n1>[0-9]+))
                |
                (?:
                    [-_\.]?
                    (?P<post_l>post|rev|r)
                    [-_\.]?
                    (?P<post_n2>[0-9]+)?
                )
            )?
            (?P<dev>                                          # dev release
                [-_\.]?
                (?P<dev_l>dev)
                [-_\.]?
                (?P<dev_n>[0-9]+)?
            )?
        )
        (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))?       # local version
    z^\s*z\s*$r   r   Nr  )r(  r)  VERBOSE
IGNORECASEr  	groupdictr  mapr  r  r  r   r   )r-  VERSION_PATTERNpatternr   release_tuples        rC   parse_versionrI    s    O> j/!G+

R]" G
--((2244Y?+0S'--:L:LRaR:P1Q1Q+R+Rz>2   tt s   A*B! !B<;B<c                     	 ddl } ddlm} t          d t	          j        d| j                  dd         D                       } |dd          r&t          j        d	k    r|d
k    s |dd          rdS dS n# t          $ r Y nw xY w	 ddl
}ddlm} t          |j                  }|t                              d           dS  |d          r|dk     rdS n# t          $ r Y nw xY wdS )z
    Returns whether gevent/eventlet have patched the stdlib in a way where thread locals are now more "correct" than contextvars.
    r   N)is_object_patchedc                 ,    g | ]}t          |          S rA   )r  )r9  parts     rC   rm  z*_is_contextvars_broken.<locals>.<listcomp>I  s    RRR4SYYRRRrB   z	a|b|rc|\.r  	threadinglocalr  r,  )   	   contextvars
ContextVarFT)is_monkey_patchedzYInternal error in Sentry SDK: Could not parse Greenlet version from greenlet.__version__.r   )r   rc  )geventgevent.monkeyrK  r  r(  r  __version__r|   version_inforp  greenleteventlet.patcherrU  rI  r   r   )rV  rK  version_tuplerZ  rU  greenlet_versions         rC   _is_contextvars_brokenr^  ?  sx   333333 RR28L&:L#M#Mbqb#QRRR
 
 ['22 	 !V++0H0H%%m\BB 1I u4	     666666()=>>#LLk   5X&& 	+;f+D+D4    5s*   A1A8 8
BB	:C C 
C&%C&rO  c                 &      G  fdd          }|S )Nc                   D    e Zd Zddeddddf fdZdddZdd	ZddZdS )1_make_threadlocal_contextvars.<locals>.ContextVarNr%  r;   r   r<   c                 `    || _         || _                     | _                     | _        d S r>   )_name_default_local_original_local)r   r%  r;   rO  s      rC   r  z:_make_threadlocal_contextvars.<locals>.ContextVar.__init__v  s2    DJ#DM%''DK#(577D   rB   c                 <    t          | j        d|p| j                  S )NrX   )rC  re  rd  )r   r;   s     rC   r@   z5_make_threadlocal_contextvars.<locals>.ContextVar.get|  s    4;1IDMJJJrB   rX   c                     t          t          j        d                    }|                                 }t	          | j        ||           || j        _        |S )N@   )r\   randomgetrandbitsr@   setattrrf  re  rX   )r   rX   rI   original_values       rC   rG   z5_make_threadlocal_contextvars.<locals>.ContextVar.set  sK    *2..//E!XXZZND(%@@@ %DKLrB   rI   c                 ^    t          | j        |          | j        _        | j        j        |= d S r>   )rC  rf  re  rX   r  )r   rI   s     rC   rH   z7_make_threadlocal_contextvars.<locals>.ContextVar.reset  s-     '(<e D DDK$-e444rB   r>   )r;   r   r<   r   )rX   r   r<   r   )rI   r   r<   N)r   r   r   r\   r  r@   rG   rH   rO  s   rC   rT  ra  s  s        	+ 	+ 	+u 	+ 	+ 	+ 	+ 	+ 	+ 	+	K 	K 	K 	K 	K	 	 	 		5 	5 	5 	5 	5 	5rB   rT  rA   )rO  rT  s   ` rC   _make_threadlocal_contextvarsrp  r  s=    5 5 5 5 5 5 5 5 5 50 rB   Tuple[bool, type]c                      t                      sFt          j        dk     r	 ddlm}  d| fS # t
          $ r Y nw xY w	 ddlm}  d| fS # t
          $ r Y nw xY wddlm} dt          |          fS )z
    Figure out the "right" contextvars installation to use. Returns a
    `contextvars.ContextVar`-like class with a limited API.

    See https://docs.sentry.io/platforms/python/contextvars/ for more information.
    rP  r   )rT  Tro  F)
r^  r|   rY  aiocontextvarsrT  rp  rS  rN  rO  rp  )rT  rO  s     rC   _get_contextvarsrt    s     "## 
 f$$555555Z''   222222Z''   
  /6666s   	* 
77	A 
AAz

With asyncio/ASGI applications, the Sentry SDK requires a functional
installation of `contextvars` to avoid leaking scope/context data across
requests.

Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information.
funcCallable[..., Any]c                    d}d\  }}t          | t                    r"t          | j        d          rd\  }}| j        } nCt	          | dd          pt	          | dd          }t          |t
                    rd\  }}|j        } t          | d          r| j        }nt          | d          r| j        }|?t          | d	          r't          | j        t                    r| j        d
z   |z   }||z   |z   }|S )zbReturn the qualified name of func. Works with regular function, lambda, partial and partialmethod.N)r  r  r   )zpartial(<function >)_partialmethod__partialmethod__)zpartialmethod(<function rx  r   r   r   )
r  r   ro  ru  rC  r	   r   r   r   r\   )ru  func_qualnameprefixsuffixpartial_methods        rC   qualname_from_functionr    s#   %)MNFF$   'WTY
%C%C '3y !'7>> 
'%tC
 C
 nm44 	'=NFF!&Dt^$$ &)	z	"	" & 4&& 	B:dos+K+K 	B Oc1MAM.7rB   c                      t          |           S r>   )r  )ru  s    rC   transaction_from_functionr    s    !$'''rB   disable_capture_eventc                       e Zd ZdZdS )ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nr   rA   rB   rC   r  r    s        HHDrB   r  c                   L    e Zd ZdZ	 	 ddededdddddf
d	Zdd
ZddZddZ	dS )TimeoutThreadzCreates a Thread which runs (sleeps) for a time duration equal to
    waiting_time and raises a custom ServerlessTimeout exception.
    Nwaiting_timeconfigured_timeoutisolation_scopezOptional[sentry_sdk.Scope]current_scoper<   c                     t           j                            |            || _        || _        || _        || _        t          j                    | _        d S r>   )	rN  Threadr  r  r  r  r  r1   _stop_event)r   r  r  r  r  s        rC   r  zTimeoutThread.__init__  sQ     	!!$'''("4.*$?,,rB   c                 8    | j                                          d S r>   )r  rG   r   s    rC   stopzTimeoutThread.stop  s    rB   r2   c                     t          j                    }t          j                    }t	          ||j        ddd          \  }}t          j        ||           |S )NrN  Fr  )r  r  )r#  )r|   r   r   r   r$  optionscapture_event)r   r   r  r  r#  s        rC   _capture_exceptionz TimeoutThread._capture_exception  sc    <>>&((*!>*u==
 
 
t
 	 T2222rB   c                    | j                             | j                   | j                                         rd S t	          | j                  }|| j        k     r|dz   }| j        | j        t          j	        
                    | j                  5  t          j	                            | j                  5  	 t          d                    |                    # t          $ r t          |                                   Y nw xY w	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          d                    |                    )Nr8   zZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)r  waitr  is_setr  r  r  r  r   scopeuse_isolation_scope	use_scoper  r   rR  reraiser  )r   integer_configured_timeouts     rC   runzTimeoutThread.run  s   d/000""$$ 	F%()@%A%A" &(???)Ca)G& +0B0N!55d6JKK 	< 	<%//0BCC < <<6x :   
 % < < <!8!8!:!:;;;;<;< < < < < < < < < < < < < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 'hoo* 
 
 	
sT   %D)6D8"C%D?DDDD)D	D)D	D))D-0D-NN)r<   N)r<   r2   )
r   r   r   r   floatr  r  r  r  r  rA   rB   rC   r  r    s          9=6:- --  - 6	-
 4- 
- - - -       
 
 
 
 
 
rB   r  originalc                    d}	 |                      d          }t          j        |          }|                    d          }nF# t          $ r9}t
                              d                    |           |           Y d}~nd}~ww xY w|S )zO
    Convert a string to base64, via UTF-8. Returns None on invalid input.
    NUTF-8z"Unable to encode {orig} to base64:)orig)rl   base64	b64encoder   rR  r   warningr   )r  base64_string
utf8_bytesbase64_byteserrs        rC   	to_base64r  1  s     MX__W--
'
33$++G44 X X X;BBBQQSVWWWWWWWWX s   >A 
B/BBr  c                 R   d}	 t                               |           }|sJ |                     d          }t          j        |          }|                    d          }nF# t          $ r9}t                              d	                    |           |           Y d}~nd}~ww xY w|S )zQ
    Convert a string from base64, via UTF-8. Returns None on invalid input.
    Nr  z#Unable to decode {b64} from base64:)b64)
BASE64_ALPHABETr  rl   r  	b64decoder   rR  r   r  r   )r  utf8_stringonly_valid_charsr  r  r  s         rC   from_base64r  A  s     K

*00??$++G44%l33
 ''00 
 
 
188]8KKS	
 	
 	
 	
 	
 	
 	
 	


 s   AA! !
B$+/BB$
Components)r  r  rz   queryfragmenturlremove_authorityremove_query_valuesr  zUnion[str, Components]c                    t          |           }t          |j        d          }|rP|j                            d          }t          |          dk    rt          dt          d|d         }n|j        }n|j        }|r't          t          d |D                                 }n|j        }t          |j
        |||j        |j                  }	|r|	S t          |	          S )	zL
    Removes the authority and query parameter values from a given URL.
    T)keep_blank_valuesr&  r8   rf   r   c                     i | ]
}|t           S rA   )r   )r9  r:  s     rC   
<dictcomp>z sanitize_url.<locals>.<dictcomp>v  s    NNN#s5NNNrB   r  r  r  rz   r  )r   r   r  r  r  rv  r   r   r   r  r  rz   r  r   )
r  r  r  r  
parsed_urlquery_paramsnetloc_partsr  query_string
componentss
             rC   sanitize_urlr  Y  s    #JJ,EEEL  #!(..s33|q  ))))))R  FF  &FF"  (NNNNNOO
 
 "' _$  J  &*%%%rB   	ParsedUrlr  r  r  sanitizec           	          t          | d|d          }t          t          |j        |j        d|j        d                    }t          ||j        |j                  S )z
    Splits a URL into a url (including path), query and fragment. If sanitize is True, the query
    parameters will be sanitized to remove sensitive data. The autority (username and password)
    in the URL will always be removed.
    T)r  r  r  r  r  r  )	r  r   r  r  r  rz   r  r  r  )r  r  r  base_urls       rC   	parse_urlr    s     d  J $$	
 	
 	
 H $   rB   ratec           	      |   t          | t          t          f          rt          j        |           r?t
                              d                    || t          |                                dS t          |           } | dk     s| dk    r1t
                              d                    ||                      dS dS )	z
    Checks the given sample rate to make sure it is valid type and value (a
    boolean or a number between 0 and 1, inclusive).
    z|{source} Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got {rate} of type {type}.)ry  r  r/  Fr   r8   zW{source} Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)ry  r  T)
r  r   r   mathisnanr   r  r   r/  r  )r  ry  s     rC   is_valid_sample_rater    s     dT7O,, 
40@0@  K  R  RDtDzz R  	
 	
 	

 u ;;Daxx4!88ellD m  	
 	
 	

 u4rB   r)  
regex_listsubstring_matchingc                 r    |dS |D ]/}|s|d         dk    r|dz  }t          j        ||           }|r dS 0dS )NFr   $Tr+  )r)  r  r  item_matchermatcheds        rC   match_regex_listr    sk    
 u"  ! 	 l2&6#&=&=CL)L$// 	44	 5rB   r  zsentry_sdk.client.BaseClientc                 ^    | duo)| j         duo | j         j        duo| j         j        j        |v S )zB
    Determines whether the given URL matches the Sentry DSN.
    N)	transport
parsed_dsnr  )r  r  s     rC   is_sentry_urlr    sL    
 	d 	6D(	6't3	6 '.#5	rB   Iterator[Tuple[str, str]]c               #     K   	 ddl m}  t                      }|                                 D ]Y}|j                            dd           }|:t          |          }|j        $||vr ||j        fV  |                    |           Zd S # t          $ rC 	 dd l	}n# t          $ r Y Y d S w xY w|j
        D ]}t          |j                  |j        fV   Y d S w xY w)Nr   )r=  Name)	importlibr=  rG   distributionsr@   _normalize_module_namer-  r  rp  pkg_resourcesworking_setr:  )r=  yieldeddistr%  normalized_namer  infos          rC   _generate_installed_modulesr    sQ     A&&&&&&%%**,, 
	1 
	1D=$$VT22D
 "8">"><+w0N0N)4<7777KK000
	1 
	1  A A A	      	 	 	FFF	 "- 	A 	AD(22DL@@@@@	A 	A 	AAs6   BB 
CBC
B'"C&B''*CCc                 *    |                                  S r>   )r]   r%  s    rC   r  r     s    ::<<rB   c                 .    t          j        dd|           S )Nz[-_.]+r   )r(  subr  s    rC   1_replace_hyphens_dots_and_underscores_with_dashesr    s    6)S$'''rB   Dict[str, str]c                  T    t           t          t                                a t           S r>   )_installed_modulesr  r  rA   rB   rC   _get_installed_modulesr  	  s#    !!"="?"?@@rB   packagec                     t          t          |                     }d t                                                      D             }|                    |          }|d S t          |          S )Nc                 4    i | ]\  }}t          |          |S rA   )r  )r9  r`  vs      rC   r  z#package_version.<locals>.<dictcomp>  s6       FA 	:&AA1  rB   )r  r  r  r&  r@   rI  )r  normalized_packageinstalled_packagesr-  s       rC   package_versionr    s|    /9'BB  /117799   !$$%788Gt!!!rB   tpr   r$   c                 J    |J |j         |ur|                    |          |r>   )r  with_traceback)r  rX   r   s      rC   r  r     s7    
 "$$""2&&&
KrB   _a_kc                      dS )z.No-op function for ensure_integration_enabled.NrA   )r  r  s     rC   _no_opr  +  s    DrB   r   )type[sentry_sdk.integrations.Integration]original_functionCallable[P, R]*Callable[[Callable[P, R]], Callable[P, R]]c                     d S r>   rA   )r   r  s     rC   ensure_integration_enabledr  2  s	     8;srB   0Callable[[Callable[P, None]], Callable[P, None]]c                     d S r>   rA   )r   s    rC   r  r  8  s
     >ASrB   (Union[Callable[P, R], Callable[P, None]]c                 t     t           r't          t          t          t          f                   d fd}|S )a  
    Ensures a given integration is enabled prior to calling a Sentry-patched function.

    The function takes as its parameters the integration that must be enabled and the original
    function that the SDK is patching. The function returns a function that takes the
    decorated (Sentry-patched) function as its parameter, and returns a function that, when
    called, checks whether the given integration is enabled. If the integration is enabled, the
    function calls the decorated, Sentry-patched function. If the integration is not enabled,
    the original function is called.

    The function also takes care of preserving the original function's signature and docstring.

    Example usage:

    ```python
    @ensure_integration_enabled(MyIntegration, my_function)
    def patch_my_function():
        with sentry_sdk.start_transaction(...):
            return my_function()
    ```
    sentry_patched_functionr  r<   c                      d fd}t           u r t                     |          S  t                    |          S )	NargsP.argskwargsP.kwargsr<   r7   c                  p    t          j                                                   | i |S  | i |S r>   )r   r   get_integration)r	  r  r   r  r  s     rC   runnerz;ensure_integration_enabled.<locals>.patcher.<locals>.runner]  sL    $&&66{CCK(($9&999**D;F;;;rB   )r	  r
  r  r  r<   r7   )r  r
   )r  r  r   r  s   ` rC   patcherz+ensure_integration_enabled.<locals>.patcher\  sk    	< 	< 	< 	< 	< 	< 	< 	< &&15011&999'u&''///rB   )r  r  r<   r  )r   r,   r   r6   r7   )r   r  r  s   `` rC   r  r  >  sT    2  D !!Q$1BCC
0 
0 
0 
0 
0 
0 
0 NrB   c                  (    t          j                    S r>   )timeperf_counter_nsrA   rB   rC   nanosecond_timer  m  s    #%%%rB   c                  H    t          t          j                    dz            S )Ng    eA)r  r  perf_counterrA   rB   rC   r  r  r  s    4$&&,---rB   c                  (    t          j                    S r>   )r  r  rA   rB   rC   nowr  v  s    rB   )get_hubis_module_patchedOptional[Hub]c                      d S r>   rA   rA   rB   rC   get_gevent_hubr    s    trB   mod_namec                     dS NFrA   )r  s    rC   r  r    s    urB   c                  >    t          d          pt          d          S )NrN  _threadr  rA   rB   rC   	is_geventr$    s    [))I->y-I-IIrB   r   Optional[threading.Thread]#Tuple[Optional[int], Optional[str]]c                    | &	 | j         }| j        }|||fS n# t          $ r Y nw xY wt                      r*t	                      }|	 |j        dfS # t          $ r Y nw xY w	 t          j                    } | j         }| j        }|||fS n# t          $ r Y nw xY w	 t          j                    } | j         }| j        }|||fS n# t          $ r Y nw xY wdS )zK
    Try to get the id of the current thread, with various fall backs.
    Nr  )	identr%  r   r$  r  thread_identrN  current_threadmain_thread)r   	thread_idthread_name
gevent_hubs       rC   get_current_thread_metar/    sZ    	I +K$ +-- % 	 	 	D	
 {{ #%%
!!.44!   )++L	k k)) !   &((L	k k)) !    :sB    
&&A 
AA"&B
 

BB&C 
CCr   c                 R    | t           k    rt          |d          r|j        dv rdS dS )Ncode)r   NFT)
SystemExitro  r1  )r   rX   s     rC   should_be_treated_as_errorr3    s2    	ZGE622uzY7N7Nu4rB   Tconvert_funcCallable[[Any], T]Optional[T]c                     	 t          ||           r|S n# t          $ r Y nw xY w	  | |          S # t          $ r Y dS w xY w)z
    Attempt to convert from an unknown type to a specific type, using the
    given function. Return None if the conversion fails, i.e. if the function
    raises an exception.
    N)r  r  rR  )r5  rX   s     rC   try_convertr9    sz    e\** 	L	   |E"""   tts    
""
1 
??c                     	 	 	 	 dfd	  |           }t          |t                    st          j        |t                    n|S # t          $ r t          |           cY S w xY w)	z&Safely serialize to a readable string.r)  r   r<   6Union[str, dict[Any, Any], list[Any], tuple[Any, ...]]c                    t          |           r|	 t          | dd           }t          | dd           }t          | dd          }|r
|r| d| }n|r
|r| d| }n|}d| dS # t          $ r dt          |           j         dcY S w xY wt          | t                    r fd	|                                 D             S t          | t          t          f          rfd
| D             S t          | d          rh	 fdt          |                                           D             }dt          |           j         d| dS # t          $ r t          |           cY S w xY w| S )Nr   r   r   	anonymousr   z
<function >z
<callable c                 .    i | ]\  }}| |          S rA   rA   r9  kr  serialize_items      rC   r  z:safe_serialize.<locals>.serialize_item.<locals>.<dictcomp>  s)    BBBTQA~~a((BBBrB   c                 &    g | ]} |          S rA   rA   )r9  r;  rB  s     rC   rm  z:safe_serialize.<locals>.serialize_item.<locals>.<listcomp>  s#    444!NN1%%444rB   r  c                 X    i | ]&\  }}|                     d           | |          'S )r  r(  r@  s      rC   r  z:safe_serialize.<locals>.serialize_item.<locals>.<dictcomp>  sK       1<<,,~~a((  rB   < )callablerC  rR  r/  r   r  r  r&  r  r  ro  r  r  )r)  r`  qualnamer%  	full_pathattrsrB  s         rC   rB  z&safe_serialize.<locals>.serialize_item  s    D>> 	; |T::"4>>tZ== %h %#) 6 6H 6 6II % %#) 2 2D 2 2II $I0I0000 ; ; ;:DJJ$7::::::;d## 	BBBBTZZ\\BBBBtUm,, 	4444t4444T:&& 	"    $T

 0 0 2 2  
 :4::.999999 " " "Dzz!!!" Ks%   AA% %"B
	B
=AE E! E!r:   N)r)  r   r<   r;  )r  r\   rj   rk   rR  )rc   
serializedrB  s     @rC   safe_serializerL    s    ""	A" " " " " "H#^D))
 j#..DJz3////	

    4yys   <A
 
A&%A&r  Optional[dict[str, Any]]c                     | dS t          |                     dd          p| d                             dd                    S )NFenable_logs_experimentsr`   r@   r  s    rC   has_logs_enabledrS    sL    uM5)) 	=>"&&}e<<  rB   .Optional[Callable[[Log, Hint], Optional[Log]]]c                 j    | d S |                      d          p| d                              d          S )Nbefore_send_logrP  r@   rR  s    rC   get_before_send_logrX    sB     t;;()) W^-D-H-H. . rB   c                 P    | dS t          |                     dd                    S )NFenable_metricsTrQ  rR  s    rC   has_metrics_enabledr[  %  s)    u,d33444rB   4Optional[Callable[[Metric, Hint], Optional[Metric]]]c                 j    | d S |                      d          p| d                              d          S )Nbefore_send_metricrP  rW  rR  s    rC   get_before_send_metricr_  ,  sB     t;;+,, 0G0K0K1 1 rB   valr/   c                    t          | t          t          t          t          f          r| S t          | t
          t          f          r| sg S t          | t
                    rat          | d                   t          t          t          t          fv r/t          fd| D                       rt          j
        |           S npt          | t                    r[t          | d                   t          t          t          t          fv r*t          fd| D                       rt          |           S t          |           S )a  
    Turn unsupported attribute value types into an AttributeValue.

    We do this as soon as a user-provided attribute is set, to prevent spans,
    logs, metrics and similar from having live references to various objects.

    Note: This is not the final attribute value format. Before they're sent,
    they're serialized further into the actual format the protocol expects:
    https://develop.sentry.dev/sdk/telemetry/attributes/
    r   c              3   :   K   | ]}t          |          u V  d S r>   r/  r9  r  r   s     rC   r;  z#format_attribute.<locals>.<genexpr>I  -      0L0L1aB0L0L0L0L0L0LrB   c              3   :   K   | ]}t          |          u V  d S r>   rc  rd  s     rC   r;  z#format_attribute.<locals>.<genexpr>M  re  rB   )r  r`   r  r  r\   r  r  r/  allr  deepcopyr  r`  r   s    @rC   format_attributerj  7  s    #c5#.// 
#e}%% 	c 			C		 #a&\\#sE4(((S0L0L0L0L0L0L0L-L-L(=%%%	C		 #a&\\#sE4(((S0L0L0L0L0L0L0L-L-L(99S>>rB   r0   c                    t          | t                    r| ddS t          | t                    r| ddS t          | t                    r| ddS t          | t                    r| ddS t          | t
                    rX| sg ddS t          | d                   t          t          t          t          fv r t          fd| D                       r| ddS t          |           ddS )	z2Serialize attribute value to the transport format.boolean)rX   r/  integerdoubler/  arrayr   c              3   :   K   | ]}t          |          u V  d S r>   rc  rd  s     rC   r;  z&serialize_attribute.<locals>.<genexpr>d  re  rB   )	r  r`   r  r  r\   r  r/  rg  r  ri  s    @rC   serialize_attributerq  S  s   #t 1i000#s 1i000#u 0h///#s 0h///#t 3 	2111 #a&\\#sD%(((S0L0L0L0L0L0L0L-L-L( '222 s^^X666rB   )r<   rE   )rX   r   rW   rY   r<   rZ   )r<   rn   r   )r   r2   r<   Nr>   )r   r   r<   r   )r?  r@  r<   rn   )r   r   r<   rU  )NNN)rJ  r   r  r^  r  r^  r<   ra  )r`  rn   r  rn   r<   rn   )NTTNN)TTN)NNNNNN)r  r@  r  r   r   r   r  r  r  r  r  r^  r  r^  ry  rn   r  r  r<   r  )r   r2   r<   r  )NNr   r   NNNN)
r   r2   r  r  r  r  r  r  r<   r  )r  r1   r<   r  )r  r1   r<   r  )
r  r1   r  r  r  r  r  rn   r<   r1   )
r  r   r  r  r  r  r  rn   r<   r   )r   r  r<   r2   )r  r  r  r  r  r  r<   r  r  )r   r  r  r  r  r  r<   r  )r<   rq  )ru  rv  r<   rn   )TTF)Tr!  )r<   r  )r<   r  )r  r   rX   r   r   r   r<   r$   )r  r   r  r   r<   N)r   r  r  r  r<   r   )r   r  r<   r  )r   r  r  r  r<   r   )r<   r  )r   r%  r<   r&  )r5  r6  rX   r   r<   r7  )r  rM  r<   rT  )r  rM  r<   r\  )r`  r   r<   r/   )r`  r/   r<   r0   )r  rS  rj   rr  loggingr  ry   r  rj  r(  r~   r|   rN  r  collectionsr   
contextlibr   r   r   decimalr   	functoolsr   r	   r
   numbersr   urllib.parser   r   r   r   r   rF  r   rp  typingr   r   sentry_sdk._compatr   sentry_sdk._typesr   r   r   sentry_sdk.constsr   r   r   r   typesr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   
gevent.hubr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r   	getLoggerr   r  rT  r?   r`   rD   rJ   r)  r  	frozensetr^   r_   r  rb   bytesrm   r   r   r\   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r!  rD  rI  rT  rZ  r  r  r  r  r  r  r  r  r  r  r  r  ro  rR  HAS_CHAINED_EXCEPTIONSr  r  r  r  r  r  r  r
  r   r  r$  r  r  r  r6  r9  rj  rI  r^  r/  rp  rt  HAS_REAL_CONTEXTVARSCONTEXTVARS_ERROR_MESSAGEr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rV  r  r  rW  r  r$  r/  r3  r4  r9  rL  rS  rX  r[  r_  rj  rq  rA   rB   rC   <module>r     s               				   				     



      " " " " " " % % % % % % ' ' ' ' ' ' ' '       3 3 3 3 3 3 3 3 3 3       K K K K K K K K K K K K K K+++++++    !               # # # # # # R R R R R R R R R R             #........                                     (                   		#AA 	q! 
	.	/	/ 1;1u   
*$ * * * * . . . . "*1229BCC IBCC   =B + + + + + +TU Tu T T T T
   6   2           F       $ 7688 ' ' ' 'H H H H+
 +u + + + +	5J 	53 	5 	5 	5 	5 Ij)) +3 +: + + + +, %)
"!
"#
" 
" 
" 
"" " " " "Z " " "L
 L
 L
 L
 L
 L
 L
 L
^+R +R +R +R +R +R +R +R\P P P P   [ T    $    #'""* ***  * 	*
 * S* * * *` )- & S	   6 E  c        U s    '6   6 "&$(#'(,<@0 000 "0 !	0
 &0 :0 0 0 0 0h %)#'(, !  & 	   4- -? - - - -!: s    , 26,0$(!%"37cc(c 	"c /	c
 *c "c c c 1c c c c cL !,BCC  "7 7 7 7 7>    26,0"377;/3H& H&H&(H& 	"H& /	H&
 *H& H& H& H& 1H& 5H& -H& (H& H& H& H&Z 26,037	((.( *( 1	(
 ( ( ( (V!S !S ! ! ! !
. 
. 
. 
.    -1,0$(	) * "	
    0 %)	(()( *( "	(
 ( ( ( (V   8("(&( /( 	( ( ( (Z 26,0-. * $	   :/ 2G D    / d    

-<
	
 
 
 
s s s    c o     /3 +!   <03 0#> 0 0 0 0f0 0 0 0 0f $    8"7 "7 "7 "7J $4#3#5#5   j    @( ( ( ( #
#:;; 	 	 	 	 	y 	 	 	B
 B
 B
 B
 B
I$ B
 B
 B
J      s     * Z&W&W&WXX

 " $	-& -&	-&-& -& 	-&
 -& -& -& -&` J{$@$@$@AA	 3 $ +    6u c d    @ )-$ 
%  
	   &	8 	s 	t 	 	 	 	A A A A8     (C (C ( ( ( (
   "S "%@ " " " "& '$ 	 	   	 	 	 	
  A;@;+; 
6; ; ; X;
 A@A	;A A A XA EK*<*A* 2* * * *Z  .&S & & & & &
.S . . . .U    000000///////      C D      J4 J J J J
 ,01(1*1 1 1 1h5  4      A   $/ /3 / / / /d8 T    '5   5!; 5 5 5 5 5';      87 7 7 7 7 7s$   2A9 9BB2S? ?TT