
    \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# 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&rVd 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j                  d      ZTdaU ej                  dd      ZWdeXfdZYedd       ZZ e	j                  d      Z\ e]d      Z^ e]d      Z_d Z`	 dd!dd$Zad%d#debfd&Zcdd(Zddd)Zed*d+deffd,Zg G d- d.      Zh eh       Zidd/Zjdd0Zkd"d1delfd2Zmd"d1deffd3Zn e]d4      Zod"efdd1fd5Zp	 d	 	 	 dd6Zq G d7 d8er      Zs G d9 d:      Zt G d; d<      Zudd>Zvdd?Zwd@dAdeXfdBZxddEZy	 	 	 ddFefdGezdHdIdJdKdLd'ddMfdNZ{	 d	 	 	 	 	 	 	 ddQZ|d"d#deffdRZ}d"d#deffdSZ~	 	 	 	 	 	 ddUZ	 	 	 	 	 dd@dAdOdIdVeXdWeXdPdIdXdYddZfd[Z	 	 	 ddVeXdWeXdPdIddZfd\Zd]eddKfd^Zd]d_deffd`Z	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddjZ eedk      ZerddlZnddmZ	 	 	 	 	 	 	 	 ddad=d]d_dCdDdbdcdddcdeezdfezdgd'dhdidndodpdqddrfdsZ	 	 	 d	 	 	 	 	 	 	 	 	 ddtZd"efdeffduZddvZddwZ	 	 	 d	 	 	 	 	 	 	 	 	 ddzZ	 d	 	 	 	 	 	 	 	 	 dd{Zdd|Z	 	 	 	 	 	 	 	 dd}Z	 	 d	 	 	 	 	 	 	 dd~Zdd'ddxdeXfdZdTd'deXfdZdTd'dyd'deXfdZdefdezdeffdZd"efddIfdZ	 dd"efdHdIddfdZdefddfdZdeXfdZdedefdZddZ e       \  ZZVdZddZddZ eVd      Z G d de      Z G d dejJ                        Zdefdd'fdZdefdd'fdZ edg d      Z	 	 	 ddefdeXdeXdeXddf
dZ edg d      ZddefdeXddfdZdd#dgefdeXfdZ	 	 ddefddxdeXdeXfdZdddefdeXfdZddZdefdeffdZdefdeffdZddZdefddfdZ	 d	 	 	 	 	 	 	 ddZddZe&reF	 	 	 	 	 	 dd       ZeF	 	 	 	 dd       Zef	 	 	 	 	 ddZe)rdezfdZndezfdZdelfdZ	 d dlmZ d dlmZ deXfdńZ	 d	 	 	 ddƄZdd#d"d#deXfdȄZe&r eCdɫ      ZddʄZd%d#deffd˄ZdddeXfd΄Z	 	 	 	 ddτZdddeXfdЄZ	 	 	 	 ddфZȐd d҄ZɐddӄZy# e$$ r dZ#Y xw xY w# e$$ r ddZdefdeXfdĄZY {w xY w(      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                  *    t         j                         S N)_is_sentry_internal_taskget     :/root/env/lib/python3.12/site-packages/sentry_sdk/utils.pyis_internal_taskrD   \   s    #''))rB   c               #      K   t         j                  d      } 	 d t         j                  |        y# t         j                  |        w xY ww)z2Context manager to mark a task as Sentry internal.TN)r?   setreset)tokens    rC   mark_sentry_task_internalrI   `   s=      %((.E. &&u- &&u-s   A3 AA

