
    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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,m-Z-m.Z.m/Z/ e#rTd dl0m1Z1m2Z2 d dl"m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB d dlCmDZD d dl'mEZEmFZFmGZGmHZHmIZImJZJmKZK  e;d      ZL e?d      ZM eddd      ZN ej                  d      ZPdaQ ej                  d      ZS eTd      ZU eTd      ZVdZW	 ddddZXd ddeYfd!ZZdd#Z[dd$Z\d%d&de]fd'Z^ G d( d)      Z_ e_       Z`dd*Zadd+Zbdd,decfd-Zddd,de]fd.Ze eTd/      Zfde]dd,fd0Zg	 d	 	 	 dd1Zh G d2 d3ei      Zj G d4 d5      Zk G d6 d7      Zldd9Zmdd:Znd;d<deofd=Zpdd@Zq	 	 	 ddAe]dBerdCdDdEdFdGd"ddHfdIZs	 d	 	 	 	 	 	 	 ddLZtddde]fdMZuddde]fdNZv	 	 	 	 	 	 ddPZw	 	 	 	 	 dd;d<dJdDdQeodReodKdDdSdTddUfdVZx	 	 	 ddQeodReodKdDddUfdWZydXezddFfdYZ{dXdZde]fd[Z|	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeZ} e~edf      ZerddgZnddhZ	 	 	 	 	 	 dd\d8dXdZd>d?d]d^d_d^d`erdaerdbd"dcddddifdjZ	 	 	 d	 	 	 	 	 	 	 	 	 ddkZde]de]fdlZddmZddnZ	 	 	 d	 	 	 	 	 	 	 	 	 ddqZ	 d	 	 	 	 	 	 	 	 	 ddrZddsZ	 	 	 	 	 	 	 	 ddtZ	 	 d	 	 	 	 	 	 	 dduZdvd"dwdodeofdxZdOd"deofdyZdOd"dpd"deofdzZd{e]d|erde]fd}Zde]ddDfd~Z	 dde]dCdDddfdZde]ddfdZdeofdZdedefdZddZ e       \  ZZdZddZddZ ed      Z G d de      Z G d dej<                        Zde]dd"fdZde]dd"fdZ edg d      Z	 	 	 dde]deodeodeoddf
dZ edg d      Zdde]deoddfdZdddbe]deofdZ	 	 dde]ddodeodeofdZddde]deofdZddZdve]de]fdZdve]de]fdZddZde]ddfdZ	 d	 	 	 	 	 	 	 ddZddZe#reB	 	 	 	 	 	 dd       ZeB	 	 	 	 dd       Zef	 	 	 	 	 ddZe&rderfdZnderfdZdecfdZ	 d dlmZ d dlmZ deofdZ	 d	 	 	 ddZdddddeofdZe#r e?d      ZddZd dde]fdZdddeofdńZ	 	 	 	 ddƄZdddeofdǄZ	 	 	 	 ddȄZddɄZddʄZy# e!$ r dZ Y Kw xY w# e!$ r ddZde]deofdZY yw xY w)    N)
namedtuple)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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.errorsz^[a-zA-Z0-9/+=]*$)falsefnnooff0)truetyyeson1i  F)strictvaluer   returnc                ~    | 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)rD   rC   
normalizeds      i/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/sentry_sdk/utils.pyenv_to_boolrN   c   sF     (-'8U!!#dJ%%&&4*tE{*    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)rP   s    rM   
json_dumpsrZ   r   s     ::de
CJJ7SSrO   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   rV   )openospathdevnullsysplatform
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWPopenPIPEcommunicatestripdecodeOSErrorIOErrorFileNotFoundError)nullra   revisions      rM   get_git_revisionry   w   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)rf   environgetry   )releasevars     rM   get_default_releaser      sZ    jjnn-.G G **..%N rO   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      rM   get_sdk_namer      s5    
. .00%,,[99 . rO   c                   0    e Zd ZdZddZdddddd	defd
Zy)CaptureInternalException rE   c                     | S Nr   selfs    rM   	__enter__z"CaptureInternalException.__enter__   s    rO   tyOptional[Type[BaseException]]rD   Optional[BaseException]tbOptional[TracebackType]c                 (    ||t        |||f       y)NT)capture_internal_exception)r   r   rD   r   s       rM   __exit__z!CaptureInternalException.__exit__   s     >e/&E27rO   NrE   zContextManager[Any])__name__
__module____qualname__	__slots__r   rK   r   r   rO   rM   r   r      s7    I	+	 )	 &		
 
	rO   r   c                      t         S r   )_CAPTURE_INTERNAL_EXCEPTIONr   rO   rM   capture_internal_exceptionsr      s    &&rO   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    rM   r   r      s/     ((*3hG +rO   r   c                 0    | t         z
  j                         S r   )epochtotal_secondsrD   s    rM   to_timestampr      s    EM((**rO   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)rD   utctimes     rM   format_timestampr      s,    
 x||,G 344rO   )+-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   )rD   resulttimestamp_formats      rM   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   )ri   r   exc_info_from_errorr   s    rM   event_hint_with_exc_infor     s9     <<>&x0{!!rO   c                       e Zd ZdZy)BadDsnzRaised on invalid DSNs.Nr   r   r   __doc__r   rO   rM   r   r   '  s    !rO   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+)\.NrE   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 hostnamer6   r     P   zMissing public key/zInvalid project in DSN (%r) )
