
    tnif                     
   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 n# e $ r dZY nw xY wd d	l!m"Z" d dl#Z#d d
l$m%Z% d dl&m'Z'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z. e"r\d dl/m0Z0m1Z1 d dl!m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m: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jO        d          ZPdaQ ejR        d          ZS eTd          ZU eTd          ZVdZW	 dddd"ZXd#dd eYfd$ZZd d&Z[d d'Z\d(d)d e]fd*Z^ G d+ d,          Z_ e_            Z`dd.Zadd1Zbdd2d ecfd3Zddd2d e]fd4Ze eTd5          Zfde]d d2fd6Zg	 d	 	 	 dd9Zh G d: d;ei          Zj G d< d=          Zk G d> d?          ZlddBZmddCZndDdEd eofdFZpddJZq	 	 	 ddKe]dLerdMdNdOdPdQd%d dRfdSZs	 d	 	 	 	 	 	 	 ddVZtddd e]fdWZuddd e]fdXZv	 	 	 	 	 	 d	dZZw	 	 	 	 	 d
dDdEdTdNd\eod]eodUdNd^d_d d`fdaZx	 	 	 dd\eod]eodUdNd d`fdbZydcezd dPfddZ{dcded e]fdfZ|	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddpZ} e~edq          ZerddsZnddtZ	 	 	 	 	 	 ddgdAdcdedGdHdhdidjdidkerdlerdmd%dndod dufdvZ	 	 	 d	 	 	 	 	 	 	 	 	 ddxZde]d e]fdyZdd}ZddZ	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZdd%ddd eofdZdYd%d eofdZdYd%dd%d eofdZde]derd e]fdZde]d dNfdZ	 dde]dMdNd dfdZde]d dfdZd eofdZded efdZddZ e            \  ZZdZddZdd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	 	 	 dde]deodeodeod df
dZ edg d          Zdde]deod dfdZdddme]d eofdZ	 	 dde]dddeod eofdZddde]d eofdZddĄZde]d e]fdńZde]d e]fdƄZddȄZde]d dfdʄZ	 d	 	 	 	 	 	 	 d d΄Zd!dфZe"r$eB	 	 	 	 	 	 d"dׄ            ZeB	 	 	 	 d#dل            Zef	 	 	 	 	 d$dۄZe%rd erfd܄Znd erfd݄Zd ecfdބZ	 d dlmZ d dlmZ n# e $ r d%dZde]d eofdZY nw xY wd eofdZ	 d	 	 	 d&dZddddd eofdZe"r e?d          Zd'dZd#dd e]fdZddd eofdZ	 	 	 	 d(dZddd eofdZ	 	 	 	 d)dZd*dZd+dZdS (,      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Literal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   rD   Optional[bool]returnbool | Nonec                    | !t          |                                           nd}|t          v rdS |t          v rdS |rdnt	          |           S )zCasts an ENV variable value to boolean using the constants defined above.
    In strict mode, it may return None if the value doesn't match any of the predefined values.
    NFT)strlowerFALSY_ENV_VALUESTRUTHY_ENV_VALUESbool)rE   rD   
normalizeds      M/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/utils.pyenv_to_boolrQ   c   s\     (-'8U!!###dJ%%%u&&&t*44tE{{*    datac                 V    t          j        | dd                              d          S )zCSerialize data into a compact JSON representation encoded as UTF-8.F),:)	allow_nan
separatorsutf-8)jsondumpsencode)rS   s    rP   
json_dumpsr]   r   s'    :de
CCCJJ7SSSrR   Optional[str]c                     	 t          t          j        j        d          5 } d }t          j        dk    st          j        dk    r-t          j                    }|xj        t          j	        z  c_        t          j
        g d|t          j        | |                                           d                                                             d          }d d d            n# 1 swxY w Y   n# t          t           t"          f$ r Y d S w xY w|S )Nzw+win32cygwin)gitz	rev-parseHEAD)startupinfostdoutstderrstdinr   rY   )openospathdevnullsysplatform
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWPopenPIPEcommunicatestripdecodeOSErrorIOErrorFileNotFoundError)nullrd   revisions      rP   get_git_revisionr|   w   s?   "'/4(( 	DK|w&&#,(*B*B(466##z'FF##  000 +%?   q"  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	& W/0   tt Os5   C+ B2CC+ C##C+ &C#'C+ +DDc                      t           j                            d          } | r| S t                      } | r| S dD ]'}t           j                            |          } | r| c S (dS )zTry to guess a default release.SENTRY_RELEASE)HEROKU_SLUG_COMMITSOURCE_VERSION!CODEBUILD_RESOLVED_SOURCE_VERSIONCIRCLE_SHA1GAE_DEPLOYMENT_ID
K_REVISIONN)ri   environgetr|   )releasevars     rP   get_default_releaser      s|    jnn-..G   G  
 
 *..%% 	NNN	4rR   installed_integrationsz	List[str]c                 N    g d}|D ]}|| v rd                     |          c S dS )zAReturn the SDK name including the name of the used web framework.)djangoflaskfastapibottlefalconquartsanic	starlettelitestarstarlitechalice