Az^[a-zA-Z0-9/+=]*$)falsefnnooff0)truetyyeson1i  )strictvaluer   c                ~    | t        |       j                         nd}|t        v ry|t        v ry|rdS 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)rW   rV   
normalizeds      rC   env_to_boolr_   y   sF     (-'8U!!#dJ%%&&4*tE{*rB   datac                 P    t        j                  | dd      j                  d      S )zCSerialize data into a compact JSON representation encoded as UTF-8.F),:)	allow_nan
separatorsutf-8)jsondumpsencode)r`   s    rC   
json_dumpsrj      s     ::de
CJJ7SSrB   Optional[str]c                     	 t        t        j                  j                  d      5 } d }t        j
                  dk(  st        j
                  dk(  r7t        j                         }|xj                  t        j                  z  c_        t        j                  g d|t        j                  | |       j                         d   j                         j                  d      }d d d        |S # 1 sw Y   S xY w# t        t         t"        f$ r Y y w xY w)Nzw+win32cygwin)gitz	rev-parseHEAD)startupinfostdoutstderrstdinr   rf   )openospathdevnullsysplatform
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWPopenPIPEcommunicatestripdecodeOSErrorIOErrorFileNotFoundError)nullrq   revisions      rC   get_git_revisionr      s    "''//4( 	DK||w&#,,(*B(446##z'F'FF#   0 +%?? q"  	, O-	, O W/0 s/   $C5 B8C(C5 (C2-C5 2C5 5DDc                      t         j                  j                  d      } | r| S t               } | r| S dD ]'  }t         j                  j                  |      } | s%| c S  y)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)rv   environr@   r   )releasevars     rC   get_default_releaser      s_    jjnn-.G G  **..%N rB   installed_integrationsz	List[str]c                 H    g d}|D ]  }|| v sdj                  |      c S  y)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      s:    
. . :00%,,[99: rB   c                   0    e Zd ZdZddZdddddd	defd
Zy)CaptureInternalExceptionrA   r<   c                     | S r>   rA   selfs    rC   	__enter__z"CaptureInternalException.__enter__   s    rB   tyOptional[Type[BaseException]]rW   Optional[BaseException]tbOptional[TracebackType]c                 (    ||t        |||f       y)NT)capture_internal_exception)r   r   rW   r   s       rC   __exit__z!CaptureInternalException.__exit__   s     >e/&E27rB   Nr<   zContextManager[Any])__name__
__module____qualname__	__slots__r   r]   r   rA   rB   rC   r   r      s7    I	+	 )	 &		
 
	rB   r   c                      t         S r>   )_CAPTURE_INTERNAL_EXCEPTIONrA   rB   rC   capture_internal_exceptionsr      s    &&rB   c                 x    t        j                         j                         rt        j	                  d|        yy)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exc_infoN)
sentry_sdk
get_client	is_activeloggererrorr   s    rC   r   r      s/     ((*3hG +rB   r   c                 0    | t         z
  j                         S r>   )epochtotal_secondsrW   s    rC   to_timestampr     s    EM((**rB   c                 b    | j                  t        j                        }|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)rW   utctimes     rC   format_timestampr     s,    
 x||,G 344rB   )+-c                 \   	 t        j                  |       }|j                  t        j                        S # t        t        f$ rf d| v rdnd}| j	                  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 w xY w)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   )rW   resulttimestamp_formats      rC   datetime_from_isoformatr     s    <''.  X\\** J' < '*Ul"8K 	 >>##2J(E9))$#2Jrs+E2Y++$""5*:;<s   6 A2B+*B+c                 \    | t        j                         } nt        |       } | d   d} d| iS )z+Creates a hint with the exc info filled in.Nr   r   )ry   r   exc_info_from_errorr   s    rC   event_hint_with_exc_infor   0  s9     <<>&x0{!!rB   c                       e Zd ZdZy)BadDsnzRaised on invalid DSNs.Nr   r   r   __doc__rA   rB   rC   r   r   =  s    !rB   r   c                   v    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y)DsnzRepresents a DSN.z	^o(\d+)\.Nr<   c                    t        |t              rt        |j                        | _        y t	        t        |            }|j                  dvrt        d|j                  z        |j                  | _        |j                  t        d      |j                  | _	        ||| _
        nCt        j                  j                  | j                        }|r|j                  d      nd | _
        |j                  | j                  dk(  xr dxs d| _        n|j                  | _        |j                  st        d      |j                  | _        |j"                  | _        |j&                  j)                  d	d      }	 t        t+        |j-                                     | _        d	j5                  |      d	z   | _        y # t0        t2        f$ r  t        d
|j&                  xs ddd  z        w xY w)N)httphttpszUnsupported scheme %rzMissing hostnamer8   r     P   zMissing public key/zInvalid project in DSN (%r) )
isinstancer   dict__dict__r   rY   schemer   hostnamehostorg_idORG_ID_REGEXmatchgroupportusername
public_keypassword
secret_keyrw   rsplitintpop
project_idr   	TypeErrorjoin)r   rW   r  partsorg_id_matchrw   s         rC   __init__zDsn.__init__F  s    eS! 0DMU$<<0005<<?@@ll>>!+,,NN	+1DK++11$))<L3?,,,Q/TDK::![[G3;ArDI

DI~~-......zz  a(	Q!#dhhj/2DO HHTNS(	 I& 	Q6%**:JAB9OOPP	Qs   <'F= =/G,c                 t    | j                   }| j                  | j                  fdvr|d| j                  }|S )zThe netloc part of a DSN.))r   r   )r   r   rc   )r  r   r  r   rvs     rC   netlocz
Dsn.netlocq  s6     YYKK#+II		*B	rB   c           	          t        | j                  | j                  | j                  | j                  | j
                  | j                  |      S )z*Returns the auth info object for this dsn.)r   r  rw   r  r  r
  client)Authr   r  rw   r  r  r
  )r   r  s     rC   to_authzDsn.to_authy  s<    ;;
 	
rB   c                     | j                   d| j                  | j                  xr d| j                  z   xs dd| j                  | j                  | j
                  S )N://@r   )r   r  r
  r  rw   r  r   s    rC   __str__zDsn.__str__  sL    KKOOOO5doo 5;;KKIIOO
 	
rB   r>   )rW   zUnion[Dsn, str]r  rk   r<   N)r  Optional[Any]r<   r  )r   r   r   r   recompiler  r  propertyrY   r  r  r  rA   rB   rC   r   r   A  sf    2::l+L CG))&))0?))	))V   


 
rB   r   c                   z    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
y)r  z,Helper object that represents the auth info.Nr   r  r  r  r
  rk   versionr  r   rw   r<   c	                 t    || _         || _        || _        || _        || _        || _        || _        || _        y r>   )r   r  rw   r  r  r
  r%  r  )	r   r   r  r  r  r
  r%  r  rw   s	            rC   r  zAuth.__init__  s<     		$$$rB   typer   c           	          | j                   d| j                  | j                  d| j                  d|j                  d	S )z'Returns the API url for storing events.r  zapi/r   )r   r  rw   r  rW   )r   r'  s     rC   get_api_urlzAuth.get_api_url  s1     KKIIIIOOJJ
 	
rB   c                    d| j                   fd| j                  fg}| j                  |j                  d| j                  f       | j                  |j                  d| j                  f       ddj                  d |D              z   S )z!Returns the auth header a string.
sentry_keysentry_versionsentry_clientsentry_secretzSentry z, c              3   0   K   | ]  \  }}|d |  yw)=NrA   ).0keyrW   s      rC   	<genexpr>z!Auth.to_header.<locals>.<genexpr>  s     $Q
UU%;$Qs   )r  r%  r  appendr
  r  r  s     rC   	to_headerzAuth.to_header  sw    T__-0@$,,/OP;;"II45??&II89499$Qb$QQQQrB   )N   Nr   )r   r   r   r   rY   r  r  r   ENVELOPEr)  r5  rA   rB   rC   r  r    s    6 '+"&  	
  $     
,  ,44

 

R3 RrB   r  Optional[type]c                 :    t        | dd       xs t        | dd       S )Nr   r   getattr)clss    rC   get_type_namer=    s    3-Oj$1OOrB   c                 *    t        | dd       }|dvr|S y )Nr   )Nbuiltins__builtins__r:  )r<  mods     rC   get_type_modulerB    s!    
#|T
*C
44
rB   framer   c                     	 | j                   d   }|j                  d      ry	 dD ]  }	 | j                  |   r y y# t        t        f$ r Y +w xY w# t
        $ r Y 8w xY w)Nr   zsentry_sdk.T)__traceback_hide____tracebackhide__F)	f_globals
startswithr   KeyErrorf_locals	Exception)rC  rA  	flag_names      rC   should_hide_framerM    s    ooj)>>-( )
 ? 		~~i( )  H%   		s     > AAA	AAr   r   c              #   f   K   | }|)t        |j                        s| |j                  }|(y y wr>   )rM  tb_frametb_next)r   tb_s     rC   iter_stacksrR    s1     %'C
/ .Ikk /s   ,11filenamelineno
max_lengthOptional[int]loaderr   moduleKTuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]c                    d}d }|0t        |d      r$	 |j                  |      }||j	                         }|	 t        j                  |       }|sg d g fS t        d||z
        }t        |dz   |z   t        |            }		 ||| D 
cg c]  }
t        |
j                  d      |        }}
t        ||   j                  d      |      }||dz   |	 D 
cg c]  }
t        |
j                  d      |        }}
|||fS # t        t        f$ r d }Y w xY w# t        t        f$ r g d g fcY S w xY wc c}
w c c}
w # t        $ r g d g fcY S w xY w)N   
get_sourcer   r8   z
)rU  )hasattrr\  ImportErrorr   
splitlines	linecachegetlinesr   maxminlenstrip_stringr   
IndexError)rS  rT  rU  rW  rX  context_linessource
source_strlower_boundupper_boundlinepre_contextcontext_linepost_contexts                 rC   get_lines_from_filerp    s    MFgfl;	*0*;*;F*CJ !**,F~	 ''1F 4|a-/0Kfqj=0#f+>K {62
 F+
C
 
 $F6N$8$8$@ZX 
k:
 F+
C
 
 L,667 W% 	J	 ! 	 tR<	 



  4|sR   D  D D; #D1++D; #D69D;  DDD.-D.1
D; ;EE	tb_linenomax_value_lengthc                    	 | j                   j                  }	 | j                  d   }	 | j                  d   }||r|dz
  }t	        |||||      S g d g fS # t        $ r d }Y Kw xY w# t        $ r g d g fcY S w xY w# t        $ r d }Y Pw xY w)Nr   
__loader__r8   )rW  rX  )f_codeco_filenamerK  rG  rp  )rC  rq  rr  abs_pathrX  rW  rT  s          rC   get_source_contextrx    s    
$)LL$<$<,. Q"f.vf
 	
 tR<#    4|  s3   A A' A; A$#A$'A87A8;B	B	c                 N    	 t        |       S # t        $ r t        |       cY S w xY wr>   )rY   rK  	safe_reprr   s    rC   safe_strr{  +  s+     5z   s   
 $$c                 8    	 t        |       S # t        $ r Y yw xY w)Nz<broken repr>)reprrK  r   s    rC   rz  rz  2  s#    E{ s   
 	rw  c                    |r| s|S 	 |j                  d      r|d d }| j                  dd      d   }|| k(  rt        j                  j	                  |      S t
        j                  |   j                  }|s|S |j                  |j                  t        j                  d      d   d      d   j                  t        j                        S # t        $ r |cY S w xY w)Nz.pycr   r   r8   r      )r   splitrv   rw   basenamery   modules__file__r  seplstriprK  )rX  rw  base_modulebase_module_paths       rC   filename_for_moduler  9  s     6V$}Hll3*1-& 77##H--;;{3<<O~~.55bffa@CQGKRRFF
 	
  s   AC  C 8AC CC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   }	|| j                  }	 |rt        j                  j                  |      nd }
t        |	|      xs d |
|xs d|	|d}|rt        | ||      \  |d<   |d<   |d<   |r'dd	lm}  |t        | j                        d
|      |d<   |S # t
        $ r d }	Y w xY w# t
        $ r d }
Y w xY w)Nru  r   z	<unknown>)rS  rw  functionrX  rT  rm  rn  ro  r   )	serializeT)is_varsr  vars)r;  ru  rv  co_namerG  rK  f_linenorv   rw   abspathr  rx  sentry_sdk.serializerr  r   rJ  )rC  rq  r  r  rr  r  ru  rw  r  rX  os_abs_pathr  r  s                rC   serialize_framer  R  s+    UHd+F<<++<<'', NN	3;bggooh/
 (9AT+B DV9.E
A=2n-r./A 3 $K
6
 I?    s$   C$  #C5 $C21C25DDc                     d}g }t        j                         }|8t        |      s|j                  t	        || ||             |j
                  }|8|j                          d|iS )NT)r  r  rr  frames)ry   	_getframerM  r4  r  f_backreverse)r  r  rr  rF  r  rK   s         rC   current_stacktracer    sp    
 F"}}A
- #MM,C+A%5	 HH - NNfrB   	exc_valuec                     t        | dd       S )Nerrnor:  )r  s    rC   	get_errnor    s    9gt,,rB   r   c                     t        t        | dd      xs t        | dd      xs t        |             }t        | dd       }t        |t              r,t	        |      dkD  r|ddj                  d |D              z   z  }|S )Nmessager   detail	__notes__r   
c              3   B   K   | ]  }t        |t              s|  y wr>   )r   rY   )r1  notes     rC   r3  z$get_error_message.<locals>.<genexpr>  s     #TTjs>SD#Ts   )r{  r;  r   listrd  r  )r  r  notess      rC   get_error_messager    s}    	9b) 	9h+	IG I{D9E%3u:>4$))#TU#TTTTNrB   exc_typeclient_optionsOptional[Dict[str, Any]]	mechanismexception_id	parent_idrh  
full_stackOptional[list[dict[str, Any]]]c	                    i }	|r|j                         nddd|	d<   |||	d   d<   |t        |      }
nd}
|
5|	d   j                  di       j                  di       j                  d	|
       |||	d   d
<   |dk(  }|s|||	d   d<   d|	d   d<   |rd|	d   vrd|	d   d<   t        duxr t	        |t              }|rd|	d   d<   t        |       |	d<   t        |       |	d<   t        |      |	d<   |d}d}t        }d}n |d   }|d   }|d   }|j                  d      }t        t        |      t        t        dz               D cg c]*  \  }}t        |j                  |j                   ||||      , }}}t#        |      t        kD  rt%        j&                  d      |	d<   |	S |r|s|}nt)        |||      }d|i|	d<   |	S c c}}w )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  numberrh  r   r  chainedr'  is_exception_grouprX  rW   r  r  rr  r  r8   )rq  r  r  rr  r  r   
stacktracer  )copyr  
setdefaultr   r   rB  r=  r  r   r@   ziprR  rangeMAX_STACK_FRAMESr  rO  rq  rd  r   removed_because_over_size_limitmerge_stack_frames)r  r  r   r  r  r  r  rh  r  exception_valuer  is_root_exceptionr  r  r  rr  r  _r  
new_framess                       rC   !single_exception_from_error_tupler    s^   " )+O%	I$+O K  7C$^4)$$//;FFR	

*Xu
%17$X.$)!64=$[1/8$V,V?;+GG/8$V,+47 J%= =A$%9: / 9OH+H5OF0;OG"&!%3"01J"K!/0H!I)*<=$((7 R%0@10D*EF& B 	KKll$;#9-#	
&F & 6{%% )7(V(V)
%  
J+FJOJ)1:(>%C&s   /G__suppress_context__c              #   h  K   | \  }}}g }t               }||t        |      |vr|||f |j                  |       |j                  t        |             |j                  r|j
                  }n|j                  }|y t        |      }|}t        |dd       }||t        |      |vry y y y y y w)N__traceback__)	rF   idr4  addr  	__cause____context__r'  r;  )r   r  r  r   seen_exceptionsseen_exception_idscauses          rC   walk_exception_chainr    s     "*)R),  %9%77Ir))
 ""9-""2i=1--!++!--}E{HI6B)  %9%77 & !7 & !s   B)B2,B2c              #      K   |  y wr>   rA   r   s    rC   r  r  >  s     s   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 |+|	j                  |       |
j                  t        |             t	        | ||||||||	      }|g}|}|dz  }t        |d      xr |j                  }|rl|xr t        |d      xr |j                  du}|r|j                  }t        t        |      |t        |dd      |||d||	|

      \  }}|j                  |       nk|xr t        |d      xr |j                  du}|rI|j                  }t        t        |      |t        |dd      |||d||	|

      \  }}|j                  |       |xr t        |d	      }|r^t        |j                        D ]F  \  }}t        t        |      |t        |dd      ||||d
|z  ||	|
      \  }}|j                  |       H ||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  rh  r  r8   r  r  r  )
r  r  r   r  r  r  rh  r  r  r  r  
exceptionszexceptions[%s])r  r  r   r  r  r  r  rh  r  r  r  )rF   r  r4  r  r  r]  r  r  exceptions_from_errorr'  r;  extendr  	enumerater  )r  r  r   r  r  r  r  rh  r  r  r  parentr  should_supress_contextexception_has_causer  child_exceptionsexception_has_contentcontextr  idxes                         rC   r  r  B  sf   J ! UI2D!Db!!y)r)}-.%!
F JIAL 		12Uy7U7U    0	;/0##4/ 	
 ''E/De5/48-#)"% /#50,\+ ./  2	=12%%T1 	
 !++G/Dg!7OT:-#)$% /#50,\+ ./ #Gwy,'G	 4 45 	0FC/Da1ot4-#)#'#-% /#50,\+ ./	0  *%%rB   c                    | \  }}}t         d uxr t        |t               }|rt        |||||dd|      \  }}	n6g }	t        |       D ]&  \  }}}|	j	                  t        ||||||             ( |	j                          |	S )Nr   )r  r  r   r  r  r  r  r  )r  r  r   r  r  r  )r   r   r  r  r4  r  r  )
r   r  r  r  r  r  r   r  r  r  s
             rC   exceptions_from_error_tupler    s     'Hi+47 J%= /)!	
J 
';H'E 
	#Hi1%'#1')	
	 rB   c                 T    	 t        |       S # t        $ r t        |       dd cY S w xY w)Nr8   r   )rY   UnicodeDecodeErrorr}  r   s    rC   	to_stringr    s1    !5z !E{1R  !s   
 ''c              #      K   d| v r| d    d| v r)| d   j                  d      xs dD ]  }d|v s|d     d| v r;| d   j                  d      xs dD ]  }t        |t              sd|v s|d    ! y y w)Nr  threadsvaluesrA   	exception)r@   r   r   )eventthreadr  s      rC   iter_event_stacktracesr    s     uL!!EI&**84: 	+Fv%\**	+ e{+//9?R 	.I)T*|y/H--	. s   /A;8A;+A;0A;c              #      K   t        |       D ]@  }t        |t              r|j                  xs i }|j	                  d      xs dD ]  }|  B y w)Nr  rA   )r  r   r   rW   r@   )r  r  rC  s      rC   iter_event_framesr    sV     ,U3 
j.1#))/RJ^^H-3 	EK		s   AAOptional[List[str]]project_rootc                     t        |       D ]@  }t        |t              r|j                  xs i }t	        |j                  d      |||       B | S )Nr  )in_app_excludein_app_includer  )r  r   r   rW   set_in_app_in_framesr@   )r  r  r  r  r  s        rC   handle_in_appr    sV     -U3 	

j.1#))/RJNN8$))%		
		
 LrB   c                    | sy | D ]  }|j                  d      }||j                  d      }t        ||      rd|d<   :t        ||      rd|d<   L|j                  d      }|`t        |      rd|d<   qt        ||      s~d|d<    | S )Nin_apprX  TFrw  )r@   _module_in_list_is_external_source_is_in_project_root)r  r  r  r  rC  current_in_apprX  rw  s           rC   r  r  )  s      8,%8$ 6>2"E(O 6>2#E(O 99Z(x(#E(Ox6"E(O;> MrB   c                 f   t        | t              rt        |       dk(  r| \  }}}npt        | t              rIt	        | dd       }|t        |       }| }nCt        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   tuplerd  BaseExceptionr;  r'  ry   r   r   r   r,   r2   )r   r  r  r   r   s        rC   r   r   T  s    %CJ!O"')R	E=	)UOT2>E{HI&)lln#Hi%!	; G$u+UVV)R(H *OrB   c                    | D ch c]  }|d   |d   |d   |d   f }}|D cg c]  }|d   |d   |d   |d   f|vr| }}|j                  |        |r|j                  dt              nd}||t        |      |z
  d }|S c c}w c c}w )zV
    Add the missing frames from full_stack to frames and return the merged list.
    rw  rn  rT  r  max_stack_framesN)r  r@   r   rd  )r  r  r  rC  	frame_ids
