U \k@sddlZddlZddlZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZerrddlmZmZnddlmZmZedddZe dZ!e"Z#gZ$d d Z%d d Z&ed dZ'ddZ(duddZ)Gddde*Z+e Gddde"Z,Gddde"Z-ddZ.ddZ/ddZ0dd Z1dvd"d#Z2dwd$d%Z3d&d'Z4d(d)Z5d*d+Z6dxd-d.Z7d/d0Z8d1d2Z9dyd4d5Z:dzd6d7Z;d{d8d9Ze?e@d>ZAeArd?d@ZBndAd@ZBd}dBdCZCdDdEZDdFdGZEdHdIZFd~dJdKZGdLdMZHdNdOZIddPdQZJdRdSZKGdTdUdUe"ZLdVdWZMdXdYZNdZd[ZOd\d]ZPd^d_ZQd`daZRGdbdcdce"ZSdddeZTddgdhZUddidjZVeVfdkdlZWd3ZXz*ddmlYmZZZesej[dnkrddl\Z\Wn6e]k rdoZXddpl^m_Z_Gdqdrdre"ZZYnXdsdtZ`dS)N)contextmanager)datetime)urlparse text_typeimplements_str string_types number_types int_typesPY2)MappingSequenceizsentry_sdk.errorscCst|dSN)global_repr_processorsappend) processorrA/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/utils.pyadd_global_repr_processor9srcCsdSrrrrrr_get_debug_hub=srccs@z dVWn0tk r:t}|dk r6|tYnXdSr) ExceptionrZ_capture_internal_exceptionsysexc_info)Zhubrrrcapture_internal_exceptionsBs  rcCs |tSr)epoch total_secondsvaluerrr to_timestampMsrcCs2|dkrt}nt|}|ddkr*d}d|iS)z+Creates a hint with the exc info filled in.Nrr)rrexc_info_from_errorrrrrevent_hint_with_exc_infoQs   r!c@seZdZdZdS)BadDsnzRaised on invalid DSNs.N)__name__ __module__ __qualname____doc__rrrrr"]sr"c@s6eZdZdZddZeddZd ddZd d ZdS) DsnzRepresents a DSN.c Cst|trt|j|_dStt|}|jdkr@td|j|j|_|j |_ |j |_ |j dkrv|jdkrpdprd|_ |j |_ |j std|j|_|jdd}ztt||_Wn2ttfk rtd |jpd ddYnXd|d|_dS) N)httphttpszUnsupported scheme %rr)PzMissing public key/r zInvalid project in DSN (%r)) isinstancer'dict__dict__rurlsplitrschemer"hostnamehostportusername public_keypassword secret_keypathrsplitintpop project_id ValueError TypeErrorjoin)selfrpartsr:rrr__init__es*     z Dsn.__init__cCs(|j}|j|jfdkr$d||jf}|S)zThe netloc part of a DSN.))r(r+)r)r*z%s:%s)r4r2r5)rBrvrrrnetlocsz Dsn.netlocNc Cs"t|j|j|j|j|j|j|dS)z*Returns the auth info object for this dsn.)r2r4r:r>r7r9client)Authr2rFr:r>r7r9)rBrGrrrto_authsz Dsn.to_authcCs.d|j|j|jrd|jpd|j|j|jfS)Nz%s://%s%s@%s%s%s@r-)r2r7r9rFr:r>rBrrr__str__sz Dsn.__str__)N) r#r$r%r&rDpropertyrFrIrLrrrrr'as   r'c@s0eZdZdZd ddZeddZd d d ZdS) rHz,Helper object that represents the auth info.Nr,c Cs4||_||_||_||_||_||_||_||_dSr)r2r4r:r>r7r9versionrG) rBr2r4r>r7r9rOrGr:rrrrDs z Auth.__init__cCsd|j|j|j|jfS)z'Returns the API url for storing events.z%s://%s%sapi/%s/store/)r2r4r:r>rKrrr store_api_urls zAuth.store_api_urlcCs~d|jfd|jfg}|dk r2|dtt|f|jdk rL|d|jf|jdk rf|d|jfddd d |DS) z!Returns the auth header a string.Z sentry_keyZsentry_versionNZsentry_timestampZ sentry_clientZ sentry_secretzSentry z, css|]\}}d||fVqdS)z%s=%sNr).0keyrrrr sz!Auth.to_header..)r7rOrstrrrGr9rA)rB timestamprErrr to_headers  zAuth.to_header)NrNNr,)N)r#r$r%r&rDrMrPrVrrrrrHs  rHcCst|ddpt|ddS)Nr%r#getattr)clsrrr get_type_namesrZcCst|dd}|dkr|SdS)Nr$)Nbuiltins __builtins__rW)rYmodrrrget_type_modules r^c Csjz|jd}|dWSttfk r.YnXdD]0}z|j|rLWdSWq4tk rbYq4Xq4dS)Nr#z sentry_sdk.)Z__traceback_hide____tracebackhide__TF) f_globals startswithAttributeErrorKeyErrorf_localsr)framer]Z flag_namerrrshould_hide_frames    rfccs$|dk r t|js|V|j}qdSr)rftb_frametb_next)tbrrr iter_stackss rjcCs4|s|St||kr(|d|ddS|d|S)N...)len)rlengthrrr slim_strings  rpc Cs6d}d}|dk rVt|drVz||}Wnttfk rDd}YnX|dk rV|}|dkrzt|}Wn"ttfk rgdgfYSX|sgdgfStd||}t |d|t |}zNdd|||D} t || d} dd||d|D} | | | fWSt k r0gdgfYSXdS) N get_sourcerr cSsg|]}t|dqS rpstriprQlinerrr sz'get_lines_from_file..rtcSsg|]}t|dqSrsrurwrrrrys)hasattrrr ImportErrorIOError splitlines linecachegetlinesOSErrormaxminrnrprv IndexError) filenamelinenoloadermoduleZ context_linessourceZ source_strZ lower_boundZ upper_bound pre_context context_line post_contextrrrget_lines_from_files:    rcCsz |jj}Wntk r$d}YnXz|jd}Wntk rRgdgfYSXz|jd}Wntk rzd}YnX|d}|dk r|rt||||SgdgfS)Nr# __loader__r )f_code co_filenamerr`r)re tb_linenoabs_pathrrrrrrget_source_context's     rcCs,z t|WStk r&t|YSXdSr)rr safe_reprrrrrsafe_str;s rcCsnzRt|}t|tr |dd}z|ddWWStk rN|YWSXWntk rhYdSXdS)Nutf-8replacelatin1zunicode-escape )reprr.bytesdecodeencoder)rrErrrrCs  rc s6t$dkrt|r2tW5QRSzdkrd}tD]L}t<|||}|tk r|W5QRWW5QRSW5QRXqLt|tt fṙfdd|DW^W5QRSt|t rfddt| DW&W5QRSt |WW5QRS|XW5QRXdS)Nrmemoremaining_depthcsg|]}t|ddqSr )rr)object_to_json)rQxrrrryrs z"object_to_json..cs(i|] \}}t|t|ddqSr)rrrQkvrrr zsz"object_to_json..r) rMemomemoize CYCLE_MARKER unmemoizerNotImplementedr.listtupler itemsr)objrrZhintsrresultrrrr_s0     0    rcCs,i}|jD]\}}t||t|<q|Sr)rdrrrT)rerErRrrrrextract_localssrcCszp|dr|dd}|ddd}||kr>tj|WStj|j}||tj dddd tj WSt k r|YSXdS)Nz.pyc.r r) endswithsplitosr:basenamermodules__file__r;seplstripr)rr base_moduleZbase_module_pathrrrfilename_for_modules   rTc Cst|dd}|r"|jj}|jj}nd}d}z|jd}Wntk rPd}YnX|dkr`|j}t||\}}} t||p|d|rt j |nd|pd||||| d} |rt || d<| S)Nrr#z )rrfunctionrrrrrvars) rXrrco_namer`rf_linenorrrr:abspathr) rer with_localsrrrrrrrrErrrserialize_frames2      rcsdfddt|DiS)Nframescsg|]}t|j|jdqS))rr)rrgr)rQrirrrrys z-stacktrace_from_traceback..)rj)rirrrrstacktrace_from_tracebacks  rcCsJd}g}t}|dk r:t|s2|t||d|j}q|d|iS)NTrr)r _getframerfrrf_backreverse)rr_rfrrrcurrent_stacktracesrcCs t|ddS)NerrnorW) exc_valuerrr get_errnosrcCsz|dk rt|}nd}|dk rB|p$i}|di}|dd|i|dkrPd}n|d}t|t|t||t||dS)NmetarcodeTr)rtyper mechanism stacktrace)r setdefaultr^rZrr)exc_typerriclient_optionsrrZmechanism_metarrrr!single_exception_from_error_tuples   r__suppress_context__ccs|\}}}g}t}|dk r|dk rt||kr|||fV|||t||jrb|j}n|j}|dkrrqt|}|}t|dd}qdS)N __traceback__) setidraddr __cause__ __context__rrX)rrrriZseen_exceptionsZseen_exception_idscauserrrwalk_exception_chains(    rccs |VdSrrr rrrr(sc Cs<|\}}}g}t|D] \}}}|t|||||q|Sr)rrr)rrrrrrirErrrexceptions_from_error_tuple-s rcCs4z t|WStk r.t|ddYSXdS)Nr r)rUnicodeDecodeErrorrrrrr to_string>s rccsHd|kr|dVd|krD|ddp*dD]}d|kr,|dVq,dS)Nr exceptionvaluesr)geteventrrrriter_event_stacktracesFs  rccs,t|D]}|dpdD] }|VqqdSNrr)rr)rrrerrriter_event_framesPs rcCs&t|D]}t|d||dq|S)Nr)in_app_excludein_app_include)rhandle_in_app_implr)rrrrrrr handle_in_appWs rcCs|sdSd}|D]\}|d}|dk r0|rd}q|d}|sBqqt||rZd|d<d}qt||rd|d<q|s|D]}|ddkrvd|d<qv|S)NFin_appTr)r_module_in_set)rrrZ any_in_apprerrrrrrcs,      rcCst|tr"t|dkr"|\}}}nZt|trvt|dd}|dk rNt|}|}q|t\}}}||k r|d}|}t|}nt|||fS)Nrlr) r.rrn BaseExceptionrXrrrr?)errorrrrirrrrs    rcCs*t|}t|}ddt|||id|fS)Nrr)levelr)rr!r)rrrZhintrrrevent_from_exceptionsrcCs6|sdS|pdD] }||ks*||drdSqdS)NFrrT)ra)nameritemrrrrs  rc@seZdZddZdS)AnnotatedValuecCs||_||_dSrrmetadata)rBrrrrrrDszAnnotatedValue.__init__N)r#r$r%rDrrrrrsrcs,fdd|\}}|dk r(||d<|S)Ncst|trri}i}|D]J\}}|dkr,q|\||<||<||dkrR||=||dkr||=q||pndfSt|trt|ttfsg}i}t|D]@\}}|\}|t|<|||t|dkr|t|=q||pdfSt|t r |j dd|j ifS|dfS)Nr-r) r.r rr rr enumeraterTrrrr)rZdict_rvrrrZlist_rviZnew_vinnerrrrs0        zflatten_metadata..innerZ_metar)rrrrrflatten_metadatas   rcCsjt|dd|dd}|rF|ddp.dD]}t|ddq0t|ddt|dddS)Nrrrrrequest breadcrumbs)strip_stacktrace_mutrstrip_request_mutstrip_breadcrumbs_mutrrrrstrip_event_muts rcCs*|sdS|ddpdD] }t|qdSr)rstrip_frame_mut)rrerrrrsrcCs,|sdS|dd}|sdSt||d<dS)Ndata)r strip_databag)rr rrrrs  rcCs.|sdStt|D]}t||||<qdSr)rangernr )rrrrrrsrcCsd|krt|d|d<dS)Nr)r )rerrrr sr c@s$eZdZddZddZddZdS)rcCs i|_dSr)_innerrKrrrrDsz Memo.__init__cCs$t||jkrdS||jt|<dS)NTF)rr rBrrrrrsz Memo.memoizecCs|jt|ddSr)r r=rrrrrrszMemo.unmemoizeN)r#r$r%rDrrrrrrrsrcCs|dkr dS|tkrdSt|tr0t|dSt|trLdd|DSt|trrt|ttfsrdd|DSt|t rt t |j |j St|t tst|St|tr|ddS|S) Nzz%Y-%m-%dT%H:%M:%SZcSsi|]\}}|t|qSr convert_typesrrrrr%sz!convert_types..cSsg|] }t|qSrr)rQrrrrry'sz!convert_types..rr)rr.rrstrftimer rr rrrrrrrrr)rrrrrs"     rcCst|trtd|dkr.tddddggiSt|tr@t|St|tri}t|D]<\}\}}||krt|d|iSt ||d|d||<qZ|St|t rg}t|D]:\}}||krt|d|iS| t ||d|dq|S|S) Nz(bytes should have been normalized beforerrem!limitrrnr )r max_breadth) r.rAssertionErrorrr strip_stringr rrr r r)rrrZrv_dictrrrZrv_listrrrr 3s<    r cCsL|s|St|}||krHt|d|dd|dd|d|ggddS|S)Nrlrmrrrnrr)rnr)r max_lengthrorrrrSsrc sD|d}|stdtt|}g}d}dg}fdd|ddD]}||t|7|t|7}|s|td|}||} t| tr| fd d | j d D| j } |t|7}t| 7|| qJ||dt|d7|t|d7}d |}t|ks(t |s2|St|||d dS)zFormat a string containing %s for placeholders and call `strip_string` on each parameter. The string template itself does not have a maximum length. TODO: handle other placeholders, not just %s z%sz No formatting placeholders foundrcsfddt|DS)Ncs.g|]&\}}t|tr&|dkr&|n|qS)r)r.r )rQrr rv_lengthrrryvsz.realign_remark..)r)remarkrrrrealign_remarkus z(format_and_strip..realign_remarkNrzNot enough params.c3s|]}|VqdSrr)rQr)rrrrSsz#format_and_strip..rr-rr)rr?rreversedrrnr=r.rextendrrrAr) templateparamsrchunksZ rv_remarksZrv_original_lengthrEchunkparamZstripped_paramr)rrrformat_and_stripdsH           r%) ContextVar)rlrNF)localc@s$eZdZddZddZddZdS)r&cCs||_t|_dSr)_namer'_local)rBrrrrrDszContextVar.__init__cCst|jd|SNr)rXr))rBdefaultrrrrszContextVar.getcCst|jd|dSr*)setattrr))rBrrrrrszContextVar.setN)r#r$r%rDrrrrrrr&sr&cCs~zd|jj|jj|jfWStk r.YnXt|ddpJt|ddpJd}|sTdSzd|j|fWStk rxYnX|S)Nz%s.%s.%sr%r#z%s.%s)Zim_classr$r#rrX)funcZ func_qualnamerrrtransaction_from_functions"r.)N)rk)NN)rN)NT)NT)T)NN)NN)NN)NN)rr)rk)arrr~Zlogging contextlibrrZsentry_sdk._compatrrrrrr r ZAnyDictUnionIteratorZTupleOptionalZListSetZTypeZ ClientOptionsrZExcInfo collectionsr r collections.abcrZ getLoggerloggerobjectrrrrrrr!r?r"r'rHrZr^rfrjrprrrrrrrrrrrrrzrZHAS_CHAINED_EXCEPTIONSrrrrrrrrrrrrrrrrr rrr rr%ZHAS_REAL_CONTEXTVARSZ contextvarsr& version_infoZaiocontextvarsr{ threadingr'r.rrrrs  $    <-  , ( "    !     &    9