U \@sddlmZddlmZddlmZmZmZddlm Z ddl m Z ddl m Z ddlmZmZmZmZGdd d e ZGd d d e Zd d ZdS))absolute_import)Hub)capture_internal_exceptionsevent_from_exceptiontransaction_from_function) Integration)SentryWsgiMiddleware)RequestExtractor)BottleRouterequest HTTPResponsec@s*eZdZdZdZdddZeddZdS) BottleIntegrationbottleNendpointcCs&d}||krtd||f||_dS)N)rurlz7Invalid value for transaction_style: %s (must be in %s)) ValueErrortransaction_style)selfrZTRANSACTION_STYLE_VALUESr /bottle.py__init__"szBottleIntegration.__init__csLtjfdd}|t_tjfdd}|t_tjfdd}|t_dS)Ncs<tj}|t}|dkr$||Stfdd||S)Ncsf||SNr)akw)old_apprrr;zOBottleIntegration.setup_once..sentry_patched_wsgi_app..)rcurrentget_integrationrr)renvironZstart_responsehub integration)rrrsentry_patched_wsgi_app3s  z=BottleIntegration.setup_once..sentry_patched_wsgi_appc sxtj}|t}|dkr"||S|}|@|}|}d|_|t|t |W5QRX||}W5QRX|S)Nr) rrrrZ push_scopeZconfigure_scope_nameZadd_event_processor_make_request_event_processorbottle_request)rr r!r"Z scope_managerappZscoperes) old_handlerr_patched_handleDs    z5BottleIntegration.setup_once.._patched_handlecs>tjt}|f|||dkr,Sfdd}|S)Nc sbfdd}z||}WnBtk r0Yn.tk r\}z|||W5d}~XYnX|S)Ncs.t|jjdddd\}}j||ddS)NrF)typeZhandled)Zclient_optionsZ mechanism)hint)rZclientZoptionsZ capture_event) exceptioneventr-)r!rrcapture_exceptionfs  zpBottleIntegration.setup_once..patched_make_callback..wrapped_callback..capture_exception)r Exception)argskwargsr0r)r.r!Zprepared_callbackrrwrapped_callbackes zUBottleIntegration.setup_once..patched_make_callback..wrapped_callback)rrrr)rr2r3r"r5)old_make_callbackr4rpatched_make_callback^s z;BottleIntegration.setup_once..patched_make_callback)r __call__Z_handler Z_make_callback)r$r+r7r)rr*r6r setup_once,s   zBottleIntegration.setup_once)r)__name__ __module__ __qualname__Z identifierrr staticmethodr9rrrrrs  rc@s<eZdZddZddZddZddZd d Zd d Zd S)BottleRequestExtractorcCs|jjSr)r r r#rrrenv~szBottleRequestExtractor.envcCs|jjSr)r cookiesr#rrrr@szBottleRequestExtractor.cookiescCs |jjSr)r Zbodyreadr#rrrraw_dataszBottleRequestExtractor.raw_datacCs|r dS|jjSr)is_jsonr Zformsdecoder#rrrformszBottleRequestExtractor.formcCs|r dS|jjSr)rCr filesr#rrrrFszBottleRequestExtractor.filescCs|jSr)Zcontent_length)rfilerrr size_of_filesz#BottleRequestExtractor.size_of_fileN) r:r;r<r?r@rBrErFrHrrrrr>}s r>csfdd}|S)Nc sxz>jdkr&jjptjj|d<njdkr<jj|d<Wntk rRYnXtt |W5QRX|S)NrZ transactionr) rZroutenamercallbackZruler1rr>Zextract_into_event)r/r-r"r rrinners    z,_make_request_event_processor..innerr)r(r r"rLrrKrr&sr&N)Z __future__rZsentry_sdk.hubrZsentry_sdk.utilsrrrZsentry_sdk.integrationsrZsentry_sdk.integrations.wsgirZ$sentry_sdk.integrations._wsgi_commonr Z_ScopedResponseZAnyZDictCallableZOptionalZ FileUploadZ FormsDictZ LocalRequestrr r r r'r rr>r&rrrrs     `