stackframer  r  s           rC   r  r  p  s       *.!(O*		
I  %
z"~&x z"	
  	
J 
 f
  	-/GH 
 #J2B B DE
A
s
   BBc                     t        |       } t        |       }|r-|j                  dt              rt	        |d   |d         d   }nd }ddt        | |||      id|fS )	Nadd_full_stackr  rr  )r  rr  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'$23L$M+,>?
 

 
 5ni	
 	
 
rB   nameitemsc                 T    | y|sy|D ]  }|| k(  s| j                  |dz         s y y)NFr   TrH  )r
  r  items      rC   r  r    s=    | 4<4??4#:6 rB   c                 <    | yt        j                  d|       d u}|S )NFz [\\/](?:dist|site)-packages[\\/]r!  search)rw  external_sources     rC   r  r    s.     			5x@L  rB   c                 2    | |y| j                  |      ryy)NFTr  )rw  r  s     rC   r  r    s(     </ <(rB   string	max_bytesc                 \    | j                  d      d|dz
   j                  dd      }|dz   S )zd
    Truncate a UTF-8-encodable string to the last full codepoint so that it fits in max_bytes.
    rf   Nr  ignore)errors...)ri   r   )r  r  	truncateds      rC   _truncate_by_bytesr    s8     g&Q7>>wx>XIurB   c                 b    	 t        | j                  d            S # t        t        f$ r Y y w xY w)Nrf   )rd  ri   UnicodeEncodeErrorr  r   s    rC   _get_size_in_bytesr    s3    5<<()) 23 s    ..zUnion[AnnotatedValue, str]c                     | s| S |t         }t        |       }t        |       }|||kD  rt        | |      }n|||kD  r| d |dz
   dz   }n| S t	        ||xs |dd|dz
  |ggd      S )Nr  r  z!limitx)rd  rem)rW   metadata)r   r  rd  r  r   )rW   rU  	byte_size	text_sizetruncated_values        rC   re  re    s     -