isinstancer   dict__dict__r   rG   schemer   hostnamehostorg_idORG_ID_REGEXmatchgroupportusername
public_keypassword
secret_keyrg   rsplitintpop
project_idr   	TypeErrorjoin)r   rD   r   partsorg_id_matchrg   s         rM   __init__zDsn.__init__0  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   rS   )r   r   r   r   rvs     rM   netlocz
Dsn.netloc[  s6     YYKK#+II		*B	rO   c           	          t        | j                  | j                  | j                  | j                  | j
                  | j                  |      S )z*Returns the auth info object for this dsn.)r   r   rg   r  r   r   client)Authr   r
  rg   r  r   r   )r   r  s     rM   to_authzDsn.to_authc  s<    ;;
 	
rO   c                     | j                   d| j                  | j                  xr d| j                  z   xs dd| j                  | j                  | j
                  S )N://@r   )r   r   r   r
  rg   r  r   s    rM   __str__zDsn.__str__o  sL    KKOOOO5doo 5;;KKIIOO
 	
rO   r   )rD   zUnion[Dsn, str]r   r[   rE   N)r  Optional[Any]rE   r  )r   r   r   r   recompiler   r  propertyrG   r
  r  r  r   rO   rM   r   r   +  sf    2::l+L CG))&))0?))	))V   


 
rO   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   r[   versionr  r  rg   rE   c	                 t    || _         || _        || _        || _        || _        || _        || _        || _        y r   )r   r   rg   r  r   r   r  r  )	r   r   r   r  r   r   r  r  rg   s	            rM   r  zAuth.__init__}  s<     		$$$rO   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   rg   r  rD   )r   r  s     rM   get_api_urlzAuth.get_api_url  s1     KKIIIIOOJJ
 	
rO   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)=Nr   ).0keyrD   s      rM   	<genexpr>z!Auth.to_header.<locals>.<genexpr>  s     $Qb
UU%;bs   )r   r  r  appendr   r  r  s     rM   	to_headerzAuth.to_header  sw    T__-0@$,,/OP;;"II45??&II89499$Qb$QQQQrO   )N   Nr   )r   r   r   r   rG   r   r  r   ENVELOPEr  r(  r   rO   rM   r  r  z  s    6 '+"&  	
  $     
,  ,44

 

