
    Yf                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZ 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!Z!d dl"Z!d d
l#m$Z$ d dl%m&Z& d dl'm(Z(m)Z) e&rNd dl*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? d dl@Z!d dl%mAZAmBZB  e:d      ZC e>d      ZD eddd      ZE ej                  d      ZGdaH ej                  d      ZJdZKd ZLd ZMd ZNd ZOd ZP G d d      ZQ eQ       ZRd ZSd  ZTd! ZUd" ZVd{d#ZW G d$ d%eX      ZY G d& d'      ZZ G d( d)      Z[ G d* d+      Z\e&rd d,l/m>Z>  e>d-      Z]e?e\e]f   Z^d. Z_d/ Z`d0 Zad1 Zb	 	 	 d|d2Zc	 d{d3Zdd4 Zed5 Zfd6 Zg	 	 	 	 d}d7Zh	 	 	 d~d8Zid9 Zjd: Zk	 	 	 	 	 dd;Zl emend<      Zoeord= Zpnd> Zp	 	 	 	 	 dd?Zq	 	 dd@ZrdA ZsdB ZtdC Zud|dDZvd{dEZwdF Zx	 	 ddGZydH ZzdI Z{dJ Z|dK Z}dL Z~d{dMZdN ZdO ZdP ZdQ Z e       \  ZZdRZdS ZdT Z edU      Z G dV dWen      Z G dX dYe
j                        ZdZ Zd[ Z ed\g d]      Zdd^Z ed_g d`      ZddaZdb ZddcZdd Zde Zdf Zdg Zdh Zd{diZdj Zdk Ze&re9dl        Ze9dm        ZefdnZe&re9do        Ze9dp        ZefdqZe$rdr Znds Zdt Z	 d dulmZ d dvlmZ dy Zd{dzZy# e $ r dZY w xY w# e $ r	 dw Zdx ZY #w xY w)    N)
namedtuple)copy)datetime)Decimal)partialpartialmethodwraps)Real)parse_qsunquote	urlencodeurlsplit
urlunsplit)BaseExceptionGroup)PY37)TYPE_CHECKING)DEFAULT_MAX_VALUE_LENGTHEndpointType)	Awaitable)	FrameTypeTracebackType)AnyCallablecastContextManagerDictIteratorListNoReturnOptionaloverload	ParamSpecSetTupleTypeTypeVarUnion)EventExcInfoPRi     zsentry_sdk.errorsz^[a-zA-Z0-9/+=]*$z
[Filtered]c                 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)datas    P/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/sentry_sdk/utils.py
json_dumpsr8   L   s"     ::de
CJJ7SS    c                       y N r<   r9   r7   _get_debug_hubr=   R        	r9   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   r2   )openospathdevnullsysplatform
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWPopenPIPEcommunicatestripdecodeOSErrorIOErrorFileNotFoundError)nullrD   revisions      r7   get_git_revisionr\   X   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_SLUG_COMMITSOURCE_VERSION!CODEBUILD_RESOLVED_SOURCE_VERSIONCIRCLE_SHA1GAE_DEPLOYMENT_IDN)rI   environgetr\   )releasevars     r7   get_default_releaserh   t   sa     jjnn-.G G 	 **..%N	 r9   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chalice
serverlesspyramidtornadoaiohttp
aws_lambdagcpbeamasgiwsgizsentry.python.{}zsentry.python)format)installed_integrationsframework_integrationsintegrations      r7   get_sdk_namer      s:    * . :00%,,[99: r9   c                       e Zd ZdZd Zd Zy)CaptureInternalExceptionr<   c                     | S r;   r<   selfs    r7   	__enter__z"CaptureInternalException.__enter__   s    r9   c                 (    ||t        |||f       y)NT)capture_internal_exception)r   tyvaluetbs       r7   __exit__z!CaptureInternalException.__exit__   s    >e/&E27r9   N)__name__
__module____qualname__	__slots__r   r   r<   r9   r7   r   r      s    Ir9   r   c                      t         S r;   )_CAPTURE_INTERNAL_EXCEPTIONr<   r9   r7   capture_internal_exceptionsr      s    &&r9   c                 @    t               }||j                  |        y y r;   )r=   _capture_internal_exception)exc_infohubs     r7   r   r      s"    

C
''1 r9   c                 0    | t         z
  j                         S r;   )epochtotal_secondsr   s    r7   to_timestampr      s    EM((**r9   c                 $    | j                  d      S )Nz%Y-%m-%dT%H:%M:%S.%fZ)strftimer   s    r7   format_timestampr      s    >>122r9   c                 \    | 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_errorr   s    r7   event_hint_with_exc_infor      s9     <<>&x0{!!r9   c                       e Zd ZdZy)BadDsnzRaised on invalid DSNs.Nr   r   r   __doc__r<   r9   r7   r   r      s    !r9   r   c                   4    e Zd ZdZd Zed        ZddZd Zy)DsnzRepresents a DSN.c                 D   t        |t              rt        |j                        | _        y t	        t        |            }|j                  dvrt        d|j                  z        |j                  | _        |j                  t        d      |j                  | _	        |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j-                  |      dz   | _        y # t(        t*        f$ r  t        d
|j                  xs dd	d  z        w xY w)N)httphttpszUnsupported scheme %rzMissing hostnamer     P   zMissing public key/r,   zInvalid project in DSN (%r) )
isinstancer   dict__dict__r   strschemer   hostnamehostportusername
public_keypassword
secret_keyrJ   rsplitintpop
project_id
ValueError	TypeErrorjoin)r   r   partsrJ   s       r7   __init__zDsn.__init__   sT   eS! 0DMU$<<0005<<?@@ll>>!+,,NN	::w.63<"DI

DI~~-......zz  a(	Q!#dhhj/2DO HHTNS(	 I& 	Q6%**:JAB9OOPP	Qs   /'E0 0/Fc                 t    | j                   }| j                  | j                  fdvr|d| j                  }|S )zThe netloc part of a DSN.))r   r   )r   r   r/   )r   r   r   r   rvs     r7   netlocz
Dsn.netloc  s6     YYKK#+II		*B	r9   Nc           	          t        | j                  | j                  | j                  | j                  | j
                  | j                  |      S )z*Returns the auth info object for this dsn.)r   r   rJ   r   r   r   client)Authr   r   rJ   r   r   r   )r   r   s     r7   to_authzDsn.to_auth  s>     ;;
 	
r9   c                     | j                   d| j                  | j                  xr d| j                  z   xs dd| j                  | j                  | j
                  S )N://@r   )r   r   r   r   rJ   r   r   s    r7   __str__zDsn.__str__#  sN     KKOOOO5doo 5;;KKIIOO
 	
r9   r;   )	r   r   r   r   r   propertyr   r   r   r<   r9   r7   r   r      s)    ")H  
	
r9   r   c                   D    e Zd ZdZ	 	 	 	 ddZej                  fdZd Zy)r   z,Helper object that represents the auth info.Nc	                 t    || _         || _        || _        || _        || _        || _        || _        || _        y r;   )r   r   rJ   r   r   r   versionr   )	r   r   r   r   r   r   r   r   rJ   s	            r7   r   zAuth.__init__2  s<     		$$$r9   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   rJ   r   r   )r   types     r7   get_api_urlzAuth.get_api_urlG  s1     KKIIIIOOJJ
 	
r9   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keyr   s      r7   	<genexpr>z!Auth.to_header.<locals>.<genexpr>\  s     $Q
UU%;$Qs   )r   r   r   appendr   r   r   s     r7   	to_headerzAuth.to_headerT  sy     T__-0@$,,/OP;;"II45??&II89499$Qb$QQQQr9   )N   Nr   )	r   r   r   r   r   r   ENVELOPEr   r   r<   r9   r7   r   r   /  s.    6 ,  ((
Rr9   r   c                   P    e Zd ZdZdZd Zd Zed        Zed        Z	ed        Z
y)	AnnotatedValuea  
    Meta information for a data field in the event payload.
    This is to tell Relay that we have tampered with the fields value.
    See:
    https://github.com/getsentry/relay/blob/be12cd49a0f06ea932ed9b9f93a655de5d6ad6d1/relay-general/src/types/meta.rs#L407-L423
    r   metadatac                      || _         || _        y r;   r   )r   r   r   s      r7   r   zAnnotatedValue.__init__i  s    
 r9   c                     t        |t              sy| j                  |j                  k(  xr | j                  |j                  k(  S NF)r   r   r   r   )r   others     r7   __eq__zAnnotatedValue.__eq__n  s4    %0zzU[[(LT]]enn-LLr9   c                 &    t        ddddggi      S )zxThe value was removed because it could not be parsed. This is done for request body values that are not json nor a form.r   remz!rawxr   r   clss    r7   removed_because_raw_dataz'AnnotatedValue.removed_because_raw_datau  s,     

 
	
r9   c                 &    t        ddddggi      S )zThe actual value was removed because the size of the field exceeded the configured maximum size (specified with the max_request_body_size sdk option)r   r   !configr   r   r   r   s    r7   removed_because_over_size_limitz.AnnotatedValue.removed_because_over_size_limit  s,     !

 
	
r9   c                 .    t        t        dddggi      S )zHThe actual value was removed because it contained sensitive information.r   r   sr   )r   SENSITIVE_DATA_SUBSTITUTEr   s    r7   +substituted_because_contains_sensitive_dataz:AnnotatedValue.substituted_because_contains_sensitive_data  s,     +!

 
	
r9   N)r   r   r   r   r   r   r   classmethodr   r   r   r<   r9   r7   r   r   _  sU     &I!
M 
 
 
 
 
 
r9   r   )r&   Tc                 :    t        | dd       xs t        | dd       S )Nr   r   getattrr   s    r7   get_type_namer    s    3-Oj$1OOr9   c                 *    t        | dd       }|dvr|S y )Nr   )Nbuiltins__builtins__r  )r   mods     r7   get_type_moduler    s!    
#|T
*C
44
r9   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
startswithAttributeErrorKeyErrorf_locals	Exception)framer  	flag_names      r7   should_hide_framer    s    ooj)>>-( )
 ? 		~~i( )  H%   		s     > AAA	AAc              #   f   K   | }|)t        |j                        s| |j                  }|(y y wr;   )r  tb_frametb_next)r   tb_s     r7   iter_stacksr    s1     
C
/ .Ikk /s   ,11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   r,   z
)
max_length)hasattrr  ImportErrorrX   
splitlines	linecachegetlinesrW   maxminlenstrip_stringrU   
IndexError)filenamelinenor  loadermodulecontext_linessource
source_strlower_boundupper_boundlinepre_contextcontext_linepost_contexts                 r7   get_lines_from_filer5    s    MFgfl;	**62J !**,F~	 ''1F 4|a-/0Kfqj=0#f+>K {62
 F+
C
 
 $F6N$8$8$@ZX 
k:
 F+
C
 
 L,667 W% 	J	 ! 	 tR<	 



  4|sR   D  D D; #D1++D; #D69D;  DDD.-D.1
D; ;EEc                    	 | j                   j                  }	 | j                  d   }	 | j                  d   }|dz
  }||r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__r,   )r*  r+  )f_codeco_filenamer  r  r5  )r  	tb_linenomax_value_lengthabs_pathr+  r*  r)  s          r7   get_source_contextr=    s    <<++,. ]Fh"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;   )r   r  	safe_reprr   s    r7   safe_strr@    s+     5z   s   
 $$c                 8    	 t        |       S # t        $ r Y yw xY w)Nz<broken repr>)reprr  r   s    r7   r?  r?  &  s#    E{ s   
 	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.pyc.r,   r      )endswithsplitrI   rJ   basenamerL   modules__file__r   seplstripr  )r+  r<  base_modulebase_module_paths       r7   filename_for_modulerP  .  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c                    t        | dd       }|sd }d }n,| j                  j                  }| j                  j                  }	 | j                  d   }|| j                  }t        ||      xs d |rt        j                  j                  |      nd |xs d||d}	|rt        | ||      \  |	d<   |	d<   |	d<   |rt        | j                        |	d<   |	S # t
        $ r d }Y w xY w)	Nr8  r   z	<unknown>)r(  r<  functionr+  r)  r2  r3  r4  vars)r  r8  r9  co_namer  r  f_linenorP  rI   rJ   abspathr=  r   r  )
r  r:  include_local_variablesinclude_source_contextr;  r8  r<  rR  r+  r   s
             r7   serialize_framerY  F  s     UHd+F<<++<<'', NN	 (9AT19BGGOOH-t+
B DV9.E
A=2n-r./A %..)6
I-  s   C C C c                     d}g }t        j                         }|8t        |      s|j                  t	        || ||             |j
                  }|8|j                          d|iS )NT)rW  rX  r;  frames)rL   	_getframer  r   rY  f_backreverse)rW  rX  r;  r  r[  fs         r7   current_stacktracer`  p  sp     FA
