U 췀g@sddlZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZmZmZmZzddlmZdd lmZWnek red YnXdd lmZerHdd lmZdd lmZddl mZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl%m&Z&ddlm'Z'ddl(m)Z)m*Z*e+eddr`ddZ,n ddl-m,Z,dZ.GdddeZ/ee/ddZ0ddZ1Gd d!d!e Z2d"d#Z3dS)$N) Integration DidNotEnable)RequestExtractor)SentryWsgiMiddleware)should_send_default_pii)SOURCE_FOR_STYLE)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionreraise) HTTPException)RequestzPyramid not installed) TYPE_CHECKING)Response)Any)_ScopedResponse)Callable)Dict)Optional)RequestCookies)_FieldStorageWithFile)ExcInfo)EventEventProcessorauthenticated_useridcCs|jSNr)requestrM/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/pyramid.pyr+sr route_nameZ route_patternc@s4eZdZdZdeZdZd ddZeddZd S) PyramidIntegrationpyramidz auto.http.r!cCs"|tkrtd|tf||_dS)Nz7Invalid value for transaction_style: %s (must be in %s))TRANSACTION_STYLE_VALUES ValueErrortransaction_style)selfr'rrr__init__=szPyramidIntegration.__init__cszddlm}|jtfdd}||_ttdrPtjfdd}|t_|jj t t fdd }||j_ dS) Nr)routercsjtt}|dkr(||f||Stt|j|t}|t t ||||f||Sr) sentry_sdk get_clientget_integrationr" _set_transaction_name_and_sourceZget_current_scoper'Zget_isolation_scopeZadd_event_processor_make_event_processorweakrefref)registryrargskwargs integrationscope) old_call_viewrrsentry_patched_call_viewMsz?PyramidIntegration.setup_once..sentry_patched_call_viewinvoke_exception_viewcsJ|f||}|jrFt|jrF|jdkrFttdk rFt|j|S)Ni)exc_infoallZ status_intr+r,r-r"_capture_exception)r(r3r4rv)old_invoke_exception_viewrr$sentry_patched_invoke_exception_viewcs  zKPyramidIntegration.setup_once..sentry_patched_invoke_exception_viewcs&fdd}t|tjd}|||S)Ncs@z||WStk r:t}t|t|YnXdSr) Exceptionsysr:r<r )environstart_responseZeinfo) old_wsgi_callr(rrsentry_patched_inner_wsgi_callys zgPyramidIntegration.setup_once..sentry_patched_wsgi_call..sentry_patched_inner_wsgi_call)Z span_origin)rr"origin)r(rBrCrEZ middleware)rDr(rsentry_patched_wsgi_callvs  z?PyramidIntegration.setup_once..sentry_patched_wsgi_call) r#r*Z _call_view functoolswrapshasattrr r9ZRouter__call__r r")r*r8r?rHr)r7r>rDr setup_onceFs   zPyramidIntegration.setup_onceN)r!) __name__ __module__ __qualname__ identifierrFr'r) staticmethodrMrrrrr"7s   r"cCsN|ddkst|dtrdSt|tjdddd\}}tj||ddS)Nrr#F)typeZhandled)Zclient_optionsZ mechanism)hint) issubclassr r r+r,optionsZ capture_event)r:eventrTrrrr<s r<cCsFz,|jj|jjd}|j||t|dWntk r@YnXdS)Nr )source)Z matched_routenamepatternZset_transaction_namerr@)r6r'rZname_for_stylerrrr.s r.c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)PyramidRequestExtractorcCs|jjSr)rpath_urlrGrrrurlszPyramidRequestExtractor.urlcCs|jjSr)rrBrGrrrenvszPyramidRequestExtractor.envcCs|jjSr)rcookiesrGrrrr_szPyramidRequestExtractor.cookiescCs|jjSr)rtextrGrrrraw_datasz PyramidRequestExtractor.raw_datacCsdd|jjDS)NcSs"i|]\}}t|dds||qSfilenameNgetattr.0keyvaluerrr s z0PyramidRequestExtractor.form..rPOSTitemsrGrrrforms zPyramidRequestExtractor.formcCsdd|jjDS)NcSs"i|]\}}t|ddr||qSrbrdrfrrrrjs z1PyramidRequestExtractor.files..rkrGrrrfiless zPyramidRequestExtractor.filescCs4|j}zt|jWStk r.YdSXdS)Nr)fileosfstatfilenost_sizer@)r(Zpostdatarprrr size_of_files z$PyramidRequestExtractor.size_of_fileN) rNrOrPr]r^r_rarnrorurrrrr[sr[csfdd}|S)Nc sj}|dkr|Stt||W5QRXtrft"|di}|dt|W5QRX|S)Nuserid)rr[Zextract_into_eventr setdefaultr)rWrTrZ user_info weak_requestrrpyramid_event_processors z6_make_event_processor..pyramid_event_processorr)rzr5r{rryrr/s r/)4rIrqrAr0r+Zsentry_sdk.integrationsrrZ$sentry_sdk.integrations._wsgi_commonrZsentry_sdk.integrations.wsgirZsentry_sdk.scoperZsentry_sdk.tracingrZsentry_sdk.utilsrr r r Zpyramid.httpexceptionsr Zpyramid.requestr ImportErrortypingrZpyramid.responserrrrrrZ webob.cookiesrZ webob.requestrrZsentry_sdk._typesrrrerZpyramid.securityr%r"r<r.r[r/rrrrsJ                 T *