serverlesspyramidtornadoaiohttp
aws_lambdagcpbeamasgiwsgizsentry.python.{}zsentry.python)format)r   framework_integrationsintegrations      rP   get_sdk_namer      sW    
  . . : :000%,,[99999 1 ?rR   c                   2    e Zd ZdZddZddddd	d
defdZdS )CaptureInternalException rG   ContextManager[Any]c                     | S Nr   selfs    rP   	__enter__z"CaptureInternalException.__enter__   s    rR   tyOptional[Type[BaseException]]rE   Optional[BaseException]tbOptional[TracebackType]c                 2    ||t          |||f           dS )NT)capture_internal_exception)r   r   rE   r   s       rP   __exit__z!CaptureInternalException.__exit__   s'     >e/&E2777trR   NrG   r   )__name__
__module____qualname__	__slots__r   rN   r   r   rR   rP   r   r      sg        I   	+	 )	 &		
 
	 	 	 	 	 	rR   r   r   c                      t           S r   )_CAPTURE_INTERNAL_EXCEPTIONr   rR   rP   capture_internal_exceptionsr      s    &&rR   exc_infor1   c                     t          j                                                    rt                              d|            dS dS )z
    Capture an exception that is likely caused by a bug in the SDK
    itself.

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

    Any datetime objects with a non-UTC timezone are converted to UTC, so that all timestamps are formatted in UTC.
    z%Y-%m-%dT%H:%M:%S.%fZ)
astimezoner   utcstrftime)rE   utctimes     rP   format_timestampr      s0    
 x|,,G 3444rR   )+-c                    	 t          j        |           }n# t          t          f$ r d| v rdnd}|                     d          r| d d         dz   } | d         t
          v r|dz  }| d d	         | d
d          z   } n| d         t
          v r|dz  }t          j        | |          }Y nw xY w|                    t          j	                  S )N.z%Y-%m-%dT%H:%M:%S.%fz%Y-%m-%dT%H:%M:%SZz+0000iz%z)
r   fromisoformatAttributeError
ValueErrorendswithISO_TZ_SEPARATORSstrptimer   r   r   )rE   resulttimestamp_formats      rP   datetime_from_isoformatr     s    <'..J' < < < '*Ull""8K 	 >># 	)#2#J(E9)))$#2#Jrss+EE2Y+++$"5*:;;< X\***s    BB('B(Optional[ExcInfo]Dict[str, Optional[ExcInfo]]c                 h    | t          j                    } nt          |           } | d         d} d| iS )z+Creates a hint with the exc info filled in.Nr   r   )rl   r   exc_info_from_errorr   s    rP   event_hint_with_exc_infor     s>     <>>&x00{!!rR   c                       e Zd ZdZdS )BadDsnzRaised on invalid DSNs.Nr   r   r   __doc__r   rR   rP   r   r   &  s        !!!!rR   r   c                   z    e Zd ZdZ ej        d          Z	 d	 	 	 	 	 dd	Zede	fd
            Z
dddZde	fdZdS )DsnzRepresents a DSN.z	^o(\d+)\.NrE   Union[Dsn, str]org_idr^   rG   c                    t          |t                    rt          |j                  | _        d S t	          t          |                    }|j        dvrt          d|j        z            |j        | _        |j        t          d          |j        | _	        ||| _
        nBt          j                            | j	                  }|r|                    d          nd | _
        |j        | j        dk    rdpd| _        n|j        | _        |j        st          d          |j        | _        |j        | _        |j                            d	d          }	 t          t+          |                                                    | _        n6# t0          t2          f$ r" t          d
|j        pddd          z            w xY wd	                    |          d	z   | _        d S )N)httphttpszUnsupported scheme %rzMissing hostnamer7   r     P   zMissing public key/zInvalid project in DSN (%r) )
isinstancer   dict__dict__r   rJ   schemer   hostnamehostr   ORG_ID_REGEXmatchgroupportusername
public_keypassword
secret_keyrj   rsplitintpop
project_idr   	TypeErrorjoin)r   rE   r   partsorg_id_matchrj   s         rP   __init__zDsn.__init__/  s    eS!! 	 00DMFU$$<00005<?@@@l>!+,,,N	+1DKK+11$)<<L3?I,,,Q///TDK:![G3;ArDII
DI~ 	/-.....z  a((	Q!#dhhjj//22DOOI& 	Q 	Q 	Q6%*:JABB9OOPPP	Q HHTNNS(			s   3F 3G c                 L    | j         }| j        | j        fdvr|d| j        }|S )zThe netloc part of a DSN.))r   r   )r   r   rV   )r   r   r   r   rvs     rP   netlocz
Dsn.netlocZ  s7     YK#+IIIBB		*B	rR   clientOptional[Any]Authc           	      j    t          | j        | j        | j        | j        | j        | j        |          S )z*Returns the auth info object for this dsn.)r   r   rj   r  r  r  r  )r  r   r  rj   r  r  r  )r   r  s     rP   to_authzDsn.to_authb  s:    ;
 
 
 	
rR   c                 v    | j         d| j        | j        r
d| j        z   pdd| j        | j        | j        S )N://@r   )r   r  r  r  rj   r  r   s    rP   __str__zDsn.__str__n  sM    KKKOOO5do 5;;;KKIIOO
 	
rR   r   )rE   r   r   r^   rG   N)r  r  rG   r  )r   r   r   r   recompiler   r  propertyrJ   r  r  r  r   rR   rP   r   r   *  s        2:l++L CG))&))0?))	)) )) )) ))V     X

 

 

 

 


 
 
 
 
 
 