R3 RrO   r  Optional[type]c                 :    t        | dd       xs t        | dd       S )Nr   r   getattr)clss    rM   get_type_namer0    s    3-Oj$1OOrO   c                 *    t        | dd       }|dvr|S y )Nr   )Nbuiltins__builtins__r-  )r/  mods     rM   get_type_moduler5    s!    
#|T
*C
44
rO   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)r6  r4  	flag_names      rM   should_hide_framer@    s    ooj)>>-( )
 ?		~~i( ) ?  H%   		s     > AAA	AAr   r   c              #   f   K   | }|)t        |j                        s| |j                  }|(y y wr   )r@  tb_frametb_next)r   tb_s     rM   iter_stacksrE    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   r6   z
)rH  )hasattrrO  ImportErrorru   
splitlines	linecachegetlinesrt   maxminlenstrip_stringrr   
IndexError)rF  rG  rH  rJ  rK  context_linessource
source_strlower_boundupper_boundlinepre_contextcontext_linepost_contexts                 rM   get_lines_from_filerc    s    MFgfl;	*0*;*;F*CJ !**,F~	 ''1F 4|a-/0Kfqj=0#f+>K {62
2 F+
C2 	 
 $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__r6   )rJ  rK  )f_codeco_filenamer>  r:  rc  )r6  rd  re  abs_pathrK  rJ  rG  s          rM   get_source_contextrk    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   )rG   r>  	safe_reprr   s    rM   safe_strrn    s+     5z   s   
 $$c                 8    	 t        |       S # t        $ r Y yw xY w)Nz<broken repr>)reprr>  r   s    rM   rm  rm    s#    E{ s   
 	rj  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   r6   r      )r   splitrf   rg   basenameri   modules__file__r   seplstripr>  )rK  rj  base_modulebase_module_paths       rM   filename_for_moduler{  #  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)Nrh  r   z	<unknown>)rF  rj  functionrK  rG  r`  ra  rb  r   )	serializeT)is_varsr~  vars)r.  rh  ri  co_namer:  r>  f_linenorf   rg   abspathr{  rk  sentry_sdk.serializerr  r   r=  )r6  rd  r|  r}  re  r~  rh  rj  r  rK  os_abs_pathr	  r  s                rM   serialize_framer  <  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}  re  frames)ri   	_getframer@  r'  r  f_backreverse)r|  r}  re  r9  r  r8   s         rM   current_stacktracer  o  sp    
 F"}}A
- #MM,C+A%5	 HH - NNfrO   	exc_valuec                     t        | dd       S )Nerrnor-  )r  s    rM   	get_errnor    s    9gt,,rO   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   rG   )r$  notes     rM   r&  z$get_error_message.<locals>.<genexpr>  s     #TUTjs>SDUs   )rn  r.  r   listrW  r  )r  r  notess      rM   get_error_messager    s}    	9b) 	9h+	IG I{D9E%3u:>4$))#TU#TTTTNrO   exc_typeclient_optionsOptional[Dict[str, Any]]	mechanismexception_id	parent_idr[  
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  numberr[  r   r  chainedr  is_exception_grouprK  rD   r|  r}  re  r~  r6   )rd  r|  r}  re  r~  r   
stacktracer  )copyr  
setdefaultr   r   r5  r0  r  r   r   ziprE  rangeMAX_STACK_FRAMESr  rB  rd  rW  r   removed_because_over_size_limitmerge_stack_frames)r  r  r   r  r  r  r  r[  r  exception_valuer  is_root_exceptionr  r|  r}  re  r~  _r  
new_framess                       rM   !single_exception_from_error_tupler    se   " )+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& GEB 	KKll$;#9-#	
 G  & 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__)	setidr'  addr  	__cause____context__r  r.  )r   r  r  r   seen_exceptionsseen_exception_idscauses          rM   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   r   r   s    rM   r  r  (  s     s   z Tuple[int, List[Dict[str, Any]]]c	                     t        | ||||||||	      }	|	g}