- #MM,C+A%5	 HH - NNfr9   c                     t        | dd       S )Nerrnor  	exc_values    r7   	get_errnore    s    9gt,,r9   c                 T    t        | dd      xs t        | dd      xs t        |       S )Nmessager   detail)r  r@  rc  s    r7   get_error_messageri    s3     		9b) 	9h+	Ir9   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        }n|d   }|d   }|d   }t        |      D cg c]&  }t        |j                  |j                  |||      ( }}|r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   handled	mechanismNexception_idmetarb  numberr-  r   	parent_idchainedr   is_exception_groupr+  r   rW  rX  r;  )r:  rW  rX  r;  r[  
stacktrace)r   re  
setdefaultr   r   r  r  ri  r   r  rY  r  r:  )exc_typerd  r   client_optionsrm  rn  rq  r-  exception_valuerb  is_root_exceptionrs  rW  rX  r;  r[  s                   r7   !single_exception_from_error_tuplerz    s   " O%	I$+O K  7C$^4)$$//;FFR	

*Xu
%17$X.$)!64=$[1/8$V,V?;+GG/8$V,+47 J%= =A$%9: / 9OH+H5OF0;OG"&!%3"01J"K!/0H!I)*<= b/	  	KKll$;#9-	
	F 	 )16(:%	s   +E__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   rv  rd  r   seen_exceptionsseen_exception_idscauses          r7   walk_exception_chainr    s     "*)R U  %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    r7   r  r    s     s   c                    t        | |||||||      }|g}	|}|dz  }t        |d      xr |j                  }
|
ri|xr t        |d      xr |j                  du}|r|j                  }t	        t        |      |t        |dd      |||d      \  }}|	j                  |       nh|xr t        |d      xr |j                  du}|rF|j                  }t	        t        |      |t        |dd      |||d      \  }}|	j                  |       |xr t        |d	      }|r[t        |j                        D ]C  \  }}t	        t        |      |t        |dd      ||||d
|z        \  }}|	j                  |       E ||	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/
    )rv  rd  r   rw  rm  rn  rq  r-  r,   r{  r  Nr}  )rv  rd  r   rw  rm  rn  r-  r  