rR   r   c                   r    e Zd ZdZ	 	 	 	 ddedededed	d
dedddeddfdZej        fdddefdZ	defdZ
dS )r  z,Helper object that represents the auth info.N   r   r   r   r  r  r  r^   versionr  r  rj   rG   c	                 v    || _         || _        || _        || _        || _        || _        || _        || _        d S r   )r   r   rj   r  r  r  r  r  )	r   r   r   r  r  r  r  r  rj   s	            rP   r  zAuth.__init__|  s@     		$$$rR   typer   c           	      T    | j         d| j        | j        d| j        d|j        d	S )z'Returns the API url for storing events.r  zapi/r   )r   r   rj   r  rE   )r   r!  s     rP   get_api_urlzAuth.get_api_url  s9     KKKIIIIIOOOJJJ
 	
rR   c                     d| j         fd| j        fg}| j        |                    d| j        f           | j        |                    d| j        f           dd                    d |D                       z   S )	z!Returns the auth header a string.
sentry_keysentry_versionNsentry_clientsentry_secretzSentry z, c              3   *   K   | ]\  }}|d |V  dS )=Nr   ).0keyrE   s      rP   	<genexpr>z!Auth.to_header.<locals>.<genexpr>  s1      $Q$Q
UUU%;$Q$Q$Q$Q$Q$QrR   )r  r  r  appendr  r	  r  s     rP   	to_headerzAuth.to_header  s    T_-0@$,/OP;"II4555?&II8999499$Q$Qb$Q$Q$QQQQQrR   )Nr  Nr   )r   r   r   r   rJ   r  r  r   ENVELOPEr#  r/  r   rR   rP   r  r  y  s        66 '+"&   	
  $     
   ,  ,4
 

 

 
 
 
R3 R R R R R RrR   r  clsOptional[type]c                 F    t          | dd           pt          | dd           S )Nr   r   getattr)r1  s    rP   get_type_namer6    s%    3--Oj$1O1OOrR   c                 4    t          | dd           }|dvr|S d S )Nr   )Nbuiltins__builtins__r4  )r1  mods     rP   get_type_moduler;    s)    
#|T
*
*C
444
4rR   framer   c                     	 | j         d         }|                    d          rdS n# t          t          f$ r Y nw xY wdD ]#}	 | j        |         r dS # t
          $ r Y  w xY wdS )Nr   zsentry_sdk.T)__traceback_hide____tracebackhide__F)	f_globals
startswithr   KeyErrorf_locals	Exception)r<  r:  	flag_names      rP   should_hide_framerF    s    oj)>>-(( 	4	H%    ?  		~i( tt 	 	 	D	 5s   "' ;;A
A! A!r   r   Iterator[TracebackType]c              #   X   K   | }|#t          |j                  s|V  |j        }|!d S d S r   )rF  tb_frametb_next)r   tb_s     rP   iter_stacksrL    sA      %'C
/ .. 	IIIk /////rR   filenamelineno
max_lengthOptional[int]loaderr  moduleKTuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]c                    d}d }|Vt          |d          rF	 |                    |          }n# t          t          f$ r d }Y nw xY w||                                }|2	 t          j        |           }n# t          t          f$ r g d g fcY S w xY w|sg d g fS t          d||z
            }t          |dz   |z   t          |                    }		 fd|||         D             }
t          ||                             d                    }fd||dz   |	         D             }|
||fS # t          $ r g d g fcY S w xY w)	N   
get_sourcer   r7   c                 X    g | ]&}t          |                    d                     'S 
rO  strip_stringru   r+  linerO  s     rP   
<listcomp>z'get_lines_from_file.<locals>.<listcomp>  sB     
 
 
 F++
CCC
 
 
rR   rY  rZ  c                 X    g | ]&}t          |                    d                     'S rX  r[  r]  s     rP   r_  z'get_lines_from_file.<locals>.<listcomp>  sB     
 
 
 F++
CCC
 
 
rR   )hasattrrV  ImportErrorrx   
splitlines	linecachegetlinesrw   maxminlenr\  ru   
IndexError)rM  rN  rO  rQ  rR  context_linessource
source_strlower_boundupper_boundpre_contextcontext_linepost_contexts     `          rP   get_lines_from_filerr    s    MFgfl;;	*0*;*;F*C*CJJW% 	 	 	JJJ	!**,,F~	 '11FF! 	  	  	 tR<	   4|a-/00Kfqj=0#f++>>K
 
 
 
{612
 
 
 $F6N$8$8$@$@ZXXX
 
 
 

k9:
 
 
 L,66   4|s4   / AA!A6 6BBAD. .E ?E 	tb_linenomax_value_lengthc                    	 | j         j        }n# t          $ r d }Y nw xY w	 | j        d         }n# t          $ r g d g fcY S w xY w	 | j        d         }n# t          $ r d }Y nw xY w||r|dz
  }t	          |||||          S g d g fS )Nr   
__loader__r7   )rQ  rR  )f_codeco_filenamerD  r@  rr  )r<  rs  rt  abs_pathrR  rQ  rN  s          rP   get_source_contextrz    s    
$)L$<   ,   4|.    Q"f.vf
 
 
 	
 tR<s-    0 AAA A#"A#c                 `    	 t          |           S # t          $ r t          |           cY S w xY wr   )rJ   rD  	safe_reprr   s    rP   safe_strr}    sB     5zz       s    --c                 D    	 t          |           S # t          $ r Y dS w xY w)Nz<broken repr>)reprrD  r   s    rP   r|  r|    s5    E{{   s    