|}|dz  }t        |d      xr |j                  }|rj|xr t        |d      xr |j                  du}|r|j                  }t	        t        |      |t        |dd      |||d|      \  }}|
j                  |       ni|xr t        |d      xr |j                  du}|rG|j                  }t	        t        |      |t        |dd      |||d|      \  }}|
j                  |       |xr t        |d	      }|r\t        |j                        D ]D  \  }}t	        t        |      |t        |dd      ||||d
|z  |	      \  }}|
j                  |       F ||
fS )z
    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/
    )	r  r  r   r  r  r  r  r[  r  r6   r  r  Nr  )r  r  r   r  r  r  r[  r  r  
exceptionszexceptions[%s])r  rP  r  r  exceptions_from_errorr  r.  extendr  	enumerater  )r  r  r   r  r  r  r  r[  r  parentr  should_supress_contextexception_has_causer  child_exceptionsexception_has_contentcontextr  idxes                       rM   r  r  ,  s   & /%!
F JIAL 		12Uy7U7U    0	;/0##4/ 	
 ''E/De5/48-#)"%	0,\+ ./  2	=12%%T1 	
 !++G/Dg!7OT:-#)$%	0,\+ ./ #Gwy,'G	 4 45FC/Da1ot4-#)#'#-%
0,\+ ./ 6 *%%rO   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  r'  r  r  )
r   r  r  r  r  r  r   r  r  r  s
             rM   exceptions_from_error_tupler    s     'Hi+47 J%= /)!	
J 
';H'E#Hi1%'#1')	 (F rO   c                 T    	 t        |       S # t        $ r t        |       dd cY S w xY w)Nr6   r   )rG   UnicodeDecodeErrorrp  r   s    rM   	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valuesr   	exception)r   r   r   )eventthreadr  s      rM   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  r   )r  r   r   rD   r   )r  r  r6  s      rM   iter_event_framesr    sO     ,U3
j.1#))/RJ^^H-33EK 4	 4s   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   rD   set_in_app_in_framesr   )r  r  r  r  r  s        rM   handle_in_appr    sQ     -U3
j.1#))/RJNN8$))%		
	 4 LrO   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_apprK  TFrj  )r   _module_in_list_is_external_source_is_in_project_root)r  r  r  r  r6  current_in_apprK  rj  s           rM   r  r    s     8,%8$ 6>2"E(O 6>2#E(O 99Z(x(#E(Ox6"E(O; > MrO   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   tuplerW  BaseExceptionr.  r  ri   r   r   r   r*   r0   )r   r  r  r   r   s        rM   r   r     s    %CJ!O"')R	E=	)UOT2>E{HI&)lln#Hi%!	; G$u+UVV)R(H *OrO   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.
    rj  ra  rG  r  max_stack_framesN)r  r   r   rW  )r  r  r  r6  	frame_ids