"5)IE
IZ!7,UJ?		9z#9 0*q.1E9)	sJNJ?@
 rB   r%  zOptional[Tuple[int, ...]]c                 P   d}t        j                  d|z   dz   t         j                  t         j                  z        }	 |j	                  |       j                         d   }t        t        t        |j                  d      dd             }|S # t        t        t        f$ r Y yw xY w)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_versionr.    s    O> jj/!G+


R]]"G
--(224Y?+0S'--:LRa:P1Q+R  z>2 s   AB B%$B%c                     	 ddl } ddlm} t        t	        j
                  d| j                        dd D cg c]  }t        |       c}      } |dd      r#t        j                  dk\  r|d	k\  s	 |d
d      ryy	 	 ddl}ddlm} t        |j                        }|t        j!                  d       y |d      r|dk  ryyc c}w # t        $ r Y Ww xY w# t        $ r Y yw xY w)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_patchedz	a|b|rc|\.r  	threadinglocalr  r6  )   	   contextvars
ContextVarFT)is_monkey_patchedzYInternal error in Sentry SDK: Could not parse Greenlet version from greenlet.__version__.r  )r   r[  )geventgevent.monkeyr0  r  r!  r  __version__r  ry   version_infor^  greenleteventlet.patcherr8  r.  r   r   )r9  r0  partversion_tupler=  r8  greenlet_versions          rC   _is_contextvars_brokenrB  ?  s    3 #%88L&:L:L#Mbq#QR4SYR
 ['2 !!V+0H%m\B 3&6()=)=>#LLk X&+;f+D M S$  "  s:   4C C1C =6C 4C C 	CC	C#"C#r2  c                        G  fdd      }|S )Nc                   B    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y)1_make_threadlocal_contextvars.<locals>.ContextVarNr
  r;   r   r<   c                 R    || _         || _                | _                | _        y r>   )_name_default_local_original_local)r   r
  r;   r2  s      rC   r  z:_make_threadlocal_contextvars.<locals>.ContextVar.__init__v  s$    DJ#DM'DK#(7D rB   c                 L    t        | j                  d|xs | j                        S )NrW   )r;  rI  rH  )r   r;   s     rC   r@   z5_make_threadlocal_contextvars.<locals>.ContextVar.get|  s    4;;1IDMMJJrB   c                     t        t        j                  d            }| j                         }t	        | j
                  ||       || j                  _        |S )N@   )rY   randomgetrandbitsr@   setattrrJ  rI  rW   )r   rW   rH   original_values       rC   rF   z5_make_threadlocal_contextvars.<locals>.ContextVar.set  sE    **2./E!XXZND((%@ %DKKLrB   c                 |    t        | j                  |      | j                  _        | j                  j                  |= y r>   )r;  rJ  rI  rW   r   )r   rH   s     rC   rG   z7_make_threadlocal_contextvars.<locals>.ContextVar.reset  s/     '(<(<e DDKK$$--e4rB   r>   )r;   r   r<   r   )rW   r   r<   r   )rH   r   r<   N)r   r   r   rY   r  r@   rF   rG   r2  s   rC   r7  rE  s  s-    	+ 	+u 	+ 	+	K		5rB   r7  rA   )r2  r7  s   ` rC   _make_threadlocal_contextvarsrT  r  s    5 50 rB   c                      t               s)t        j                  dk  r	 ddlm}  d| fS 	 ddlm}  d| fS ddlm} dt        |      fS # t
        $ r Y w xY w# t
        $ r Y -w xY w)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.
    r3  r   )r7  TrS  F)