ry  c                    |r| s|S 	 |                     d          r
|d d         }|                     dd          d         }|| k    rt          j                            |          S t
          j        |         j        }|s|S |                    |                    t          j	        d          d         d          d         
                    t          j	                  S # t          $ r |cY S w xY w)Nz.pycr   r   r7   r      )r   splitri   rj   basenamerl   modules__file__r  seplstriprD  )rR  ry  base_modulebase_module_paths       rP   filename_for_moduler  "  s     6 V$$ 	%}Hll3**1-&  7##H---;{3< 	O~~.55bfa@@CQGGKRRF
 
 	
    s   AC  (C  AC   C/.C/Tinclude_local_variablesinclude_source_contextcustom_reprz&Optional[Callable[..., Optional[str]]]Dict[str, Any]c                    t          | dd           }|sd }d }n| j        j        }| j        j        }	 | j        d         }	n# t
          $ r d }	Y nw xY w|| j        }	 |rt          j        	                    |          nd }
n# t
          $ r d }
Y nw xY wt          |	|          pd |
|pd|	|d}|rt          | ||          \  |d<   |d<   |d<   |r)dd	lm}  |t          | j                  d
|          |d<   |S )Nrw  r   z	<unknown>)rM  ry  functionrR  rN  ro  rp  rq  r   )	serializeT)is_varsr  vars)r5  rw  rx  co_namer@  rD  f_linenori   rj   abspathr  rz  sentry_sdk.serializerr  r   rC  )r<  rs  r  r  rt  r  rw  ry  r  rR  os_abs_pathr  r  s                rP   serialize_framer  ;  s    UHd++F (<+<',    N	3;Ebgooh///    (99AT+ B  
DV9.E
 E
A=2n-r./A  
333333Y  $K
 
 
6
 Is#   A   AA#B   BBc                     d}g }t          j                    }|>t          |          s&|                    t	          || ||                     |j        }|>|                                 d|iS )NT)r  r  rt  frames)rl   	_getframerF  r.  r  f_backreverse)r  r  rt  r?  r  r9   s         rP   current_stacktracer  n  s    
 F"}A
- ## 	MM,C+A%5	     H - NNfrR   	exc_valuec                 $    t          | dd           S )Nerrnor4  )r  s    rP   	get_errnor    s    9gt,,,rR   r   c                 >   t          t          | dd          pt          | dd          pt          |                     }t          | dd           }t          |t                    r8t	          |          dk    r%|dd                    d |D                       z   z  }|S )Nmessager   detail	__notes__r   
c              3   D   K   | ]}t          |t                    |V  d S r   )r   rJ   )r+  notes     rP   r-  z$get_error_message.<locals>.<genexpr>  s1      #T#TTjs>S>S#TD#T#T#T#T#T#TrR   )r}  r5  r   listrh  r	  )r  r  notess      rP   get_error_messager    s    	9b)) 	9h++	I G I{D99E% U3u::>>4$))#T#TU#T#T#TTTTTNrR   exc_typeclient_optionsOptional[Dict[str, Any]]	mechanismexception_id	parent_idrk  
full_stackOptional[list[dict[str, Any]]]c	                    i }	|r|                                 nddd|	d<   |||	d         d<   |t          |          }
nd}
|
D|	d                             di                               di                               d	|
           |||	d         d
<   |dk    }|s|||	d         d<   d|	d         d<   |rd|	d         vrd|	d         d<   t          duot	          |t                    }|rd|	d         d<   t          |           |	d<   t          |           |	d<   t          |          |	d<   |ddt          dn-|d         |d         |d         |	                    d          fdt          t          |          t          t          dz                       D             }t          |          t          k    rt          j        d          |	d<   n|r|s|}nt#          |||          }d|i|	d<   |	S )z
    Creates a dict that goes into the events `exception.values` list and is ingestible by Sentry.

    See the Exception Interface documentation for more details:
    https://develop.sentry.dev/sdk/event-payloads/exception/
    genericTr!  handledr  Nr  metar  numberrk  r   r  chainedr!  is_exception_grouprR  rE   r  r  rt  r  c           
      T    g | ]$\  }}t          |j        |j                   %S ))rs  r  r  rt  r  )r  rI  rs  )r+  r   _r  r  r  rt  s      rP   r_  z5single_exception_from_error_tuple.<locals>.<listcomp>  sT     & & & B 	Kl$;#9-#	
 	
 	
& & &rR   r7   r   
stacktracer  )copyr  
setdefaultr   r   r;  r6  r  r   r   ziprL  rangeMAX_STACK_FRAMESrh  r   removed_because_over_size_limitmerge_stack_frames)r  r  r   r  r  r  r  rk  r  exception_valuer  is_root_exceptionr  r  
new_framesr  r  r  rt  s                  @@@@rP   !single_exception_from_error_tupler    s   " )+O%O	I$+O+O K  7C$^4)$$$//;;FFR	
 	

*Xu
%
%
%17$X.$) 9!64=$[1/8$V, 9V?;+GGG/8$V,+47 J%= =  B=A$%9: / 9 9OH+H55OF0;;OG"&!%3"01J"K!/0H!I)*<=$((77& & & & & & & R%0@10D*E*EFF& & &F 6{{%%% )7(V)
 )
 )