stackframer  r  s           rM   r  r  5  s      E *.!(O*		
    %
$Jz"~&x z"	
  	$  
 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|  re  )r|  re  r  r   r  )levelr  )r   r   r   r   r  r  )r   r  r  hintr  s        rM   event_from_exceptionr  `  s    
 #8,H#H-D.,,-=?UV'$23L$M+,>?
 

 
 5ni	
 	
 
rO   nameitemsc                 T    | y|sy|D ]  }|| k(  s| j                  |dz         s y y)NFr   Tr;  )r  r  items      rM   r  r  }  s8    |4<4??4#:6  rO   c                 <    | yt        j                  d|       d u}|S )NFz [\\/](?:dist|site)-packages[\\/]r  search)rj  external_sources     rM   r  r    s.     			5x@L  rO   c                 2    | |y| j                  |      ryy)NFTr  )rj  r  s     rM   r  r    s(     </ <(rO   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.
    rV   Nr  ignore)errors...)rY   rs   )r  r	  	truncateds      rM   _truncate_by_bytesr    s8     g&Q7>>wx>XIurO   c                 b    	 t        | j                  d            S # t        t        f$ r Y y w xY w)NrV   )rW  rY   UnicodeEncodeErrorr  r   s    rM   _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)rW  rem)rD   metadata)r   r  rW  r  r   )rD   rH  	byte_size	text_sizetruncated_values        rM   rX  rX    s     -
"5)IE
IZ!7,UJ?		9z#9 0*q.1E9)	sJNJ?@
 rO   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   rs  r  r   r   )r  VERSION_PATTERNpatternr   release_tuples        rM   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|\.rr  	threadinglocalr  r)  )   	   contextvars
ContextVarFT)is_monkey_patchedzYInternal error in Sentry SDK: Could not parse Greenlet version from greenlet.__version__.r  )r   rN  )geventgevent.monkeyr$  r  r  rs  __version__r   ri   version_inforQ  greenleteventlet.patcherr,  r"  r   r   )r-  r$  partversion_tupler1  r,  greenlet_versions          rM   _is_contextvars_brokenr6    s    3 #%88L&:L:L#Mbq#QR#Q4SY#Q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#r&  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  defaultr   rE   c                 R    || _         || _                | _                | _        y r   )_name_default_local_original_local)r   r  r:  r&  s      rM   r  z:_make_threadlocal_contextvars.<locals>.ContextVar.__init__;  s$    DJ#DM'DK#(7D rO   c                 L    t        | j                  d|xs | j                        S )NrD   )r.  r>  r=  )r   r:  s     rM   r   z5_make_threadlocal_contextvars.<locals>.ContextVar.getA  s    4;;1IDMMJJrO   c                     t        t        j                  d            }| j                         }t	        | j
                  ||       || j                  _        |S )N@   )rG   randomgetrandbitsr   setattrr?  r>  rD   )r   rD   tokenoriginal_values       rM   r  z5_make_threadlocal_contextvars.<locals>.ContextVar.setD  sE    **2./E!XXZND((%@ %DKKLrO   c                 |    t        | j                  |      | j                  _        | j                  j                  |= y r   )r.  r?  r>  rD   r   )r   rF  s     rM   resetz7_make_threadlocal_contextvars.<locals>.ContextVar.resetK  s/     '(<(<e DDKK$$--e4rO   r   )r:  r   rE   r   )rD   r   rE   r   )rF  r   rE   N)r   r   r   rG   r  r   r  rI  r&  s   rM   r+  r9  8  s-    	+ 	+u 	+ 	+	K		5rO   r+  r   )r&  r+  s   ` rM   _make_threadlocal_contextvarsrK  7  s    5 50 rO   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.
    r'  r   )r+  TrJ  F)
r6  ri   r0  aiocontextvarsr+  rQ  r*  r%  r&  rK  )r+  r&  s     rM   _get_contextvarsrN  S  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}	 | j                   j                  d| j                   j                  d| j                  S # t        $ r Y nw xY w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.Nr   )r   r   r   )zpartial(<function >)_partialmethod__partialmethod__)zpartialmethod(<function rP  r   r   )im_classr   r   r>  r   r   rP  funcr.  r   r   rG   )rT  func_qualnameprefixsuffixpartial_methods        rM   qualname_from_functionrY    s4   %)MMM$$MM""MM
 	

   NFF$ WTYY
