U \@sddlZddlmZddlmZmZddlmZmZm Z m Z ddl m Z ddl mZmZmZddlmZddlmZmZdd lmZGd d d e Zd d ZddZGdddeZ dS)N)iscoroutinefunction)Hub_should_send_default_pii)HAS_REAL_CONTEXTVARSevent_from_exceptioncapture_internal_exceptionstransaction_from_function) Integration)RequestExtractor_filter_headers_is_json_content_type) ignore_logger)RequestHandler HTTPError) coroutinec@seZdZdZeddZdS)TornadoIntegrationtornadocsddl}t|dd}|dks$|dkr,tdts8tdtdtdtjt}|rhfdd }ntfd d }|t_tj fd d }|t_ dS) Nr version_info)rzTornado 5+ requiredzUThe tornado integration for Sentry requires Python 3.6+ or the aiocontextvars packageztornado.applicationztornado.accessc stj}|t}|dkr.|f||IdHSt|}t|N}|}||t |W5QRX|f||IdHW5QRSQRXdSN) rcurrentget_integrationrweakrefrefconfigure_scopeZclear_breadcrumbsadd_event_processor_make_event_processor)selfargskwargshub integration weak_handlerscope old_execute /tornado.pysentry_execute_request_handler;s    zETornadoIntegration.setup_once..sentry_execute_request_handlerc ?stj}|t}|dkr(|f||St|}t|J}|}|t|W5QRX|f||EdH}|W5QRSQRXdSr) rrrrrrrrr)rrrr r!r"r#resultr$r&r'r(Ls    cs"t|||||||f||Sr)_capture_exception)rtyvaluetbrr)old_log_exceptionr&r'sentry_log_exception_s z;TornadoIntegration.setup_once..sentry_log_exception) rgetattr RuntimeErrorrr rZ_executerrZ log_exception)rZtornado_versionZ awaitabler(r/r&)r%r.r' setup_once!s(  zTornadoIntegration.setup_onceN)__name__ __module__ __qualname__Z identifier staticmethodr2r&r&r&r'rsrcCsZtj}|tdkrdSt|tr&dSt|||f|jjdddd\}}|j ||ddS)NrF)typeZhandled)Zclient_optionsZ mechanism)hint) rrrr isinstancerrZclientZoptionsZ capture_event)r+r,r-r eventr8r&r&r'r*gs  r*csfdd}|S)Nc s}|dkr|S|j}t$t||jj}t||d<W5QRXtlt|}|||d}d|j|j |j f|d<|j |d<|j|d<d|j i|d<t t|j|d <W5QRXt"|jrtrd |d id <W5QRX|S) NZ transactionrequestz %s://%s%sZurlZ query_stringmethodZ REMOTE_ADDRenvheadersTuserZis_authenticated)r;rr0r<lowerrTornadoRequestExtractorZextract_into_eventZprotocolZhostpathZqueryZ remote_ipr dictr>Z current_userr setdefault)r:r8Zhandlerr;r<Z extractorZ request_infor"r&r'tornado_processorzs0     z0_make_event_processor..tornado_processorr&)r"rFr&rEr'rxs #rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)rAcCs|jjdkrdSt|jjS)Nr)r;bodylenrr&r&r'content_lengths z&TornadoRequestExtractor.content_lengthcCsdd|jjDS)NcSsi|]\}}||jqSr&)r,.0kvr&r&r' sz3TornadoRequestExtractor.cookies..)r;cookiesitemsrIr&r&r'rPszTornadoRequestExtractor.cookiescCs|jjSr)r;rGrIr&r&r'raw_datasz TornadoRequestExtractor.raw_datacCsdd|jjDS)NcSs i|]\}}|dd|DqS)cSsg|]}|ddqS)latin1replace)decode)rLrNr&r&r' sz;TornadoRequestExtractor.form...r&)rLrMZvsr&r&r'rOsz0TornadoRequestExtractor.form..)r;Zbody_argumentsrQrIr&r&r'forms zTornadoRequestExtractor.formcCst|jjdS)Nz content-type)r r;r>getrIr&r&r'is_jsonszTornadoRequestExtractor.is_jsoncCsdd|jjDS)NcSsi|]\}}|r||dqS)rr&rKr&r&r'rOsz1TornadoRequestExtractor.files..)r;filesrQrIr&r&r'rZszTornadoRequestExtractor.filescCst|jp dS)Nr&)rHrG)rfiler&r&r' size_of_filesz$TornadoRequestExtractor.size_of_fileN) r3r4r5rJrPrRrWrYrZr\r&r&r&r'rAsrA)!rinspectrZsentry_sdk.hubrrZsentry_sdk.utilsrrrrZsentry_sdk.integrationsr Z$sentry_sdk.integrations._wsgi_commonr r r Zsentry_sdk.integrations.loggingr Z tornado.webrrZ tornado.genrZAnyZListZOptionalZDictCallablerr*rrAr&r&r&r's    I(