%% 
 ? 	PJJ+FJOOJ)1:(>%rR   __suppress_context__Iterator[ExcInfo]c              #     K   | \  }}}g }t                      }||t          |          |vr|||fV  |                    |           |                    t          |                     |j        r|j        }n|j        }|d S t          |          }|}t          |dd           }||t          |          |vd S d S d S d S d S d S )N__traceback__)	setidr.  addr  	__cause____context__r!  r5  )r   r  r  r   seen_exceptionsseen_exception_idscauses          rP   walk_exception_chainr    s     "*)R),  %9%777Ir))))
 ""9---""2i==111- .!+!-}E{{HI66B)  %9%77777 ! %%77 ! %%rR   c              #      K   | V  d S r   r   r   s    rP   r  r  '  s      rR   z Tuple[int, List[Dict[str, Any]]]c	                 8   t          | ||||||||	  	        }	|	g}
|}|dz  }t          |d          o|j        }|rp|ot          |d          o|j        du}|rR|j        }t	          t          |          |t          |dd          |||d|          \  }}|
                    |           no|ot          |d          o|j        du}|rR|j        }t	          t          |          |t          |dd          |||d|          \  }}|
                    |           |ot          |d	          }|rit          |j
                  D ]T\  }}t	          t          |          |t          |dd          ||||d
|z  |	  	        \  }}|
                    |           U||
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  rk  r  r7   r  r  Nr  )r  r  r   r  r  r  rk  r  r  
exceptionszexceptions[%s])r  ra  r  r  exceptions_from_errorr!  r5  extendr  	enumerater  )r  r  r   r  r  r  r  rk  r  parentr  should_supress_contextexception_has_causer  child_exceptionsexception_has_contentcontextr  idxes                       rP   r  r  +  sS   & /%!
 
 
F JIAL 		122Uy7U   *0  0	;//0#4/ 	
  	0'E/De5/488-#)"%	0 	0 	0,\+ .///  2	=112%T1 	
 ! 	0+G/Dg!7OT::-#)$%	0 	0 	0,\+ ./// #Gwy,'G'G 0	 455 	0 	0FC/Da1ot44-#)#'#-%
0 
0 
0,\+ .////*%%rR   List[Dict[str, Any]]c                 0   | \  }}}t           d uot          |t                     }|rt          |||||dd|          \  }}	n@g }	t          |           D ].\  }}}|	                    t          ||||||                     /|	                                 |	S )Nr   )r  r  r   r  r  r  r  r  )r  r  r   r  r  r  )r   r   r  r  r.  r  r  )
r   r  r  r  r  r  r   r  r  r  s
             rP   exceptions_from_error_tupler    s     'Hi+47 J%= =  /)!	
 	
 	
JJ 
';H'E'E 
	 
	#Hi1%'#1')  	 	 	 	 rR   c                 p    	 t          |           S # t          $ r t          |           dd         cY S w xY w)Nr7   r   )rJ   UnicodeDecodeErrorr  r   s    rP   	to_stringr    sI    !5zz ! ! !E{{1R4    !s    !55eventr0   #Iterator[Annotated[Dict[str, Any]]]c              #     K   d| v r
| d         V  d| v r.| d                              d          pdD ]}d|v r
|d         V  d| v rC| d                              d          pdD ]'}t          |t                    rd|v r
|d         V  &d S d S )Nr  threadsvaluesr   	exception)r   r   r   )r  threadr  s      rP   iter_event_stacktracesr    s      uL!!!!EI&**844: 	+ 	+Fv%%\****e{+//99?R 	. 	.I)T** .|y/H/H---- 	. 	.rR   Iterator[Dict[str, Any]]c              #      K   t          |           D ]>}t          |t                    r	|j        pi }|                    d          pdD ]}|V  ?d S )Nr  r   )r  r   r   rE   r   )r  r  r<  s      rP   iter_event_framesr    sv      ,U33  
j.11 	0#)/RJ^^H--3 	 	EKKKK		 rR   in_app_excludeOptional[List[str]]in_app_includeproject_rootc                     t          |           D ]F}t          |t                    r	|j        pi }t	          |                    d          |||           G| S )Nr  )r  r  r  )r  r   r   rE   set_in_app_in_framesr   )r  r  r  r  r  s        rP   handle_in_appr    su     -U33 	
 	

j.11 	0#)/RJNN8$$))%		
 	
 	
 	
 	
 LrR   r  c                 P   | sd S | D ]}|                     d          }||                     d          }t          ||          rd|d<   Et          ||          rd|d<   [|                     d          }|st          |          rd|d<   t          ||          rd|d<   | S )Nin_apprR  TFry  )r   _module_in_list_is_external_source_is_in_project_root)r  r  r  r  r<  current_in_apprR  ry  s           rP   r  r    s      t  8,,%8$$ 6>22 	"E(O 6>22 	#E(O 99Z((x(( 	#E(Ox66 	"E(O	 MrR   r   Union[BaseException, ExcInfo]c                    t          | t                    rt          |           dk    r| \  }}}nt          | t                    rTt	          | dd           }|t          |           }| }nNt          j                    \  }}}|| urd }| }t          |           }nt          dt          |           z            |||f}t          rt          t          |          }|S )N   r  z,Expected Exception object to report, got %s!)r   tuplerh  BaseExceptionr5  r!  rl   r   r   r   r+   r1   )r   r  r  r   r   s        rP   r   r     s    % WCJJ!OO"')RR	E=	)	) WUOT22>E{{HII&)lnn#Hi%%!	;; G$u++UVVV)R(H + **OrR   c                     d | D             fd|D             }|                     |            |r|                    dt                    nd}||t          |          |z
  d         }|S )zV
    Add the missing frames from full_stack to frames and return the merged list.
    c                 J    h | ] }|d          |d         |d         |d         f!S ry  rp  rN  r  r   )r+  r<  s     rP   	<setcomp>z%merge_stack_frames.<locals>.<setcomp><  sK         *.!(O*		
  rR   c                 T    g | ]$}|d          |d         |d         |d         fv"|%S r  r   )r+  