%C3yy !'7> 
'%tC
 nm4=NFF!&&Dt^$))	z	"  4&:doos+K OOc1MAM.7s   ;A   	AAc                     t        |       S r   )rY  )rT  s    rM   transaction_from_functionr[    s    !$''rO   disable_capture_eventc                       e Zd ZdZy)ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nr   r   rO   rM   r^  r^    s    HrO   r^  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_scoperE   c                     t         j                  j                  |        || _        || _        || _        || _        t        j                         | _        y r   )	r%  Threadr  ra  rb  rc  rd  r/   _stop_event)r   ra  rb  rc  rd  s        rM   r  zTimeoutThread.__init__  sG     	!!$'("4.*$??,rO   c                 8    | j                   j                          y r   )rg  r  r   s    rM   stopzTimeoutThread.stop  s    rO   c                     t        j                         }t        j                         }t	        ||j
                  ddd      \  }}t        j                  ||       |S )Nr%  Fr  )r  r  )r  )ri   r   r   r   r  optionscapture_event)r   r   r  r  r  s        rM   _capture_exceptionz TimeoutThread._capture_exception  sR    <<>&&(*!>>*u=
t
 	  T2rO   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)Nr6   zZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)rg  waitra  is_setr   rb  rc  rd  r   scopeuse_isolation_scope	use_scoper^  r   r>  reraiserm  )r   integer_configured_timeouts     rM   runzTimeoutThread.run  s,   d//0""$%()@)@%A" &(?(??)Ca)G& +0B0B0N!!55d6J6JK%%//0B0BC<6x :  'hoo*
 	
 % <!8!8!:;<; DCC LKKsB   +*ED:DD-*D:,D--D:1	E:E	?EENN)rE   N)rE   r0   )
r   r   r   r   floatr   r  ri  rm  rv  r   rO   rM   r`  r`    sS     9=6:--  - 6	-
 4- 
- 
rO   r`  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)rY   base64	b64encoders   r>  r   warningr   )ry  base64_string
utf8_bytesbase64_byteserrs        rM   	to_base64r    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   rY   r}  	b64decoders   r>  r   r  r   )r  utf8_stringonly_valid_charsr  r  r  s         rM   from_base64r    s     K

*00?$++G4%%l3
 ''0   
188]8KS	
 	
 
s   AA 	B&BB
Components)r   r
  rg   queryfragmenturlremove_authorityremove_query_valuesrs  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  r6   rS   r   r   r
  r  rg   r  )r   r   r  r
  rs  rW  r   r   r   r  r   rg   r  r   )r  r  r  rs  
parsed_urlquery_paramsnetloc_partsr
  r%  query_string
componentss              rM   sanitize_urlr  )  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  rs  r   r  r  )	r  r   r  r   r
  rg   r  r  r  )r  r  r  base_urls       rM   	parse_urlr  \  sn     dJ $$$$	
H $$ rO   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}.)r[  r  r  Fr   r6   zW{source} Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)r[  r  T)
r   r
   r   mathisnanr   r  r   r  rx  )r  r[  s     rM   is_valid_sample_rater  w  s     dT7O,

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

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

 rO   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        rM   match_regex_listr    sK    
 "!l2&6#&=CL))L$/ # rO   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     rM   is_sentry_urlr    s^    
 	d 	6D(	6''t3	6 ''..#5	rO   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  r  distributionsr   _normalize_module_namer  r  rQ  pkg_resourcesworking_setr%  )r  yieldeddistr  normalized_namer  infos          rM   _generate_installed_modulesr    s     A&%**,D==$$VT2D
 "8"><<+w0N)4<<77KK0 -  A	  		 "--D(2DLL@@ .Ase   C AB B B ##B C 	CBC	B#C C "B##7CC CC c                 "    | j                         S r   )rH   r  s    rM   r  r    s    ::<rO   c                 0    t        j                  dd|       S )Nz[-_.]+r   )r  subr  s    rM   1_replace_hyphens_dots_and_underscores_with_dashesr    s    66)S$''rO   c                  @    t         t        t                     a t         S r   )_installed_modulesr   r  r   rO   rM   _get_installed_modulesr    s    !!"="?@rO   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_packagerK  vinstalled_packagesr  s         rM   package_versionr    s|    /9'B 017799IFA 	:&A1D9   !$$%78G!!s   A(c                 L    |J |j                   |ur|j                  |      |r   )r  with_traceback)tprD   r   s      rM   rt  rt    s4    
 "$""2&&
KrO   c                       y)z.No-op function for ensure_integration_enabled.Nr   )_a_ks     rM   _no_opr    s    rO   c                      y r   r   )r   original_functions     rM   ensure_integration_enabledr    s     8;rO   c                      y r   r   )r   s    rM   r  r    s     >ArO   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     rM   runnerz;ensure_integration_enabled.<locals>.patcher.<locals>.runner-  s=    $$&66{CK($9&99*D;F;;rO   )r  zP.argsr  zP.kwargsrE   r5   )r  r	   )r  r  r   r  s   ` rM   patcherz+ensure_integration_enabled.<locals>.patcher,  s8    	< &1501&99'u&'//rO   )r  Callable[P, R]rE   r  )r   r*   r   r4   r5   )r   r  r  s   `` rM   r  r    s,    2  !!Q$1BC
0 NrO   c                  *    t        j                         S r   )timeperf_counter_nsr   rO   rM   nanosecond_timer  =  s    ##%%rO   c                  B    t        t        j                         dz        S )Ng    eA)r   r  perf_counterr   rO   rM   r  r  B  s    4$$&,--rO   c                  *    t        j                         S r   )r  r  r   rO   rM   nowr  F  s    rO   )get_hubis_module_patchedc                       y r   r   r   rO   rM   get_gevent_hubr  P  s    rO   mod_namec                      yNFr   )r  s    rM   r  r  S  s    rO   c                  2    t        d      xs t        d      S )Nr%  _threadr  r   rO   rM   	is_geventr  X  s    [)I->y-IIrO   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.
    Nrw  )	identr  r   r  r  thread_identr%  current_threadmain_thread)r  	thread_idthread_name