exceptionszexceptions[%s])rz  r  r{  r  exceptions_from_errorr   r  extendr  	enumerater  )rv  rd  r   rw  rm  rn  rq  r-  parentr  should_supress_contextexception_has_causer  child_exceptionsexception_has_contentcontextrs  idxes                      r7   r  r    s   & /%!	F JIAL$Y0FGjILjLj  0	;/0##4/ 	
 ''E/De5/48-#)"0,\+ ./  2	=12%%T1 	
 !++G/Dg!7OT:-#)$0,\+ ./ #Gwy,'G	 4 45 	0FC/Da1ot4-#)#'#-	0,\+ ./	0 *%%r9   c           
          | \  }}}t         d uxr t        |t               }|rt        |||||dd      \  }}n4g }t        |       D ]$  \  }}}|j	                  t        |||||             & |j                          |S )Nr   )rv  rd  r   rw  rm  rn  rq  )r   r   r  r  r   rz  r^  )	r   rw  rm  rv  rd  r   rs  _r  s	            r7   exceptions_from_error_tupler  s  s     'Hi+47 J%= /)
J 
';H'E 	#Hi1i^Y	 r9   c                 T    	 t        |       S # t        $ r t        |       dd cY S w xY w)Nr,   rD  )r   UnicodeDecodeErrorrB  r   s    r7   	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 ]  }d|v s|d     y y w)Nrt  threadsvaluesr<   	exception)re   )eventthreadr  s      r7   iter_event_stacktracesr    s     uL!!EI&**84: 	+Fv%\**	+ e{+//9?R 	.Iy(--	. s   /A*,A*A*c              #   h   K   t        |       D ]   }|j                  d      xs dD ]  }|  " y w)Nr[  r<   )r  re   )r  rt  r  s      r7   iter_event_framesr    s<     ,U3 
^^H-3 	EK	s   02c                 b    t        |       D ]   }t        |j                  d      |||       " | S )Nr[  )in_app_excludein_app_includeproject_root)r  set_in_app_in_framesre   )r  r  r  r  rt  s        r7   handle_in_appr    s:    ,U3 