stackframe	frame_idss     rP   r_  z&merge_stack_frames.<locals>.<listcomp>F  s]     
 
 
z"~&x z"	
   	  rR   max_stack_framesN)r  r   r   rh  )r  r  r  r  r  r  s        @rP   r  r  4  s        I
 
 
 
$
 
 
J f
 	-/GHHH 
 #J2B B D DE
rR   Tuple[Event, Dict[str, Any]]c                     t          |           } t          |           }|r?|                    dt                    r$t	          |d         |d                   d         }nd }ddt          | |||          id|fS )	Nadd_full_stackr  rt  )r  rt  r  r   r  )levelr  )r   r   r   r   r  r  )r   r  r  hintr  s        rP   event_from_exceptionr  _  s    
 #8,,H#H--D .,,-=?UVV '$23L$M+,>?
 
 
 


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

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

R]" G
--((2244Y?+0S'--:L:LRaR:P1Q1Q+R+Rz>2   tt s   A*B! !B<;B<c                     	 ddl } ddlm} t          d t	          j        d| j                  dd         D                       } |dd          r&t          j        d	k    r|d
k    s |dd          rdS dS n# t          $ r Y nw xY w	 ddl
}ddlm} t          |j                  }|t                              d           dS  |d          r|dk     rdS n# t          $ r Y nw xY wdS )z
    Returns whether gevent/eventlet have patched the stdlib in a way where thread locals are now more "correct" than contextvars.
    r   N)is_object_patchedc                 ,    g | ]}t          |          S r   )r  )r+  parts     rP   r_  z*_is_contextvars_broken.<locals>.<listcomp>  s    RRR4SYYRRRrR   z	a|b|rc|\.r  	threadinglocalr  r  )   	   contextvars
ContextVarFT)is_monkey_patchedzYInternal error in Sentry SDK: Could not parse Greenlet version from greenlet.__version__.r  )r   rU  )geventgevent.monkeyr>  r  r  r  __version__rl   version_inforb  greenleteventlet.patcherrH  r<  r   r   )rI  r>  version_tuplerM  rH  greenlet_versions         rP   _is_contextvars_brokenrQ    sx   333333 RR28L&:L#M#Mbqb#QRRR
 
 ['22 	 !V++0H0H%%m\BB 1I u4	     666666()=>>#LLk   5X&& 	+;f+D+D4    5s*   A1A8 8
BB	:C C 
C&%C&rB  c                 &      G  fdd          }|S )Nc                   D    e Zd Zddeddddf fdZdddZdd	ZddZdS )1_make_threadlocal_contextvars.<locals>.ContextVarNr  defaultr   rG   c                 `    || _         || _                     | _                     | _        d S r   )_name_default_local_original_local)r   r  rU  rB  s      rP   r  z:_make_threadlocal_contextvars.<locals>.ContextVar.__init__:  s2    DJ#DM%''DK#(577D   rR   c                 <    t          | j        d|p| j                  S )NrE   )r5  rY  rX  )r   rU  s     rP   r   z5_make_threadlocal_contextvars.<locals>.ContextVar.get@  s    4;1IDMJJJrR   rE   c                     t          t          j        d                    }|                                 }t	          | j        ||           || j        _        |S )N@   )rJ   randomgetrandbitsr   setattrrZ  rY  rE   )r   rE   tokenoriginal_values       rP   r  z5_make_threadlocal_contextvars.<locals>.ContextVar.setC  sK    *2..//E!XXZZND(%@@@ %DKLrR   ra  c                 ^    t          | j        |          | j        _        | j        j        |= d S r   )r5  rZ  rY  rE   r   )r   ra  s     rP   resetz7_make_threadlocal_contextvars.<locals>.ContextVar.resetJ  s-     '(<e D DDK$-e444rR   r   )rU  r   rG   r   )rE   r   rG   r   )ra  r   rG   N)r   r   r   rJ   r  r   r  rd  rB  s   rP   rG  rT  7  s        	+ 	+ 	+u 	+ 	+ 	+ 	+ 	+ 	+ 	+	K 	K 	K 	K 	K	 	 	 		5 	5 	5 	5 	5 	5rR   rG  r   )rB  rG  s   ` rP   _make_threadlocal_contextvarsrf  6  s=    5 5 5 5 5 5 5 5 5 50 rR   Tuple[bool, type]c                      t                      sFt          j        dk     r	 ddlm}  d| fS # t
          $ r Y nw xY w	 ddlm}  d| fS # t
          $ r Y nw xY wddlm} dt          |          fS )z
    Figure out the "right" contextvars installation to use. Returns a
    `contextvars.ContextVar`-like class with a limited API.

    See https://docs.sentry.io/platforms/python/contextvars/ for more information.
    rC  r   )rG  Tre  F)
rQ  rl   rL  aiocontextvarsrG  rb  rF  rA  rB  rf  )rG  rB  s     rP   _get_contextvarsrj  R  s     "## 
 f$$555555Z''   222222Z''   
  /6666s   	* 