rB  ry   r<  aiocontextvarsr7  r^  r6  r1  r2  rT  )r7  r2  s     rC   _get_contextvarsrW    s}     "#
 f$5Z''
2Z''  /666    s"   	A 	A 	A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.
c                    d}d\  }}t        | t              r(t        | j                  d      rd\  }}| j                  } n=t	        | dd      xs 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 rY  r   r   r   )
r   r   r]  funcr;  r	   r   r   r   rY   )r\  func_qualnameprefixsuffixpartial_methods        rC   qualname_from_functionra    s    %)MNFF$ WTYY
%C3yy !'7> 
'%tC
 nm4=NFF!&&Dt^$))	z	" 4&:doos+K OOc1MAM.7rB   c                     t        |       S r>   )ra  )r\  s    rC   transaction_from_functionrc    s    !$''rB   disable_capture_eventc                       e Zd ZdZy)ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nr   rA   rB   rC   rf  rf    s    HrB   rf  c                   J    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	y)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                  j                  |        || _        || _        || _        || _        t        j                         | _        y r>   )	r1  Threadr  ri  rj  rk  rl  r1   _stop_event)r   ri  rj  rk  rl  s        rC   r  zTimeoutThread.__init__  sG     	!!$'("4.*$??,rB   c                 8    | j                   j                          y r>   )ro  rF   r   s    rC   stopzTimeoutThread.stop  s    rB   c                     t        j                         }t        j                         }t	        ||j
                  ddd      \  }}t        j                  ||       |S )Nr1  Fr  )r  r  )r  )ry   r   r   r   r	  optionscapture_event)r   r   r  r  r  s        rC   _capture_exceptionz TimeoutThread._capture_exception  sR    <<>&&(*!>>*u=
t
 	  T2rB   c                    | j                   j                  | j                         | j                   j                         ry t	        | j
                        }|| j
                  k  r|dz   }| j                  {| j                  ot        j                  j                  | j                        5  t        j                  j                  | j                        5  	 t        dj                  |            t        dj                  |            # t        $ r t        | j!                           Y nw xY w	 d d d        n# 1 sw Y   nxY wd d d        ^# 1 sw Y   gxY w)Nr8   zZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)ro  waitri  is_setr  rj  rk  rl  r   scopeuse_isolation_scope	use_scoperf  r   rK  reraiseru  )r   integer_configured_timeouts     rC   runzTimeoutThread.run  s<   d//0""$%()@)@%A" &(?(??)Ca)G& +0B0B0N!!55d6J6JK 	<%%//0B0BC <<6x :  'hoo*
 	
 % <!8!8!:;<;< < <	< 	< 	<sB   +*ED:DD-*D:,D--D:1	E:E	?EENN)r<   N)r<   r2   )
