U 췀g @sddlZddlmZmZddlmZmZddlmZddl m Z ddl m Z ddl mZmZmZmZddlmZerdd lmZmZmZmZdd lmZmZdd lmZdd lmZmZz ddlZWne k rdZYnXz@dd l!m"Z"m#Z#ddl!m$Z%ddl&m'Z'm(Z(m)Z)ddl*m+Z+Wne k r<edYnXz ddl,Z,Wne k rhedYnXdZ-GdddeZ.ddZ/ddZ0ddZ1GdddeZ2ddZ3ee.d d!Z4d"d#Z5dS)$N) DidNotEnable Integration)DEFAULT_HTTP_METHODS_TO_CAPTURERequestExtractor)SentryWsgiMiddleware)should_send_default_pii)SOURCE_FOR_STYLE)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionpackage_version) TYPE_CHECKING)AnyCallableDictUnion)EventEventProcessor)_ScopedResponse) FileStorageImmutableMultiDict)FlaskRequestrequest)before_render_templategot_request_exceptionrequest_started)MarkupzFlask is not installedzblinker is not installed)endpointurlc@s8eZdZdZdeZdZdefddZeddZ d S) FlaskIntegrationflaskz auto.http.rcCs4|tkrtd|tf||_tttj||_dS)Nz7Invalid value for transaction_style: %s (must be in %s))TRANSACTION_STYLE_VALUES ValueErrortransaction_styletuplemapstrupperhttp_methods_to_capture)selfr&r+r-K/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/flask.py__init__:szFlaskIntegration.__init__csbtd}|dkrtd|dkr(tdttttttt j fdd}|t _ dS)Nr"zUnparsable Flask version.)r z Flask 0.10 or newer is required.csZttdkr||Stt}tfddtj|rH|jntd}|||S)Ncsf||SNr-)akw)old_appr,r-r.azNFlaskIntegration.setup_once..sentry_patched_wsgi_app..)Z span_originr+) sentry_sdk get_clientget_integrationr!roriginr+r)r,environZstart_response integrationZ middlewarer4r,r.sentry_patched_wsgi_appYs   z.sentry_patched_wsgi_app) r rrconnect_add_sentry_tracer_request_startedr_capture_exceptionr__call__)versionr?r-r=r. setup_onceHs    zFlaskIntegration.setup_onceN) __name__ __module__ __qualname__ identifierr:r&rr/ staticmethodrFr-r-r-r.r!4s  r!cKs4d|kr dSt}t|}||d<||d<dS)NZ sentry_traceZsentry_trace_meta)r7get_current_scoperZtrace_propagation_meta)sendertemplatecontextextrascopeZ trace_metar-r-r.rAns  rAcCsFz,|jj|jjd}|j||t|dWntk r@YnXdS)N)r r)source)Zurl_rulerulerZset_transaction_namer Exception)rQr&rZname_for_styler-r-r. _set_transaction_name_and_sourceys rUcKsVtt}|dkrdSt}tt|j|t }t |||}| |dSr1) r7r8r9r! flask_requestZ_get_current_objectrUrLr&Zget_isolation_scope_make_request_event_processorZadd_event_processor)appkwargsr<rrQZ evt_processorr-r-r.rBs rBc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)FlaskRequestExtractorcCs|jjSr1)rr;r>r-r-r.envszFlaskRequestExtractor.envcCsdd|jjDS)NcSs4i|],\}}|t|tr,t|dkr,|dn|qS)r) isinstancelistlen).0kvr-r-r. sz1FlaskRequestExtractor.cookies..)rcookiesitemsr>r-r-r.rds zFlaskRequestExtractor.cookiescCs |jSr1)rget_datar>r-r-r.raw_dataszFlaskRequestExtractor.raw_datacCs|jjSr1)rformr>r-r-r.rhszFlaskRequestExtractor.formcCs|jjSr1)rfilesr>r-r-r.riszFlaskRequestExtractor.filescCs|jjSr1)ris_jsonr>r-r-r.rjszFlaskRequestExtractor.is_jsoncCs|jjddS)NT)Zsilent)rZget_jsonr>r-r-r.jsonszFlaskRequestExtractor.jsoncCs|jSr1)content_length)r,filer-r-r. size_of_filesz"FlaskRequestExtractor.size_of_fileN) rGrHrIr[rdrgrhrirjrkrnr-r-r-r.rZsrZcsfdd}|S)Nc sPdkr |Stt|W5QRXtrLtt|W5QRX|Sr1)r rZZextract_into_eventr_add_user_to_event)eventhintrr-r.innersz,_make_request_event_processor..innerr-)rXrr<rrr-rr.rWs rWcKs0t|tjdddd\}}tj||ddS)Nr"F)typeZhandled)Zclient_optionsZ mechanism)rq)r r7r8optionsZ capture_event)rM exceptionrYrprqr-r-r.rCs  rCc Cstdkr dStj}|dkrdSt|di}z|d|Wntk rZYnXz|d|jWntk rYnXz|d|jWntk rYnXW5QRXdS)Nuseridemailusername) flask_loginZ current_userr setdefaultZget_idAttributeErrorrxrTry)rprvZ user_infor-r-r.ros&  ro)6r7Zsentry_sdk.integrationsrrZ$sentry_sdk.integrations._wsgi_commonrrZsentry_sdk.integrations.wsgirZsentry_sdk.scoperZsentry_sdk.tracingrZsentry_sdk.utilsr r r r typingr rrrrZsentry_sdk._typesrrrZwerkzeug.datastructuresrrrz ImportErrorr"rrrrVZ flask.signalsrrrZ markupsaferZblinkerr$r!rArUrBrZrWrCror-r-r-r.sJ         : %