NN8$))%		

 Lr9   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_appr+  TFr<  )re   _module_in_list_is_external_source_is_in_project_root)r[  r  r  r  r  current_in_appr+  r<  s           r7   r  r    s     8,%8$ 6>2"E(O 6>2#E(O 99Z(x(#E(Ox6"E(O;> Mr9   c                 6   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S )N   r}  z,Expected Exception object to report, got %s!)	r   tupler%  BaseExceptionr  r   rL   r   r   )errorrv  rd  r   s       r7   r   r     s    %CJ!O"')R	E=	)UOT2>E{HI&)lln#Hi%!	; G$u+UVVY""r9   c                 V    t        |       } t        |       }ddt        | ||      id|fS )Nr  r  )levelr  )r   r   r  )r   rw  rm  hints       r7   event_from_exceptionr    sH     #8,H#H-D 5ni	
 	
 
r9   c                 T    | y|sy|D ]  }|| k(  s| j                  |dz         s y y)NFrE  Tr  )nameitemsitems      r7   r  r    s=    | 4<4??4#:6 r9   c                 6    t        j                  d|       d u}|S )Nz [\\/](?:dist|site)-packages[\\/]research)r<  external_sources     r7   r  r  #  s%     			5x@L  r9   c                 .    |y| j                  |      ryy)NFTr  )r<  r  s     r7   r  r  ,  s!     <(r9   c                 \    | 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.
    r2   Nr  ignore)errors...)r5   rV   )string	max_bytes	truncateds      r7   _truncate_by_bytesr  8  s8    
 g&Q7>>wx>XIur9   c                 b    	 t        | j                  d            S # t        t        f$ r Y y w xY w)Nr2   )r%  r5   UnicodeEncodeErrorr  r   s    r7   _get_size_in_bytesr  B  s3    5<<()) 23 s    ..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!limitr   )r%  r   r   )r   r  r%  r  r   )r   r  	byte_size	text_sizetruncated_values        r7   r&  r&  J  s    -
