U \@sddlmZddlZddlZddlZddlmZddlmZddl m Z m Z ddl m Z mZddlmZddlmZdd lmZdd lmZe ed drd d Z!n dd l"m!Z!GdddeZ#ddZ$GdddeZ%ddZ&dS))absolute_importN) HTTPException)Request)Hub_should_send_default_pii)capture_internal_exceptionsevent_from_exception)reraise) Integration)RequestExtractor)SentryWsgiMiddlewareauthenticated_useridcCs|jSNr )requestr /pyramid.pyr !src@s*eZdZdZdZdddZeddZdS) PyramidIntegrationpyramidN route_namecCs&d}||krtd||f||_dS)N)r route_patternz7Invalid value for transaction_style: %s (must be in %s)) ValueErrortransaction_style)selfrZTRANSACTION_STYLE_VALUESrrr__init__0szPyramidIntegration.__init__cs@ddlm}|jfdd}||_|jfdd}||_dS)Nr)Routerc stj}|t}|dkr*||f||S|}|tt||W5QRXz||f||WSt k rt }t |t |YnXdSr)rcurrentget_integrationrZconfigure_scopeZadd_event_processor_make_event_processorweakrefref Exceptionsysexc_info_capture_exceptionr )rrargskwargshub integrationZscoper#)old_handle_requestrrsentry_patched_handle_requestAs  zDPyramidIntegration.setup_once..sentry_patched_handle_requestcs<tj}|t}|dkr$||Stfdd||S)Ncsf||Srr)akw) old_wsgi_callrrr_zQPyramidIntegration.setup_once..sentry_patched_wsgi_call..)rrrrr )renvironZstart_responser'r()r-rrsentry_patched_wsgi_callXs  z?PyramidIntegration.setup_once..sentry_patched_wsgi_call)Zpyramid.routerrZhandle_request__call__)rr*r2r)r)r-r setup_once:s   zPyramidIntegration.setup_once)r)__name__ __module__ __qualname__Z identifierrr staticmethodr4rrrrr+s  rcKsd|ddkst|dtrdStj}|tdkr6dSt||jjdddd\}}|j ||ddS)NrrF)typeZhandled)Zclient_optionsZ mechanism)hint) issubclassrrrrrrZclientZoptionsZ capture_event)r#r&r'eventr:rrrr$fs r$c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)PyramidRequestExtractorcCs|jjSr)rZpath_urlr1rrrurlwszPyramidRequestExtractor.urlcCs|jjSr)rr0r1rrrenvzszPyramidRequestExtractor.envcCs|jjSr)rcookiesr1rrrr@~szPyramidRequestExtractor.cookiescCs|jjSr)rtextr1rrrraw_datasz PyramidRequestExtractor.raw_datacCsdd|jjDS)NcSs"i|]\}}t|dds||qSfilenameNgetattr.0keyvaluerrr s z0PyramidRequestExtractor.form..rZPOSTitemsr1rrrforms zPyramidRequestExtractor.formcCsdd|jjDS)NcSs"i|]\}}t|ddr||qSrCrErGrrrrKs z1PyramidRequestExtractor.files..rLr1rrrfiless zPyramidRequestExtractor.filescCs4|j}zt|jWStk r.YdSXdS)Nr)fileosfstatfilenost_sizer!)rZpostdatarPrrr size_of_files z$PyramidRequestExtractor.size_of_fileN) r5r6r7r>r?r@rBrNrOrUrrrrr=vsr=csfdd}|S)Nc s}|dkr|Sz2jdkr,|jj|d<njdkrB|jj|d<Wntk rXYnXtt||W5QRXtrt| di}t ||d<W5QRX|S)NrZ transactionruserid) rZ matched_routenamepatternr!rr=Zextract_into_eventr setdefaultr )r<r:rZ user_infor( weak_requestrrevent_processors"   z._make_event_processor..event_processorr)r\r(r]rr[rrsr)'Z __future__rrQr"rZpyramid.httpexceptionsrZpyramid.requestrZsentry_sdk.hubrrZsentry_sdk.utilsrrZsentry_sdk._compatr Zsentry_sdk.integrationsr Z$sentry_sdk.integrations._wsgi_commonr Zsentry_sdk.integrations.wsgir ZResponseZAnyZ_ScopedResponseCallableZDictZOptionalZRequestCookiesZcgi_FieldStorageZExcInforFr Zpyramid.securityrr$r=rrrrrs$          ;)