bg2 dZddlmZddlmZddlmZddlmZm Z ddl m Z ddl m Z Gdd e ZGd d eZd S) z raven.contrib.tornado ~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2012 by the Sentry Team, see AUTHORS for more details :license: BSD, see LICENSE for more details )absolute_import)partial)ioloop)AsyncHTTPClient HTTPError)r)ClientcFeZdZdZfdZdZd dZd dZdZd dZ xZ S) AsyncSentryClientz A mixin class that could be used along with request handlers to asynchronously send errors to sentry. The client also captures the information from the request handlers c~|dd|_tt|j|i|dS)N validate_certT)popr superr __init__)selfargskwargs __class__s o/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/raven/contrib/tornado/__init__.pyrzAsyncSentryClient.__init__sB#ZZ>>/&&/@@@@@@c|sdS|j|i|}|jdd|ddi|}|d|fS)a  Takes the same arguments as the super function in :py:class:`Client` and extracts the keyword argument callback which will be called on asynchronous sending of the request :return: a 32-length string identifying this event Ncallbackevent_id) is_enabled build_msgsendget)rrrdatafutures rcapturezAsyncSentryClient.capturesk    Ft~t.v..IIFJJz4$@$@IDIIZ &))rNc \||}||||S)zV Serializes the message and passes the payload onto ``send_encoded``. ) auth_headerr)encode send_encoded)rr"rrmessages rrzAsyncSentryClient.send/s0++d##  kH UUUrcV|i}|js,||}||dS|||||}t j|t|j |||S)N)urlrheadersr) state should_trydecode_log_failed_submission _send_remoterIOLoopcurrent add_futurer_handle_result)rr'rr(rrs r send_remotezAsyncSentryClient.send_remote7s ?Gz$$&& ;;t$$D  ' ' - - - F""$(#    **674;NPSUY3Z3Z[[[ rch ||jdS#t$r7}||}||||Yd}~dSd}~wt $r7}||}||||Yd}~dSd}~wwxYwN)resultr) set_successrr+ _failed_send Exception)rr'rres rr1z AsyncSentryClient._handle_resultFs % MMOOO J " " $ $ $ $ $ , , ,;;t$$D   ad + + + + + + + + + , , ,;;t$$D   ad + + + + + + + + + ,s 1 B1,A-- B1:,B,,B1cb|i}t||d|||jS)z Initialise a Tornado AsyncClient and send the request to the sentry server. If the callback is a callable, it will be called with the response. NPOST)methodbodyr(r )rfetchr )rr'rr(rs rr-zAsyncSentryClient._send_remoteRsB ?G  && &tW,'   r)NN) __name__ __module__ __qualname____doc__rr rr2r1r- __classcell__rs@rr r s AAAAA***"VVVV     % % %         rr cbeZdZdZdZdZdZdZdZddZ dd Z d Z fd Z dfd Z xZS) SentryMixina A mixin class that extracts information from the Request in a Request Handler to capture and send to sentry. This mixin class is designed to be used along with `tornado.web.RequestHandler` .. code-block:: python :emphasize-lines: 6 class MyRequestHandler(SentryMixin, tornado.web.RequestHandler): def get(self): try: fail() except Exception as e: self.captureException() While the above example would result in sequential execution, an example for asynchronous use would be .. code-block:: python :emphasize-lines: 6 class MyRequestHandler(SentryMixin, tornado.web.RequestHandler): @tornado.web.asynchronous @tornado.gen.engine def get(self): # Do something and record a message in sentry response = yield tornado.gen.Task( self.captureMessage, "Did something really important" ) self.write("Your request to do something important is done") self.finish() The mixin assumes that the application will have an attribute called `sentry_client`, which should be an instance of :py:class:`AsyncSentryClient`. This can be changed by implementing your own get_sentry_client method on your request handler. c|jjS)z Returns the sentry client configured in the application. If you need to change the behaviour to do something else to get the client, then subclass this method ) application sentry_clientrs rget_sentry_clientzSentryMixin.get_sentry_clients --rc d|j|jj|jj|jj|jjddt|jjdiS)z Extracts the data required for 'sentry.interfaces.Http' from the current request being handled by the request handler :param return: A dictionary. requestCookieN)r'r<r query_stringcookiesr()rMfull_urlr<r=queryr(rdictrJs rget_sentry_data_from_requestz(SentryMixin.get_sentry_data_from_requestsl |,,..,- ) $ 2</33HdCC 455   rcf |}n#t$ricYSwxYwdd|rdndiiS)z Data for sentry.interfaces.User Default implementation only sends `is_authenticated` by checking if `tornado.web.RequestHandler.get_current_user` tests postitively for on Truth calue testing useris_authenticatedTF)get_current_userr8)rrVs rget_sentry_user_infoz SentryMixin.get_sentry_user_infos` ((**DD   III  "D$;DDe  s  &&c diiS)zf Subclass and implement this method if you need to send any extra information extrarrJs rget_sentry_extra_infoz!SentryMixin.get_sentry_extra_infos   rci}|||||||Sr4)updaterTrYr\)rrs rget_default_contextzSentryMixin.get_default_contextsl D5577888 D--//000 D..00111 rNc ||}nL|}t|tr||n ||dd<|}|}t ||dd|i|S)Nr[ extra_datarr)r_ isinstancerSr^rKgetattr)r call_namerrdefault_contextclients r_capturezSentryMixin._captures <++--DD"6688O$%% >&&t,,,,9=(6"D'')))wvy))>>t>v>>>rc |jdd|i|S)NcaptureExceptionexc_info)rirg)rrjrs rrizSentryMixin.captureExceptionst}MM(MfMMMrc |jdd|i|S)NcaptureMessager%)rmrk)rr%rs rrmzSentryMixin.captureMessagest}IIwI&IIIrctt||||}t|tr|jdks |jdkr|S||||f|S)zvOverride implementation to report all exceptions to sentry. log_exception() is added in Tornado v3.1. Wrj)rrF log_exceptionrb WebHTTPError status_coderi)rtypvaluetbrvrs rrrzSentryMixin.log_exceptions{; % % 3 3C C C e\ * * 0AC0G0G5K\_bKbKbI UB'7888 rroc Dttt|dr!tt|j|fi|Stt|j|fi|}d|cxkrdkr,nn)||d|S)zOverride implementation to report all exceptions to sentry, even after self.flush() or self.finish() is called, for pre-v3.1 Tornado. rrrorprjrq)hasattrrrF send_errorrir)rrtrrxrs rr{zSentryMixin.send_errors 5d++_ = = 65d++6{MMfMM M4{D))4[KKFKKBk((((S(((((%%vzz*/E/E%FFFIrr4)ro)r?r@rArBrKrTrYr\r_rgrirmrrr{rCrDs@rrFrFas''R...   $   $       ? ? ? ?NNNNJJJ               rrFN)rB __future__r functoolsrtornadortornado.httpclientrr tornado.webrs raven.baserr objectrFrrrrs'&&&&&99999999111111K K K K K K K K \XXXXX&XXXXXr