"5)IE
IZ!7,UJ?		9z#9 0*q.1E9)	sJNJ?@
 r9   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*$rf   rE  Nr  )r  compileVERBOSE
IGNORECASEmatch	groupdictr  mapr   rH  r   r   r  )r   VERSION_PATTERNpatternrf   release_tuples        r7   parse_versionr  g  s    O> jj/!G+


R]]"G
--(224Y?c#w}}S'9"1'=>?  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|\.rF  	threadinglocalr  r   )   	   contextvars
ContextVarFT)is_monkey_patchedzYInternal error in Sentry SDK: Could not parse Greenlet version from greenlet.__version__.r  )r   r  )geventgevent.monkeyr  r  r  rH  __version__r   rL   version_infor  greenleteventlet.patcherr  r  loggerr  )r  r  partversion_tupler  r  greenlet_versions          r7   _is_contextvars_brokenr    s    
3 #%88L&:L:L#Mbq#QR4SYR
 ['2 !!V+0H%m\B 3&6()=)=>#LLk X&+;f+D M S$  "  s:   4C C1C =6C 4C C 	CC	C#"C#c                        G  fdd      }|S )Nc                   .    e Zd Zd fd	ZddZd Zd Zy)1_make_threadlocal_contextvars.<locals>.ContextVarNc                 R    || _         || _                | _                | _        y r;   )_name_default_local_original_local)r   r  defaultr  s      r7   r   z:_make_threadlocal_contextvars.<locals>.ContextVar.__init__  s$    DJ#DM'DK#(7D r9   c                 L    t        | j                  d|xs | j                        S )Nr   )r  r  r  )r   r  s     r7   re   z5_make_threadlocal_contextvars.<locals>.ContextVar.get  s    4;;1IDMMJJr9   c                     t        t        j                  d            }| j                         }t	        | j
                  ||       || j                  _        |S )N@   )r   randomgetrandbitsre   setattrr  r  r   )r   r   tokenoriginal_values       r7   r~  z5_make_threadlocal_contextvars.<locals>.ContextVar.set  sE    **2./E!XXZND((%@ %DKKLr9   c                 |    t        | j                  |      | j                  _        | j                  j                  |= y r;   )r  r  r  r   r   )r   r  s     r7   resetz7_make_threadlocal_contextvars.<locals>.ContextVar.reset  s/     '(<(<e DDKK$$--e4r9   r;   )r   r   r   r   re   r~  r  r  s   r7   r  r    s    	+	K		5r9   r  r<   )r  r  s   ` r7   _make_threadlocal_contextvarsr    s    5 58 r9   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  Tr  F)