r   r   r   r   floatr  r  rq  ru  r~  rA   rB   rC   rh  rh    sS     9=6:--  - 6	-
 4- 
- 
rB   rh  originalc                     d}	 | j                  d      }t        j                  |      }|j                  d      }|S # t        $ r1}t
        j                  dj                  |       |       Y d}~|S d}~ww xY w)zO
    Convert a string to base64, via UTF-8. Returns None on invalid input.
    NUTF-8z"Unable to encode {orig} to base64:)orig)ri   base64	b64encoder   rK  r   warningr   )r  base64_string
utf8_bytesbase64_byteserrs        rC   	to_base64r  1  s     MX__W-
''
3$++G4   X;BBBQSVWWXs   7= 	A7&A22A7r  c                 &   d}	 t         j                  |       }|sJ | j                  d      }t        j                  |      }|j                  d      }|S # t        $ r1}t        j                  dj                  |       |       Y d}~|S d}~ww xY w)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  ri   r  	b64decoder   rK  r   r  r   )r  utf8_stringonly_valid_charsr  r  r  s         rC   from_base64r  A  s     K

*00?$++G4%%l3
 ''0   
188]8KS	
 	
 
s   AA 	B&BB
Components)r   r  rw   queryfragmenturlremove_authorityremove_query_valuesr  zUnion[str, Components]c           	         t        |       }t        |j                  d      }|rL|j                  j	                  d      }t        |      dkD  rt        dt        d|d   }n|j                  }n|j                  }|r(t        t        |D ci c]	  }|t         c}            }	n|j                  }	t        |j                  ||	|j                  |j                        }
|r|
S t        |
      S c c}w )zL
    Removes the authority and query parameter values from a given URL.
    T)keep_blank_valuesr  r8   rc   r   r   r  r  rw   r  )r   r   r  r  r  rd  r   r   r   r  r   rw   r  r   )r  r  r  r  
parsed_urlquery_paramsnetloc_partsr  r2  query_string
componentss              rC   sanitize_urlr  Y  s     #JJ,,EL !((..s3|q ))R F  &&F"" N#s55NO
 "''  __$$J *%%! Os   C0	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  rw   r  r  r  )r  r  r  base_urls       rC   	parse_urlr    sn     dJ $$$$	
H $$ rB   ratec           	      4   t        | t        t        f      rt        j                  |       r1t
        j                  dj                  || t        |                    yt        |       } | dk  s| dkD  r't
        j                  dj                  ||              yy)	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}.)rh  r  r'  Fr   r8   zW{source} Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)rh  r  T)
r   r   r   mathisnanr   r  r   r'  r  )r  rh  s     rC   is_valid_sample_rater    s     dT7O,

40@ K  R  RDtDz R 	

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

 rB   r  