77	A 
AAz

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

Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information.
funcCallable[..., Any]c                 P   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        } nCt          | dd          pt          | dd          }t	          |t                    rd\  }}|j        } t          | d	          r| j
        }nt          | d          r| j        }|?t          | d
          r't	          | j        t                    r| j        dz   |z   }||z   |z   }|S )zbReturn the qualified name of func. Works with regular function, lambda, partial and partialmethod.Nr   )r   r   r   )zpartial(<function >)_partialmethod__partialmethod__)zpartialmethod(<function rn  r   r   )im_classr   r   rD  r   r   ra  rk  r5  r   r   rJ   )rk  func_qualnameprefixsuffixpartial_methods        rP   qualname_from_functionrv    s{   %)MM$$$M"""MM
 	

     NFF$   'WTY
%C%C '3y !'7>> 
'%tC
 C
 nm44 	'=NFF!&Dt^$$ &)	z	"	" &  4&& 	B:dos+K+K 	B Oc1MAM.7s   "' 
44c                      t          |           S r   )rv  )rk  s    rP   transaction_from_functionrx    s    !$'''rR   disable_capture_eventc                       e Zd ZdZdS )ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nr   r   rR   rP   r{  r{    s        HHDrR   r{  c                   L    e Zd ZdZ	 	 ddededdddddf
d	Zdd
ZddZddZ	dS )TimeoutThreadzCreates a Thread which runs (sleeps) for a time duration equal to
    waiting_time and raises a custom ServerlessTimeout exception.
    Nwaiting_timeconfigured_timeoutisolation_scopezOptional[sentry_sdk.Scope]current_scoperG   c                     t           j                            |            || _        || _        || _        || _        t          j                    | _        d S r   )	rA  Threadr  r~  r  r  r  r0   _stop_event)r   r~  r  r  r  s        rP   r  zTimeoutThread.__init__  sQ     	!!$'''("4.*$?,,rR   c                 8    | j                                          d S r   )r  r  r   s    rP   stopzTimeoutThread.stop  s    rR   r1   c                     t          j                    }t          j                    }t	          ||j        ddd          \  }}t          j        ||           |S )NrA  Fr  )r  r  )r  )rl   r   r   r   r  optionscapture_event)r   r   r  r  r  s        rP   _capture_exceptionz TimeoutThread._capture_exception  sc    <>>&((*!>*u==
 
 
t
 	 T2222rR   c                    | j                             | j                   | j                                         rd S t	          | j                  }|| j        k     r|dz   }| j        | j        t          j	        
                    | j                  5  t          j	                            | j                  5  	 t          d                    |                    # t          $ r t          |                                   Y nw xY w	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          d                    |                    )Nr7   zZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)r  waitr~  is_setr  r  r  r  r   scopeuse_isolation_scope	use_scoper{  r   rD  reraiser  )r   integer_configured_timeouts     rP   runzTimeoutThread.run  s   d/000""$$ 	F%()@%A%A" &(???)Ca)G& +0B0N!55d6JKK 	< 	<%//0BCC < <<6x :   
 % < < <!8!8!:!:;;;;<;< < < < < < < < < < < < < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 'hoo* 
 
 	
sT   %D)6D8"C%D?DDDD)D	D)D	D))D-0D-NN)rG   N)rG   r1   )
r   r   r   r   floatr  r  r  r  r  r   rR   rP   r}  r}    s          9=6:- --  - 6	-
 4- 
- - - -       
 
 
 
 
 
rR   r}  originalc                    d}	 |                      d          }t          j        |          }|                    d          }nF# t          $ r9}t
                              d                    |           |           Y d}~nd}~ww xY w|S )zO
    Convert a string to base64, via UTF-8. Returns None on invalid input.
    NUTF-8z"Unable to encode {orig} to base64:)orig)r\   base64	b64encoderv   rD  r   warningr   )r  base64_string
utf8_bytesbase64_byteserrs        rP   	to_base64r     s     MX__W--
'
33$++G44 X X X;BBBQQSVWWWWWWWWX s   >A 
B/BBr  c                 R   d}	 t                               |           }|sJ |                     d          }t          j        |          }|                    d          }nF# t          $ r9}t                              d	                    |           |           Y d}~nd}~ww xY w|S )zQ
    Convert a string from base64, via UTF-8. Returns None on invalid input.
    Nr  z#Unable to decode {b64} from base64:)b64)
BASE64_ALPHABETr   r\   r  	b64decoderv   rD  r   r  r   )r  utf8_stringonly_valid_charsr  r  r  s         rP   from_base64r    s     K

*00??$++G44%l33
 ''00 
 
 
188]8KKS	
 	
 	
 	
 	
 	
 	
 	


 s   AA! !