r  rL   r  aiocontextvarsr  r  r  r  r  r  )r  r  s     r7   _get_contextvarsr
    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                 P   d}	 | j                   j                  d| j                   j                  d| j                  S # t        $ r Y nw xY wd\  }}t	        | d      r6t        | j                  t              rd\  }}| j                  j                  } n7t        | t              r't	        | j                  d      rd\  }}| j                  } t	        | d      r| j                  }nt	        | d      r| j                  }|&t	        | d	      r| j                  dz   |z   }||z   |z   }|S )
zbReturn the qualified name of func. Works with regular function, lambda, partial and partialmethod.NrE  )r   r   _partialmethod)zpartialmethod(<function >)r   )zpartial(<function r  r   r   )im_classr   r   r  r  r   r  r   funcr   r   )r  func_qualnameprefixsuffixs       r7   qualname_from_functionr  "  s    MMM$$MM""MM
 	

   NFFt%&:], :""''	D'	"wtyy*'E3yyt^$))	z	"  4& OOc1MAM.7s   ;A   	AAc                     t        |       S r;   )r  )r  s    r7   transaction_from_functionr  J  s    !$''r9   disable_capture_eventc                       e Zd ZdZy)ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nr   r<   r9   r7   r  r  R  s    Hr9   r  c                   "    e Zd ZdZd Zd Zd Zy)TimeoutThreadzCreates a Thread which runs (sleeps) for a time duration equal to
    waiting_time and raises a custom ServerlessTimeout exception.
    c                     t         j                  j                  |        || _        || _        t        j
                         | _        y r;   )r  Threadr   waiting_timeconfigured_timeoutr(   _stop_event)r   r  r  s      r7   r   zTimeoutThread.__init__]  s5    !!$'("4$??,r9   c                 8    | j                   j                          y r;   )r  r~  r   s    r7   stopzTimeoutThread.stopd  s    r9   c                    | j                   j                  | j                         | j                   j                         ry t	        | j
                        }|| j
                  k  r|dz   }t        dj                  |            )Nr,   zZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)r  waitr  is_setr   r  r  r|   )r   integer_configured_timeouts     r7   runzTimeoutThread.runh  s     	d//0""$%()@)@%A" &(?(??)Ca)G& 'hoo*
 	