regex_listsubstring_matchingc                 j    |y|D ]+  }|s|d   dk7  r|dz  }t        j                  ||       }|s+ y y)NFr   $Tr  )r  r  r  item_matchermatcheds        rC   match_regex_listr    sP    
 " !l2&6#&=CL))L$/ rB   r  zsentry_sdk.client.BaseClientc                     | duxrL | j                   duxr< | j                   j                  duxr" | 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    s^    
 	d 	6D(	6''t3	6 ''..#5	rB   c               #     K   	 ddl m}  t               }| j                         D ]_  }|j                  j	                  dd       }|"t        |      }|j                  :||vs?||j                  f |j                  |       a y # t        $ rM 	 dd l	}n# t        $ r Y Y y w xY w|j                  D ]%  }t        |j                        |j                  f ' Y y w xY ww)Nr   )r"  Name)	importlibr"  rF   distributionsr@   _normalize_module_namer%  r  r^  pkg_resourcesworking_setr2  )r"  yieldeddistr
  normalized_namer  infos          rC   _generate_installed_modulesr    s     A&%**, 
	1D==$$VT2D
 "8"><<+w0N)4<<77KK0
	1  A	  		 "-- 	AD(2DLL@@	AAse   C AB B B ##B C 	CBC	B#C C "B##7CC CC c                 "    | j                         S r>   )rZ   r
  s    rC   r  r     s    ::<rB   c                 0    t        j                  dd|       S )Nz[-_.]+r   )r!  subr  s    rC   1_replace_hyphens_dots_and_underscores_with_dashesr    s    66)S$''rB   c                  @    t         t        t                     a t         S r>   )_installed_modulesr   r  rA   rB   rC   _get_installed_modulesr  	  s    !!"="?@rB   packagec                     t        t        |             }t               j                         D ci c]  \  }}t        |      | }}}|j	                  |      }|y t        |      S c c}}w r>   )r  r  r  r  r@   r.  )r  normalized_packagerX  vinstalled_packagesr%  s         rC   package_versionr    sz    /9'B 01779FA 	:&A1D  !$$%78G!!s   A(c                 L    |J |j                   |ur|j                  |      |r>   )r  with_traceback)tprW   r   s      rC   r|  r|     s4    
 "$""2&&
KrB   c                       y)z.No-op function for ensure_integration_enabled.NrA   )_a_ks     rC   _no_opr  +  s    rB   c                      y r>   rA   )r   original_functions     rC   ensure_integration_enabledr  2  s     8;rB   c                      y r>   rA   )r   s    rC   r  r  8  s     >ArB   c                 ^     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()
    ```
    c                 j     d fd}t         u r t               |      S  t              |      S )Nc                  j    t        j                         j                         | i |S  | i |S r>   )r   r   get_integration)argskwargsr   r  sentry_patched_functions     rC   runnerz;ensure_integration_enabled.<locals>.patcher.<locals>.runner]  s=    $$&66{CK($9&99*D;F;;rB   )r  zP.argsr  zP.kwargsr<   r7   )r  r
   )r  r  r   r  s   ` rC   patcherz+ensure_integration_enabled.<locals>.patcher\  s8    	< &1501&99'u&'//rB   )r  Callable[P, R]r<   r  )r   r,   r   r6   r7   )r   r  r  s   `` rC   r  r  >  s,    2  !!Q$1BC
0 NrB   c                  *    t        j                         S r>   )timeperf_counter_nsrA   rB   rC   nanosecond_timer  m  s    ##%%rB   c                  B    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_patchedc                       y r>   rA   rA   rB   rC   get_gevent_hubr    s    rB   mod_namec                      yNFrA   )r  s    rC   r  r    s    rB   c                  2    t        d      xs t        d      S )Nr1  _threadr  rA   rB   rC   	is_geventr    s    [)I->y-IIrB   c                    |  	 | j                   }| j                  }|||fS 	 t               rt	               }|	 |j
                  dfS 	 t        j                         } | j                   }| j                  }|||fS 	 	 t        j                         } | j                   }| j                  }|||fS 	 y# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y ^w xY w# t        $ r Y yw xY w)zK
    Try to get the id of the current thread, with various fall backs.
    Nr  )	identr
  r   r  r  thread_identr1  current_threadmain_thread)r  	thread_idthread_name
gevent_hubs       rC   get_current_thread_metar    s0    	I ++K$ +-- % {#%
!!..44
))+LL	kk k)) !&&(LL	kk k)) ! G  		 "      	sF   B1 C  	1C =1C 1	B=<B= 	CC	CC	C*)C*r   c                 L    | t         k(  rt        |d      r|j                  dv ryy)Ncode)r   NFT)
SystemExitr]  r  )r   rW   s     rC   should_be_treated_as_errorr    s$    	ZGE62uzzY7NrB   Tc                 p    	 t        ||       r|S 	 	  | |      S # t        $ r Y w xY w# t        $ r Y y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  rK  )convert_funcrW   s     rC   try_convertr    sR    e\*L +
E""	  
  s    ) 	&&	55c                     	 	 	 	 dfd	  |       }t        |t              st        j                  |t              S |S # t        $ r t        |       cY S w xY w)z&Safely serialize to a readable string.c                    t        |       rH	 t        | dd       }t        | dd       }t        | dd      }|r
|r| d| }n|r
|r| d| }n|}d| dS t        | t              r*| j                         D ci c]  \  }}| 	|       c}}S t        | t        t        f      r| D cg c]
  } 	|       c}S t        | d	      r`	 t        |       j                         D ci c]  \  }}|j                  d
      s	| 	|      ! }}}dt        |       j                   d| dS | S # t        $ r dt        |       j                   dcY S w xY wc c}}w c c}w c c}}w # t        $ r t        |       cY S w xY w)Nr   r   r   	anonymousr   z
<function >z
<callable r   r  < )callabler;  rK  r'  r   r   r   r  r  r  r]  r  rH  r}  )
r  rX  qualnamer
  	full_pathkr  r   attrsserialize_items
            rC   r  z&safe_serialize.<locals>.serialize_item  s    D>; |T:"4>tZ=h#)(!H: 6I#)(!D6 2I $I#I;a00 d#59ZZ\BTQA~a((BBtUm,/34!N1%44T:&" !%T
 0 0 21<<, ~a(( 
 4:../qq99 K#  ;#DJ$7$7#8::; C4  "Dz!"sB   AD) 8E)EE" $$EE" )"EEE" "E98E9r:   )r  r   r<   z6Union[str, dict[Any, Any], list[Any], tuple[Any, ...]])r   rY   rg   rh   rK  )r`   
