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)epochZ 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__rZurlsplitrschemer!ZhostnamehostportZusername public_keyZpassword secret_keypathrsplitintpop project_id ValueError TypeErrorjoin)selfrpartsr5rrr__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)r1r0r2)r=rvrrrnetlocsz Dsn.netlocNc Cs"t|j|j|j|j|j|j|dS)z*Returns the auth info object for this dsn.)r0r1r5r9r3r4client)Authr0rAr5r9r3r4)r=rBrrrto_authsz Dsn.to_authcCs.d|j|j|jrd|jpd|j|j|jfS)Nz%s://%s%s@%s%s%s@r,)r0r3r4rAr5r9r=rrr__str__sz Dsn.__str__)N) r"r#r$r%r?propertyrArDrGrrrrr&as   r&c@s0eZdZdZd ddZeddZd d d ZdS) rCz,Helper object that represents the auth info.Nr+c Cs4||_||_||_||_||_||_||_||_dSr)r0r1r5r9r3r4versionrB) r=r0r1r9r3r4rJrBr5rrrr?s z Auth.__init__cCsd|j|j|j|jfS)z'Returns the API url for storing events.z%s://%s%sapi/%s/store/)r0r1r5r9rFrrr 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..)r3rJrstrrrBr4r<)r=Z timestampr@rrr to_headers  zAuth.to_header)NrINr+)N)r"r#r$r%r?rHrKrPrrrrrCs  rCcCst|ddpt|ddS)Nr$r"getattr)clsrrr get_type_namesrTcCst|dd}|dkr|SdS)Nr#)Nbuiltins __builtins__rQ)rSmodrrrget_type_modules rXc Csjz|jd}|dWSttfk r.YnXdD]0}z|j|rLWdSWq4tk rbYq4Xq4dS)Nr"z sentry_sdk.)Z__traceback_hide____tracebackhide__TF) f_globals startswithAttributeErrorKeyErrorf_localsr)framerWZ flag_namerrrshould_hide_frames    r`ccs$|dk r t|js|V|j}qdSr)r`tb_frametb_next)tbrrr iter_stackss rdcCs4|s|St||kr(|d|ddS|d|S)N...)len)rlengthrrr slim_strings  rjc 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 rjstriprLlinerrr sz'get_lines_from_file..rncSsg|]}t|dqSrmrorqrrrrss)hasattrrl ImportErrorIOError splitlines linecachegetlinesOSErrormaxminrhrjrp 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_filenamerrZr)r_ 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)rr@rrrrCs  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)rLxrrrrsrs z"object_to_json..cs(i|] \}}t|t|ddqSr)rrrLkvrrr zsz"object_to_json..r) rMemomemoize CYCLE_MARKER unmemoizerNotImplementedr-listtupler itemsr)objrrZhintsrresultrrrr_s0     0    rcCs,i}|jD]\}}t||t|<q|Sr)r^rrrO)r_r@rMrrrrextract_localssrcCszp|dr|dd}|ddd}||kr>tj|WStj|j}||tj dddd tj WSt k r|YSXdS)Nz.pyc.r r) endswithsplitosr5basenamermodules__file__r6seplstripr)rrZ 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 )r~rfunctionrrrrrvars) rRrrco_namerZrf_linenorrrr5abspathr) r_r with_localsrrrrrrrr@rrrserialize_frames2      rcsdfddt|DiS)Nframescsg|]}t|j|jdqS))rr)rrar)rLrcrrrrss z-stacktrace_from_traceback..)rd)rcrrrrstacktrace_from_tracebacks  rcCsJd}g}t}|dk r:t|s2|t||d|j}q|d|iS)NTrr)r _getframer`rrf_backreverse)rrYrfrrrcurrent_stacktracesrcCs t|ddS)NerrnorQ) 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 setdefaultrXrTrr)exc_typerrcclient_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__rrR)rrrrcZseen_exceptionsZseen_exception_idscauserrrwalk_exception_chains(    rccs |VdSrrrrrrr(sc Cs<|\}}}g}t|D] \}}}|t|||||q|Sr)rrr)rrrrrrcr@rrrexceptions_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)rrr_rrriter_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_appr_rrrrrrcs,      rcCst|tr"t|dkr"|\}}}nZt|trvt|dd}|dk rNt|}|}q|t\}}}||k r|d}|}t|}nt|||fS)Nrfr) r-rrh BaseExceptionrRrrrr:)errorrrrcrrrrs    rcCs*t|}t|}ddt|||id|fS)Nrr)levelr)rr r)rrrZhintrrrevent_from_exceptionsrcCs6|sdS|pdD] }||ks*||drdSqdS)NFrrT)r[)nameritemrrrrs  rc@seZdZddZdS)AnnotatedValuecCs||_||_dSrrmetadata)r=rrrrrr?szAnnotatedValue.__init__N)r"r#r$r?rrrrrsrcs,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 enumeraterOrrrr)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)rr_rrrrsrcCs,|sdS|dd}|sdSt||d<dS)Ndata)r strip_databag)rrrrrrs  rcCs.|sdStt|D]}t||||<qdSr)rangerhr)rrrrrrsrcCsd|krt|d|d<dS)Nr)r)r_rrrrsrc@s$eZdZddZddZddZdS)rcCs i|_dSr)_innerrFrrrr?sz Memo.__init__cCs$t||jkrdS||jt|<dS)NTF)rrr=rrrrrsz Memo.memoizecCs|jt|ddSr)rr8rrrrrrszMemo.unmemoizeN)r"r#r$r?rrrrrrrsrcCs|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)rLrrrrrs'sz!convert_types..rr)rr-rrstrftimer rr rrr rrrrrr)rrrrr s"     r cCst|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!limitrrhr )r max_breadth) r-rAssertionErrorrr strip_stringr rrrr r)rrrZrv_dictrrrZrv_listrrrr3s<    rcCsL|s|St|}||krHt|d|dd|dd|d|ggddS|S)Nrfrgr rrhr r)rhr)rZ max_lengthrirrrrSsrc 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 )rLrr rv_lengthrrrsvsz.realign_remark..)r)remarkrrrrealign_remarkus z(format_and_strip..realign_remarkNrzNot enough params.c3s|]}|VqdSrr)rLr)rrrrNsz#format_and_strip..r r,rr)rr:rreversedrrhr8r-rextendrrr<r) templateZparamsrZchunksZ rv_remarksZrv_original_lengthr@chunkZparamZstripped_paramr)rrrformat_and_stripdsH           r) ContextVar)rfrIF)localc@s$eZdZddZddZddZdS)rcCs||_t|_dSr)_namer_local)r=rrrrr?szContextVar.__init__cCst|jd|SNr)rRr)r=defaultrrrrszContextVar.getcCst|jd|dSr)setattrr)r=rrrrrszContextVar.setN)r"r#r$r?rrrrrrrsrcCs~zd|jj|jj|jfWStk r.YnXt|ddpJt|ddpJd}|sTdSzd|j|fWStk rxYnX|S)Nz%s.%s.%sr$r"z%s.%s)Zim_classr#r"rrR)funcZ func_qualnamerrrtransaction_from_functions"r#)N)re)NN)rN)NT)NT)T)NN)NN)NN)NN)r r )re)arrrxZlogging contextlibrrZsentry_sdk._compatrrrrrr r ZAnyZDictZUnionIteratorZTupleZOptionalZListSetZTypeZ ClientOptionsrZExcInfo collectionsr r collections.abcrZ getLoggerZloggerobjectrrrrrrr r:r!r&rCrTrXr`rdrjrrrrrrrrrrrrrtrZHAS_CHAINED_EXCEPTIONSrrrrrrrrrrrrrrrrrrr rrrZHAS_REAL_CONTEXTVARSZ contextvarsr version_infoZaiocontextvarsru threadingrr#rrrrs  $    <-  , ( "    !     &    9