r9   N)r   r   r   r   r   r!  r&  r<   r9   r7   r  r  X  s    -
r9   r  c                     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)r5   base64	b64encoderV   r  r  warningr|   )originalbase64_string
utf8_bytesbase64_byteserrs        r7   	to_base64r2  ~  s    
 MX__W-
''
3$++G4   X;BBBQSVWWXs   7= 	A7&A22A7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  r5   r*  	b64decoderV   r  r  r,  r|   )r.  utf8_stringonly_valid_charsr0  r/  r1  s         r7   from_base64r9    s    
 K

*00?$++G4%%l3
 ''0   
188]8KS	
 	
 
s   AA 	B&BB
Components)r   r   rJ   queryfragmentc           	         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   r,   r/   rD  r   r   r;  rJ   r<  )r   r   r;  r   rH  r%  r   r   r   r:  r   rJ   r<  r   )urlremove_authorityremove_query_valuesrH  
parsed_urlquery_paramsnetloc_partsr   r   query_string
componentss              r7   sanitize_urlrH    s    
 #JJ,,EL !((..s3|q ))R F  &&F"" N#s55NO
 "''  __$$J *%%! Os   C0	ParsedUrlr@  r;  r<  c           	          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)rA  rB  rH  r   r?  rJ  )	rH  r   r:  r   r   rJ   rI  r;  r<  )r@  sanitizerC  base_urls       r7   	parse_urlrN    sn     dJ $$$$	
H $$ r9   c           	      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-  rater   Fr   r,   zW{source} Given sample rate is invalid. Sample rate must be between 0 and 1. Got {rate}.)r-  rP  T)
r   r
   r   mathisnanr  r,  r|   r   float)rP  r-  s     r7   is_valid_sample_raterT    s     dT7O,

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

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

 r9   c                 j    |y|D ]+  }|s|d   dk7  r|dz  }t        j                  ||       }|s+ y y)NFrD  $Tr  )r  
regex_listsubstring_matchingitem_matchermatcheds        r7   match_regex_listr[    sN    " !l2&6#&=CL))L$/ r9   c                     | 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     r7   is_sentry_urlr_  "  s^     	d 	6D(	6''t3	6 ''..#5	r9   c               #     K   	 ddl m}  t               }| j                         D ]R  }|j                  d   }|t	        |      }|j
                  -||vs2||j
                  f |j                  |       T 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~  distributions_normalize_module_namer   r  r  pkg_resourcesworking_setr   )r   yieldeddistr  normalized_namere  infos          r7   _generate_installed_modulesrk  /  s     A&%**, 
	1D==(D
 "8"><<+w0N)4<<77KK0
	1  A	  		 "-- 	AD(2DLL@@	AAsc   C4A: A: A: #A: 9C:	CB	C		BCCB7CCCCc                 "    | j                         S r;   )lower)r  s    r7   rd  rd  L  s    ::<r9   c                  @    t         t        t                     a t         S r;   )_installed_modulesr   rk  r<   r9   r7   _get_installed_modulesrp  Q  s     !!"="?@r9   c                 T    t               }|j                  |       }|y t        |      S r;   )rp  re   r  )packageinstalled_packagesr   s      r7   package_versionrt  Y  s.    /1 $$W-G!!r9   c                 L    |J |j                   |ur|j                  |      |r;   )r}  with_traceback)tpr   r   s      r7   reraiserx  c  s2    "$""2&&
Kr9   c                       y)z.No-op function for ensure_integration_enabled.Nr<   _a_ks     r7   _no_opr}  k  r>   r9   c                     K   yw)z4No-op function for ensure_integration_enabled_async.Nr<   rz  s     r7   _no_op_asyncr  q  s      	s   c                      y r;   r<   r   original_functions     r7   ensure_integration_enabledr  y       	r9   c                      y r;   r<   r   s    r7   r  r        
 	r9   c                 \     t         rt        t        t        t        f          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;   