gevent_hubs       rM   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)
SystemExitrP  r  )r   rD   s     rM   should_be_treated_as_errorr    s$    	ZGE62uzzY7NrO   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  r>  )convert_funcrD   s     rM   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.  r>  r  r   r   r   r  r  r  rP  r  r;  rp  )
r  rK  qualnamer  	full_pathkr  r  attrsserialize_items
            rM   r  z&safe_serialize.<locals>.serialize_item  s    D>; |T:"4>tZ=h#)(!H: 6I#)(!D6 2I $I#I;a00 d#59ZZ\B\TQA~a((\BBtUm,/34t!N1%t44T:&" !%T
 0 0 2 21<<, ~a(( 2  
 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   rE   z6Union[str, dict[Any, Any], list[Any], tuple[Any, ...]])r   rG   rW   rX   r>  )rP   
serializedr  s     @rM   safe_serializer    sn    ""	A"H#D)
 j#. JJz3/	
 	

  4ys   2A  A AArk  Optional[dict[str, Any]]c                 l    | yt        | j                  dd      xs | d   j                  dd            S )NFenable_logs_experimentsrK   r   rk  s    rM   has_logs_enabledr    s?    M5) 	=>"&&}e< rO   c                 V    | y | j                  d      xs | d   j                  d      S )Nbefore_send_logr  r   r  s    rM   get_before_send_logr    s8     ;;() W^-D-H-H. rO   c                 >    | yt        | j                  dd            S )NFenable_metricsTr  r  s    rM   has_metrics_enabledr    s!    ,d344rO   c                 V    | y | j                  d      xs | d   j                  d      S )Nbefore_send_metricr  r  r  s    rM   get_before_send_metricr"    s8     ;;+, 0G0K0K1 rO   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  r$  r  r   s     rM   r&  z#format_attribute.<locals>.<genexpr>       0L1aB   c              3   8   K   | ]  }t        |      u   y wr   r%  r&  s     rM   r&  z#format_attribute.<locals>.<genexpr>  r'  r(  )r   rK   r   rx  rG   r  r  r  allr  deepcopyrm  valr   s    @rM   format_attributer.    s     #c5#./