serializedr  s     @rC   safe_serializer    sn    ""	A"H#D)
 j#. JJz3/	
 	

  4ys   2A  A AArs  Optional[dict[str, Any]]c                 l    | yt        | j                  dd      xs | d   j                  dd            S )NFenable_logs_experimentsr]   r@   rs  s    rC   has_logs_enabledr     s?    M5) 	=>"&&}e< rB   c                 V    | y | j                  d      xs | d   j                  d      S )Nbefore_send_logr  r@   r  s    rC   get_before_send_logr$    s8     ;;() W^-D-H-H. rB   c                 >    | yt        | j                  dd            S )NFenable_metricsTr  r  s    rC   has_metrics_enabledr'  %  s!    ,d344rB   c                 V    | y | j                  d      xs | d   j                  d      S )Nbefore_send_metricr  r#  r  s    rC   get_before_send_metricr*  ,  s8     ;;+, 0G0K0K1 rB   c                    t        | t        t        t        t        f      r| S t        | t
        t        f      r| sg S t        | t
              rOt        | d         t        t        t        t        fv r~t        fd| D              rjt        j                  |       S t        | t              rEt        | 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   8   K   | ]  }t        |      u   y wr>   r'  r1  r  r   s     rC   r3  z#format_attribute.<locals>.<genexpr>I       0L1aB0L   c              3   8   K   | ]  }t        |      u   y wr>   r-  r.  s     rC   r3  z#format_attribute.<locals>.<genexpr>M  r/  r0  )r   r]   r  r  rY   r  r  r'  allr  deepcopyrz  valr   s    @rC   format_attributer6  7  s     #c5#./
#e}%c		C	#a&\#sE4((S0L0L-L==%%	C	#a&\#sE4((S0L0L-L9S>rB   c                 t   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
              rF| 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)rW   r'  integerdoubler  arrayr   c              3   8   K   | ]  }t        |      u   y wr>   r-  r.  s     rC   r3  z&serialize_attribute.<locals>.<genexpr>d  r/  r0  )	r   r]   r  r  rY   r  r'  r2  rz  r4  s    @rC   serialize_attributer=  S  s    #ti00#si00#uh//#sh//#t11 #a&\#sD%((S0L0L-L '22 s^X66rB   )r<   zGenerator[None, None, None])rW   r   rV   zOptional[bool]r<   zbool | None)r<   rk   r   )r   r2   r<   Nr>   )r   zOptional[ExcInfo]r<   zDict[str, Optional[ExcInfo]])r<  r8  r<   rk   )r   r   r<   zIterator[TracebackType])NNN)rC  r   rq  rV  rr  rV  r<   rY  )rX  rk   rw  rk   r<   rk   )NTTNN)TTN)NNNNNN)r  r8  r  r   r   r   r  r  r  r  r  rV  r  rV  rh  rk   r  r  r<   r  )r   r2   r<   zIterator[ExcInfo])NNr   r   NNNN)
r   r2   r  r  r  r  r  r  r<   List[Dict[str, Any]])r  r1   r<   z#Iterator[Annotated[Dict[str, Any]]])r  r1   r<   zIterator[Dict[str, Any]])
r  r1   r  r  r  r  r  rk   r<   r1   )
r  r   r  r  r  r  r  rk   r<   r   )r   Union[BaseException, ExcInfo]r<   r2   )r  r>  r  r>  r  r  r<   r>  r  )r   r?  r  r  r  r  r<   zTuple[Event, Dict[str, Any]])r<   zTuple[bool, type])r\  zCallable[..., Any]r<   rk   )TTF)Tr  )r<   zIterator[Tuple[str, str]])r<   zDict[str, str])r  r   rW   r   r   r   r<   r$   )r  r   r  r   r<   N)r   )type[sentry_sdk.integrations.Integration]r  r  r<   *Callable[[Callable[P, R]], Callable[P, R]])r   r@  r<   z0Callable[[Callable[P, None]], Callable[P, None]])r   r@  r  z(Union[Callable[P, R], Callable[P, None]]r<   rA  )r<   zOptional[Hub])r  zOptional[threading.Thread]r<   z#Tuple[Optional[int], Optional[str]])r
  zCallable[[Any], T]rW   r   r<   zOptional[T])rs  r  r<   z.Optional[Callable[[Log, Hint], Optional[Log]]])rs  r  r<   z4Optional[Callable[[Metric, Hint], Optional[Metric]]])r5  r   r<   r/   )r5  r/   r<   r0   )r  r6  rg   r`  loggingr  rv   r  rN  r!  r{   ry   r1  r  collectionsr   
contextlibr   r   r   decimalr   	functoolsr   r	   r
   numbersr   urllib.parser   r   r   r   r   r?  r   r^  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  r7  r?   r]   rD   rI   r"  r  	frozensetr[   r\   r  r_   bytesrj   r   r   rY   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r  r=  rB  rM  rR  r  rp  rx  r{  rz  r  r  r  r   r  r  r  r]  rK  HAS_CHAINED_EXCEPTIONSr  r  r  r  r  r  r  r  r   r  r	  r  r  r  r  r  re  r.  rB  r'  rT  rW  HAS_REAL_CONTEXTVARSCONTEXTVARS_ERROR_MESSAGEra  rc  rd  rf  rn  rh  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r|  r  r  r  r  r9  r  r  r:  r  r  r  r  r  r  r  r   r$  r'  r*  r6  r=  rA   rB   rC   <module>rU     s
         	   	  
   " % '  3 3  K K+
 !  # R R  .    (    	#AA 	q! 
		.	/ 1;11u 
*$ * . . "**12BC BC   =B +TU Tu T
62     F $ 78 'H+
 +u +	5J 	53 	5 j) +3 +: +, %)
"!
"#
""Z "L
 L
^+R +R\P[ T $ #'""***  * 	*
 * S*` )- & S	6 E  c  U s '66 "&$(#'(,<@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L !,BC 7> 26,0"377;/3H&H&(H& 	"H& /	H&
 *H& H& H& H& 1H& 5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f0 0f $ 8"7J $4#5   j @( ##:; 	y 	B
I$$ B
J   s  * &WX

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