sentry_sdk
get_clientget_integrationargskwargsr   r  sentry_patched_functions     r7   runnerz;ensure_integration_enabled.<locals>.patcher.<locals>.runner  s=    $$&66{CK($9&99*D;F;;r9   r  zP.argsr  zP.kwargs)r}  r	   r  r  r   r  s   ` r7   patcherz+ensure_integration_enabled.<locals>.patcher  s8    	< &1501&99'u&'//r9   )r   r   r   r*   r+   r   r  r  s   `` r7   r  r    s,    4  !!Q$1BC0 Nr9   c                      y r;   r<   r  s     r7    ensure_integration_enabled_asyncr    r  r9   c                      y r;   r<   r  s    r7   r  r    r  r9   c                 j     t         r$t        t        t        t        t
           f          fd}|S )z
    Version of `ensure_integration_enabled` for decorating async functions.

    Please refer to the `ensure_integration_enabled` documentation for more information.
    c                 j     d fd}t         u r t               |      S  t              |      S )Nc                     K   t        j                         j                         | i | d {   S  | i | d {   S 7 7 wr;   r  r  s     r7   r  zAensure_integration_enabled_async.<locals>.patcher.<locals>.runner  sQ     $$&66{CK.????0$A&AAA @As!   /AAAA	A	Ar  )r  r	   r  s   ` r7   r  z1ensure_integration_enabled_async.<locals>.patcher  s9    	B ,1501&99'u&'//r9   )r   r   r   r*   r   r+   r  s   `` r7   r  r    s1      !!Yq\/!:<MN0 Nr9   c                  *    t        j                         S r;   )timeperf_counter_nsr<   r9   r7   nanosecond_timer    s    ##%%r9   c                  B    t        t        j                         dz        S )Ng    eA)r   r  perf_counterr<   r9   r7   r  r    s    4$$&,--r9   c                  *    t        j                         S r;   )r  r  r<   r9   r7   nowr    s    r9   )get_hubis_module_patchedc                       y r;   r<   r<   r9   r7   get_gevent_hubr    s    r9   c                       yr   r<   )r  r  s     r7   r  r  	  s     r9   c                  2    t        d      xs t        d      S )Nr  _threadr  r<   r9   r7   	is_geventr    s    [)I->y-IIr9   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.
    NNN)	identr  r  r  r  thread_identr  current_threadmain_thread)r  	thread_idthread_name
gevent_hubs       r7   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;   )NNN)NTTN)TTN)NNNNN)NNr   r   Nr  )TTF)Tr   )r*  r3   r!  loggingrQ  rI   r  r  rN   rL   r  r  collectionsr   r   r   decimalr   	functoolsr   r   r	   numbersr
   urllib.parser   r   r   r   r   r  r   r  r  sentry_sdk.hubsentry_sdk._compatr   sentry_sdk._typesr   sentry_sdk.constsr   r   collections.abcr   typesr   r   typingr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   sentry_sdk.integrationsr(   r)   r*   r+   r   	getLoggerr  ro  r  r5  r   r8   r=   r\   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	Annotatedr  r  r  r  r5  r=  r@  r?  rP  rY  r`  re  ri  rz  r  r  HAS_CHAINED_EXCEPTIONSr  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r&  r  r  r  r
  HAS_REAL_CONTEXTVARSr  CONTEXTVARS_ERROR_MESSAGEr  r  r  r  r  r  r2  r9  r:  rH  rI  rN  rT  r[  r_  rk  rd  rp  rt  rx  r}  r  r  r  r  r  r  r  r  r  r  r  r  r<   r9   r7   <module>r     s#        	  	  
   "    3 3  K K+
   # + D).    & #0#AA 	q! 
		.	/ "**12( T	80D  78 '
2+
3
	""Z "F
 F
R-R -R`D
 D
N Ana'(IP
& +b 4 4  'V !6-
 Nb !,BC 7@ ]&D "J!.
$N#0 *	:1h1hB#7L $4#5   j %P(
 ##:; 	y 	#
I$$ #
L", &WX
)&X {$@A	8> 
A:
"		     -`      #B &.

0/J
0y7  V7  		s$   (K# K1 #K.-K.1K?>K?