B$+/BB$
Components)r   r  rj   queryfragmenturlremove_authorityremove_query_valuesr  zUnion[str, Components]c                    t          |           }t          |j        d          }|rP|j                            d          }t          |          dk    rt          dt          d|d         }n|j        }n|j        }|r't          t          d |D                                 }n|j        }t          |j
        |||j        |j                  }	|r|	S t          |	          S )	zL
    Removes the authority and query parameter values from a given URL.
    T)keep_blank_valuesr  r7   rV   r   c                     i | ]
}|t           S r   )r   )r+  r,  s     rP   
<dictcomp>z sanitize_url.<locals>.<dictcomp>E  s    NNN#s5NNNrR   r   r  r  rj   r  )r   r   r  r  r  rh  r   r   r   r  r   rj   r  r   )
r  r  r  r  
parsed_urlquery_paramsnetloc_partsr  query_string
componentss
             rP   sanitize_urlr  (  s    #JJ,EEEL  #!(..s33|q  ))))))R  FF  &FF"  (NNNNNOO
 
 "' _$  J  &*%%%rR   	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  rj   r  r  r  )r  r  r  base_urls       rP   	parse_urlr  [  s     d  J $$	
 	
 	
 H $   rR   ratec           	      |   t          | t          t          f          rt          j        |           r?t
                              d                    || t          |                                dS t          |           } | dk     s| dk    r1t
                              d                    ||                      dS dS )	z
    Checks the given sample rate to make sure it is valid type and value (a
    boolean or a number between 0 and 1, inclusive).
    z|{source} Given sample rate is invalid. Sample rate must be a boolean or a number between 0 and 1. Got {rate} of type {type}.)rk  r  r!  Fr   r7   zW{source} Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)rk  r  T)
r   r
   r   mathisnanr   r  r   r!  r  )r  rk  s     rP   is_valid_sample_rater  v  s     dT7O,, 
40@0@  K  R  RDtDzz R  	
 	
 	

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

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

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

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

    Example usage:

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

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

 0 0 2 2  
 :4::.999999 " " "Dzz!!!" Ks%   AA% %"B
	B
=AE E! E!)rU  N)r  r   rG   r2  )rZ   r[   rJ   rD  )rS   
serializedr9  s     @rP   safe_serializerC    s    ""	A" " " " " "H#^D))
z*c2222   4yys   %3 AAr  Optional[dict[str, Any]]c                     | dS t          |                     dd          p| d                             dd                    S )NFenable_logs_experimentsrN   r   r  s    rP   has_logs_enabledrJ    sL    uM5)) 	=>"&&}e<<  rR   .Optional[Callable[[Log, Hint], Optional[Log]]]c                 j    | d S |                      d          p| d                              d          S )Nbefore_send_logrG  r   rI  s    rP   get_before_send_logrO    sB     t;;()) W^-D-H-H. . rR   c                 P    | dS t          |                     dd                    S )NFenable_metricsTrH  rI  s    rP   has_metrics_enabledrR    s)    u,d33444rR   4Optional[Callable[[Metric, Hint], Optional[Metric]]]c                 j    | d S |                      d          p| d                              d          S )Nbefore_send_metricrG  rN  rI  s    rP   get_before_send_metricrV    sB     t;;+,, 0G0K0K1 1 rR   valr.   c                 t    t          | t          t          t          t          f          r| 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   rN   r  r  rJ   r|  rW  s    rP   format_attributer[    s0     #c5#.// 
S>>rR   r/   c                     t          | t                    r| ddS t          | t                    r| ddS t          | t                    r| ddS t          | t                    r| ddS t          |           ddS )z2Serialize attribute value to the transport format.boolean)rE   r!  integerdoubler"  rY  rZ  s    rP   serialize_attributer`    s    #t 1i000#s 1i000#u 0h///#s 0h/// s^^X666rR   )rE   r   rD   rF   rG   rH   )rG   r^   r   )r   r1   rG   Nr   )r   r   rG   r   )r1  r2  rG   r^   )r   r   rG   rG  )NNN)r<  r   rs  rP  rt  rP  rG   rS  )rR  r^   ry  r^   rG   r^   )NTTNN)TTN)NNNNNN)r  r2  r  r   r   r   r  r  r  r  r  rP  r  rP  rk  r^   r  r  rG   r  )r   r1   rG   r  )NNr   r   NN)
r   r1   r  r  r  r  r  r  rG   r  )r  r0   rG   r  )r  r0   rG   r  )
r  r0   r  r  r  r  r  r^   rG   r0   )
r  r   r  r  r  r  r  r^   rG   r  )r   r  rG   r1   )r  r  r  r  r  r  rG   r  r  )r   r  r  r  r  r  rG   r  )rG   rg  )rk  rl  rG   r^   )TTF)Tr  )rG   r  )rG   r  )r  r   rE   r   r   r  rG   r#   )r  r   r  r   rG   N)r   r  r  r  rG   r  )r   r  rG   r  )r   r  r  r  rG   r  )rG   r  )r  r  rG   r  )r,  r-  rE   r   rG   r.  )r  rD  rG   rK  )r  rD  rG   rS  )rW  r   rG   r.   )rW  r.   rG   r/   )r  rZ   rd  loggingr  ri   r^  r  rn   rl   rA  r	  collectionsr   r   r   decimalr   	functoolsr   r   r	   numbersr
   urllib.parser   r   r   r   r   r8  r   rb  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.   r/   r0   r1   r2   r3   r4   r5   r6   r   	getLoggerr   r  r  r  	frozensetrL   rM   r  rQ   bytesr]   r|   r   rJ   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r  r6  r;  rN   rF  rL  r  rr  rz  r}  r|  r  r  r  r	  r  r  r  ra  rD  HAS_CHAINED_EXCEPTIONSr  r  r  r  r  r  r  r  r   r  r  r  r  r  r)  r,  r\  r<  rQ  r!  rf  rj  HAS_REAL_CONTEXTVARSrG  CONTEXTVARS_ERROR_MESSAGErv  rx  ry  r{  r  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rI  r  r  rJ  r  r  r&  r*  r+  r0  rC  rJ  rO  rR  rV  r[  r`  r   rR   rP   <module>rs     s6           				  				     



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

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