bgdZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZejZed Zdd ZGd d eZdS)z raven.contrib.sanic ~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2010-2018 by the Sentry Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. )absolute_importN) setup_logging)Client) SentryHandler)urlparse) to_unicode)convert_optionslogging_configuredc|dit|j|t|jdgt|jgzd|idS)NSENTRY_INCLUDE_PATHSapp)dsn include_pathsextra)defaults)r configsetgetname) client_clsr rs d/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/raven/contrib/sanic.py make_clientrs~ :    J '=rBBCC38*oo&3     ceZdZdZdedddejfdZdZdZ dZ dZ d Z d Z dd Zd Zd ZdZdZdZdZdZdZdS)Sentryaj Sanic application for Sentry. Look up configuration from ``os.environ['SENTRY_DSN']``:: >>> sentry = Sentry(app) Pass an arbitrary DSN:: >>> sentry = Sentry(app, dsn='http://public:secret@example.com/1') Pass an explicit client:: >>> sentry = Sentry(app, client=client) Automatically configure logging:: >>> sentry = Sentry(app, logging=True, level=logging.ERROR) Capture an exception:: >>> try: >>> 1 / 0 >>> except ZeroDivisionError: >>> sentry.captureException() Capture a message:: >>> sentry.captureMessage('hello, world!') NFc|r$t|tstd||_||_||_||_||_||_| |dS)Nz&client should be an instance of Client) isinstancer TypeErrorclientrrlogginglogging_exclusionslevelinit_app)selfr r rrr!r"r#s r__init__zSentry.__init__Mso  F*VV44 FDEE E $ "4  crcV|jsdS |j||nC#t$r6}|jjt |Yd}~nd}~wwxYwt|||jf}| |dS)N)exc_info) r http_context get_http_info Exceptionlogger exceptionrtype __traceback__captureException)r%requestr-eexception_infos rhandle_exceptionzSentry.handle_exceptionZs{  F 8 K $ $T%7%7%@%@ A A A A 8 8 8 K  ( (A 7 7 7 7 7 7 7 7 8 y//9i6MN ~66666s-9 A9,A44A9c|jSN)formr%r1s r get_form_datazSentry.get_form_datag |rcv||r|j}n|j}|||S)zR Determine how to retrieve actual data by using request.mimetype. ) is_json_type get_json_datar9get_http_info_with_retriever)r%r1 retrievers rr*zSentry.get_http_infojsB   W % % +*II*I00)DDDrc|jSr6)jsonr8s rr=zSentry.get_json_datatr:rctj|j} ||}n#t$ri}YnwxYwd|j|j|j|j|j ||j |j d|j idS)zT Exact method for getting http_info but with form data work around. z {0}://{1}{2} REMOTE_ADDR)url query_stringmethoddatacookiesheadersenv) rurlsplitrDr+formatschemenetlocpathqueryrFrHrI remote_addr)r%r1r?urlpartsrGs rr>z#Sentry.get_http_info_with_retrieverws$W[11 9W%%DD   DDD "(((-AA$Nnw2   s ' 66cB|jd}|dkS)Nz content-typezapplication/json)rIr)r%r1 content_types rr<zSentry.is_json_types#**>:: 111rc^|||_|||_|||_|d|_n||_|js t |j||j|_|jrTi}|j |j|d<t|j|j}t|fi|tj |fdti|t|dsi|_ ||j d<|j t|j||jd||jd dS) N)rootz sanic.accessz sanic.errorexclude)r#sentry_handler extensionssentryr1) attach_toresponse)rr#r!r"r rrrrr sendhasattrrY error_handleraddr+r4register_middlewarebefore_request after_request)r%r rr!r#r"kwargshandlers rr$zSentry.init_appsf ?DH  DJ  "DL  %'7D # #'9D #{ F%dosDHEEDK < >F&2$($;y!#DKtzBBBG ' , ,V , , ,  # > >%2 >6< > > >sL)) CN#'x  i)>???  3yIII  2jIIIIIrcd|_ |j||dS#t$r7}|jjt|Yd}~dSd}~wwxYwr6) last_event_idr r)r*r+r,r-r)r%r1r2s rrbzSentry.before_requests! 8 K $ $T%7%7%@%@ A A A A A 8 8 8 K  ( (A 7 7 7 7 7 7 7 7 7 8s-8 A9,A44A9cn|jr|j|jd<|jjdS)Nz X-Sentry-ID)rgrIr contextclear)r%r1r\s rrczSentry.after_requests;   A.2.@H ] + !!#####rcv|js Jd|jj|i|}|||S)Nz5captureException called before application configured)r r0set_last_event_id_from_resultr%argsrdresults rr0zSentry.captureExceptionsJ{SSSSS{--t>v>> **6222 rcv|js Jd|jj|i|}|||S)Nz3captureMessage called before application configured)r captureMessagerlrms rrqzSentry.captureMessagesJ{QQQQQ{++T!>D   !%D   rcH|js Jd|jj|i|S)Nz1user_context called before application configured)r user_contextr%rnrds rruzSentry.user_context2{OOOOO{'t{'8888rcH|js Jd|jj|i|S)Nz1tags_context called before application configured)r tags_contextrvs rryzSentry.tags_contextrwrcH|js Jd|jj|i|S)Nz2extra_context called before application configured)r extra_contextrvs rr{zSentry.extra_contexts2{PPPPP{(t{($9&999r)NNNN)__name__ __module__ __qualname____doc__rr!NOTSETr&r4r9r*r=r>r<r$rbrcr0rqrlruryr{rrrrr-s:>$(F4w~     7 7 7EEE   0222;?$(#J#J#J#JJ888$$$   &&& 999999:::::rrr6)r __future__rr!blinker raven.confr raven.baserraven.handlers.loggingrraven.utils.compatrraven.utils.encodingrraven.utils.confr Namespace raven_signalssignalr robjectrrrrrs'&&&&&$$$$$$000000''''''++++++,,,,,,"!## "))*>??$s:s:s:s:s:Vs:s:s:s:s:r