0i9*ddlZddlmZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZmZmZddlmZdd l mZdd lmZmZdd lmZmZmZmZdd lmZeradd lmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddl'm(Z(m)Z)e$dZ*e$dZ+e$dZ,Gdde%Z-edZ.d(dZ/d)dZ0Gdd Z1 d*d!Z2d"Z3d#Z4d$Z5Gd%d&Z6d'Z7y)+N)partial)get_host _get_headers)continue_trace)OPshould_send_default_pii)DEFAULT_HTTP_METHODS_TO_CAPTURE_filter_headers nullcontext) track_session)use_isolation_scope) TransactionTransactionSource) ContextVarcapture_internal_exceptionsevent_from_exceptionreraise) TYPE_CHECKING)Callable)Dict)Iterator)Any)Tuple)Optional)TypeVar)Protocol)ExcInfo)EventEventProcessorWsgiResponseIterWsgiResponseHeaders WsgiExcInfoceZdZddZy) StartResponseNcyN)selfstatusresponse_headersexc_infos K/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/integrations/wsgi.py__call__zStartResponse.__call__,s r')__name__ __module__ __qualname__r.r(r/r-r%r%+s r/r%sentry_wsgi_middleware_appliedcD|jdj||S)Nlatin1)encodedecode)scharseterrorss r-wsgi_decoding_dancer;4s 88H  $ $Wf 55r/c |jddjd}|jddjd}|d|}|jddt||dt |jdS)zPReturn the absolute URL without query string for the given WSGI environment. SCRIPT_NAME/ PATH_INFOzwsgi.url_schemez://)getrstriplstriprr;)environuse_x_forwarded_for script_name path_infopaths r-get_request_urlrI9s++mR077$r/c tjdr|j||Stjd t j 5}t |d5t5|jd|_ |jt||jddd|jddj}d}||jvr6t|t j"dt$j&|j( }|t j*|d |i n t-}|5 |j|t/t0||}dddddddddtjdt9S#1swYxYw#t2$rt5t7Y`wxYw#1swYexYw#1swYixYw#1swYmxYw#tjdwxYw) NFTrequest) session_modewsgiREQUEST_METHODr>zgeneric WSGI request)opnamesourceorigin wsgi_environ)custom_sampling_context)_wsgi_middleware_appliedrArMset sentry_sdkisolation_scoper rclear_breadcrumbs_nameadd_event_processor_make_wsgi_event_processorrEupperrOrr HTTP_SERVERrROUTErNstart_transactionr r_sentry_start_response BaseExceptionr_capture_exception_ScopedResponse)r)rDstart_responsescopemethod transactiontransaction_contextresponses r-r.zSentryWsgiMiddleware.__call__]s # ' ' .88G^4 4 $$T** 0++-"5yA46//1&, 116 ')A)A7%[[)92>DDFF"&K!=!==&4#!~~!7#4#:#:#'#3#3 ' '2 #44'5CW4M )] (-;'+xx ' '$:NK!"(H-;B.R % ( ( /uh//S76H -;#%7%9:;-,;BA.-R % ( ( /sG(G G+=F(BG=G?!F% G(G0G(F" G%G >GG GG GG GG%!G((G?N)r0r1r2 __slots__r rRr.r(r/r-rKrKHsI" ? ?20r/rKct5t|jddd}||j|ddd| |||S||||S#1swYxYw)N r)rintsplitset_http_status)old_start_responserqr*r+r, status_ints r-rjrjsn % &c1-a01  "  ' ' 3 ' "&*:;;!&*:HEE ' &s 2AA#c#^Kddg}tr|dgz }|D]}||vs|||fyw)z Returns our explicitly included environment variables we want to capture (server name, port and remote addr if pii is enabled). SERVER_NAME SERVER_PORT REMOTE_ADDRNr)rDkeyskeys r- _get_environrsF = )D   '>ws|# #s- -c |djddjS#ttf$rYnwxYw |dS#t$rYnwxYw|j dS)z Infer the user IP address from various headers. This cannot be used in security sensitive situations since the value may be forged from a client, but it's good enough for the event payload. HTTP_X_FORWARDED_FOR,rHTTP_X_REAL_IPr)rystripKeyError IndexErrorrA)rDs r- get_client_iprsw -.44S9!<BBDD j !    '((     ;;} %%s$'99A A Ac tj}|d}t|txr|jdv}|sGt |t jjddd\}}t j|||S)z Captures the current exception and sends it to Sentry. Returns the ExcInfo tuple to it can be reraised afterwards. rw)rNrVF)typehandled)client_options mechanism)hint) sysr, isinstance SystemExitcoderr` get_clientoptions capture_event)r,eshould_skip_captureeventrs r-rlrlsz ||~H A%Q 3K)8K * %002::%%8 t   T2 Or/c&eZdZdZdZdZdZdZy)rmaY Users a separate scope for each response chunk. This will make WSGI apps more tolerant against: - WSGI servers streaming responses from a different thread/from different threads than the one that called start_response - close() not being called - WSGI servers streaming responses interleaved from the same thread ) _response_scopec ||_||_yr')rr)r)rorss r-rRz_ScopedResponse.__init__s !r/c#Kt|j} t|j5 t |}ddd/#t $r Ydddyt $rttY:wxYw#1swY?xYwwr') iterrrrnext StopIterationrkrrl)r)iteratorchunks r-__iter__z_ScopedResponse.__iter__s|'$T[[13 NE2K% 21 %3/123 21sJ,BA9 A B A6A9 BA63A95A66A99B>Bct|j5 |jjdddy#t$rYt $rt tY.wxYw#1swYyxYwr')rrrcloseAttributeErrorrkrrl)r)s r-rz_ScopedResponse.closes\  - /$$&. -"   /+-. / . -s2A$; A!A$A!A$ A!!A$$A-N)r0r1r2__doc__rtrRrrr(r/r-rmrms(I" /r/rmct|t|||jd|jdtt |t tt |fd}|S)N QUERY_STRINGrWct5|jdi}tr&|jdi}r|jd |d<|d<|d<|d<|d<ddd|S#1swY|SxYw) NrTuser ip_addressurl query_stringrpenvheaders)r setdefaultr ) rr request_info user_info client_iprrrpr request_urls r-event_processorz3_make_wsgi_event_processor..event_processor$s ( * ++Ir:L&(!,,VR8 ((yA"-L +7L (%+L ""%L &-L #+ + s AA22A<)rrIrAdictrr r) rDrErrrrrprrs @@@@@@r-reresng&I!'+>?K;;~.L [[) *F |G$ %Cd<#89:G& r/)zutf-8replace)Fr')8r functoolsrr`sentry_sdk._werkzeugrrsentry_sdk.apirsentry_sdk.constsrsentry_sdk.scoper $sentry_sdk.integrations._wsgi_commonr r r sentry_sdk.sessionsr rsentry_sdk.tracingrrsentry_sdk.utilsrrrrtypingrrrrrrrrrrsentry_sdk._typesrr r!r"r#r%r^r;rIrKrjrrrlrmrer(r/r-rs 7) 4 .0=!(712!"78-(K &&FG6 G0G0^ F,$"&(,)/)/X(r/