#e}%c		C	#a&\#sE4((S0L0L-L==%%	C	#a&\#sE4((S0L0L-L9S>rO   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)rD   r  integerdoubler  arrayr   c              3   8   K   | ]  }t        |      u   y wr   r%  r&  s     rM   r&  z&serialize_attribute.<locals>.<genexpr>4  r'  r(  )	r   rK   r   rx  rG   r  r  r*  rm  r,  s    @rM   serialize_attributer5  #  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6rO   )rD   r   rC   zOptional[bool]rE   zbool | None)rE   r[   r   )r   r0   rE   Nr   )r   zOptional[ExcInfo]rE   zDict[str, Optional[ExcInfo]])r/  r+  rE   r[   )r   r   rE   zIterator[TracebackType])NNN)r6  r   rd  rI  re  rI  rE   rL  )rK  r[   rj  r[   rE   r[   )NTTNN)TTN)NNNNNN)r  r+  r  r   r   r   r  r  r  r  r  rI  r  rI  r[  r[   r  r  rE   r  )r   r0   rE   zIterator[ExcInfo])NNr   r   NN)
r   r0   r  r  r  r  r  r  rE   List[Dict[str, Any]])r  r/   rE   z#Iterator[Annotated[Dict[str, Any]]])r  r/   rE   zIterator[Dict[str, Any]])
r  r/   r  r  r  r  r  r[   rE   r/   )
r  r   r  r  r  r  r  r[   rE   r  )r   Union[BaseException, ExcInfo]rE   r0   )r  r6  r  r6  r  r  rE   r6  rw  )r   r7  r  r  r  r  rE   zTuple[Event, Dict[str, Any]])rE   zTuple[bool, type])rT  zCallable[..., Any]rE   r[   )TTF)Tr  )rE   zIterator[Tuple[str, str]])rE   zDict[str, str])r  r   rD   r   r   r  rE   r"   )r  r   r  r   rE   N)r   )type[sentry_sdk.integrations.Integration]r  r  rE   *Callable[[Callable[P, R]], Callable[P, R]])r   r8  rE   z0Callable[[Callable[P, None]], Callable[P, None]])r   r8  r  z(Union[Callable[P, R], Callable[P, None]]rE   r9  )rE   zOptional[Hub])r  zOptional[threading.Thread]rE   z#Tuple[Optional[int], Optional[str]])r  zCallable[[Any], T]rD   r   rE   zOptional[T])rk  r  rE   z.Optional[Callable[[Log, Hint], Optional[Log]]])rk  r  rE   z4Optional[Callable[[Metric, Hint], Optional[Metric]]])r-  r   rE   r-   )r-  r-   rE   r.   )r}  rW   rS  loggingr  rf   r  rC  r  rk   ri   r%  r  collectionsr   r   r   decimalr   	functoolsr   r   r	   numbersr
   urllib.parser   r   r   r   r   r2  r   rQ  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+   
gevent.hubr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r   	getLoggerr   r  r  r  	frozensetrI   rJ   r  rN   bytesrZ   ry   r   rG   r   r   r   r   r   rx  r   r   r   r   r   r   r   r   r  r0  r5  rK   r@  rE  r   rc  rk  rn  rm  r{  r  r  r  r  r  r  rP  r>  HAS_CHAINED_EXCEPTIONSr  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  rX  r"  r6  r  rK  rN  HAS_REAL_CONTEXTVARSr+  CONTEXTVARS_ERROR_MESSAGErY  r[  r\  r^  rf  r`  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rt  r  r  r  r  r-  r  r  r.  r  r  r  r  r   r  r  r  r  r  r"  r.  r5  r   rO   rM   <module>rL     s@
        	   	  
   " '  3 3  K K+
 !  # R R  .    &    	#AA 	q! 
		.	/ "**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"37c&c&(c& 	"c& /	c&
 *c& c& c& c& 1c& (c&P 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 (V( ##:; 	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7W@  j9  C D s$   (R/ R= /R:9R:=SS