U \h@sddlmZddlZddlmZmZddlmZmZddl m Z ddl m Z ddl mZz ddlZWnek r|dZYnXddlmZmZmZmZdd lmZm Z m!Z!m"Z"Gd d d e Z#d d Z$ddZ%ddZ&GdddeZ'ddZ(ddZ)ddZ*dS))absolute_importN)Hub_should_send_default_pii)capture_internal_exceptionsevent_from_exception) Integration)SentryWsgiMiddleware)RequestExtractor)RequestFlask_request_ctx_stack_app_ctx_stack)appcontext_pushedappcontext_tearing_downgot_request_exceptionrequest_startedc@s*eZdZdZdZdddZeddZdS) FlaskIntegrationflaskNendpointcCs&d}||krtd||f||_dS)N)rurlz7Invalid value for transaction_style: %s (must be in %s)) ValueErrortransaction_style)selfrZTRANSACTION_STYLE_VALUESrN/opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/integrations/flask.py__init__(szFlaskIntegration.__init__csDttttttttt j fdd}|t _ dS)Ncs4tjtdkr||Stfdd||S)Ncsf||SNr)akw)old_apprrrAzNFlaskIntegration.setup_once..sentry_patched_wsgi_app..)rcurrentget_integrationrr)renvironZstart_responserrrsentry_patched_wsgi_app<s  z.sentry_patched_wsgi_app) rconnect _push_appctxr _pop_appctxr_request_startedr_capture_exceptionr __call__)r'rr%r setup_once2s     zFlaskIntegration.setup_once)r)__name__ __module__ __qualname__ identifierrr staticmethodr.rrrrr#s  rc OsJtj}|tdk rF|}||tj_| }d|_ W5QRXdS)Nr) rr"r#rZ push_scope __enter__r topsentry_sdk_scope_managerconfigure_scope_name)argskwargshub scope_managerscoperrrr)Hs r)cOs(ttjdd}|dk r$|ddddS)Nr6)getattrr r5__exit__)r9r:r<rrrr*Usr*c Ks\tj}|t}|dkrdSttjj}t jj }| }| t |||W5QRXdSr)rr"r#rweakrefrefr r5requestr appr7Zadd_event_processor_make_request_event_processor)senderr:r; integration weak_requestrCr=rrrr+\s  r+c@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)FlaskRequestExtractorcCs|jjSr)rBr$r&rrrenvnszFlaskRequestExtractor.envcCs|jjSr)rBcookiesr&rrrrJrszFlaskRequestExtractor.cookiescCs|jjSr)rBdatar&rrrraw_datavszFlaskRequestExtractor.raw_datacCs|jjSr)rBformr&rrrrMzszFlaskRequestExtractor.formcCs|jjSr)rBfilesr&rrrrN~szFlaskRequestExtractor.filescCs|jjSr)rBis_jsonr&rrrrOszFlaskRequestExtractor.is_jsoncCs |jSr)rBZget_jsonr&rrrjsonszFlaskRequestExtractor.jsoncCs|jSr)Zcontent_length)rfilerrr size_of_filesz"FlaskRequestExtractor.size_of_fileN) r/r0r1rIrJrLrMrNrOrPrRrrrrrHmsrHcsfdd}|S)Nc s}|dkr|Sz2jdkr,|jj|d<njdkrB|jj|d<Wntk rXYnXtt||W5QRXtrtt |W5QRX|S)NrZ transactionr) rZurl_rulerZrule ExceptionrrHZextract_into_eventr_add_user_to_event)eventhintrBrFrGrrinners   z,_make_request_event_processor..innerr)rCrGrFrXrrWrrDsrDcKsFtj}|tdkrdSt||jjdddd\}}|j||ddS)NrF)typeZhandled)Zclient_optionsZ mechanism)rV)rr"r#rrZclientoptionsZ capture_event)rE exceptionr:r;rUrVrrrr,s r,c Cstdkr dStj}|dkrdSt|di}z||d<Wntk rVYnXz|j|d<|d<Wntk rYnXz|j|d<Wntk rYnXW5QRXdS)Nuseridemailusername) flask_loginZ current_userr setdefaultZget_idAttributeErrorr^rSr_)rUr\Z user_inforrrrTs&  rT)+ __future__rr@Zsentry_sdk.hubrrZsentry_sdk.utilsrrZsentry_sdk.integrationsrZsentry_sdk.integrations.wsgirZ$sentry_sdk.integrations._wsgi_commonr Z_ScopedResponseZAnyDictZImmutableTypeConversionDictZImmutableMultiDictZ FileStorageUnionCallabler` ImportErrorrr r r r Z flask.signalsrrrrrr)r*r+rHrDr,rTrrrrs(      %