AlkantarClanX12

Your IP : 3.145.103.100


Current Path : /opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/
Upload File :
Current File : //opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyc

�
��Yc@@s�dZddlmZddlmZddlmZddlmZm	Z	ddl
m	Zddlm
Z
de
fd	��YZd
efd��YZdS(
s�
raven.contrib.tornado
~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2012 by the Sentry Team, see AUTHORS for more details
:license: BSD, see LICENSE for more details
i(tabsolute_import(tpartial(tioloop(tAsyncHTTPClientt	HTTPError(R(tClienttAsyncSentryClientcB@sVeZdZd�Zd�Zddd�Zddd�Zd�Zddd�Z	RS(s�
    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
    cO@s2|jdt�|_tt|�j||�dS(Nt
validate_cert(tpoptTrueRtsuperRt__init__(tselftargstkwargs((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyRscO@sQ|j�sdS|j||�}|jd|jdd�|�}|d|fS(s	
        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
        Ntcallbacktevent_id(t
is_enabledt	build_msgtsendtgettNone(RR
Rtdatatfuture((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytcaptures
!cK@s(|j|�}|j|d|d|�S(sV
        Serializes the message and passes the payload onto ``send_encoded``.
        tauth_headerR(tencodetsend_encoded(RRRRtmessage((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyR/sc	C@s�|dkri}n|jj�sD|j|�}|j|�dS|jd|d|d|d|�}tjj�j	|t
|j||��|S(NturlRtheadersR(Rtstatet
should_trytdecodet_log_failed_submissiont_send_remoteRtIOLooptcurrentt
add_futureRt_handle_result(RRRRRR((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytsend_remote7s	
	(cC@s�y|j�Wnitk
rE}|j|�}|j|||�nBtk
ry}|j|�}|j|||�nX|jj�dS(N(tresultRR!t_failed_sendt	ExceptionRtset_success(RRRRte((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyR'FscC@sC|dkri}nt�j||ddd|d|d|j�S(s�
        Initialise a Tornado AsyncClient and send the reuqest to the sentry
        server. If the callback is a callable, it will be called with the
        response.
        tmethodtPOSTtbodyRRN(RRtfetchR(RRRRR((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyR#Rs
		N(
t__name__t
__module__t__doc__RRRRR(R'R#(((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyRs			tSentryMixincB@sqeZdZd�Zd�Zd�Zd�Zd�Zdd�Z	dd�Z
d�Zd	�Zd
d�Z
RS(
s�
    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.
    cC@s
|jjS(s�
        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
        (tapplicationt
sentry_client(R((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytget_sentry_client�scC@snii|jj�d6|jjd6|jjd6|jjd6|jjjdd	�d6t|jj�d6d6S(
s�
        Extracts the data required for 'sentry.interfaces.Http' from the
        current request being handled by the request handler

        :param return: A dictionary.
        RR.Rtquery_stringtCookietcookiesRtrequestN(	R<tfull_urlR.R0tqueryRRRtdict(R((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytget_sentry_data_from_request�s


cC@sCy|j�}Wntk
r$iSXii|r7tntd6d6S(s�
        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
        tis_authenticatedtuser(tget_current_userR+R	tFalse(RRB((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytget_sentry_user_info�s
cC@siid6S(sf
        Subclass and implement this method if you need to send any extra
        information
        textra((R((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytget_sentry_extra_info�scC@sCi}|j|j��|j|j��|j|j��|S(N(tupdateR@RERG(RR((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pytget_default_context�s
cK@s|dkr|j�}n?|j�}t|t�rF|j|�n||dd<|}|j�}t||�d||�S(NRFt
extra_dataR(RRIt
isinstanceR?RHR8tgetattr(Rt	call_nameRRtdefault_contexttclient((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyt_capture�scK@s|jdd||�S(NtcaptureExceptiontexc_info(RP(RRRR((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyRQ�scK@s|jdd||�S(NtcaptureMessageR(RP(RRR((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyRS�scC@sltt|�j|||�}t|t�rO|jdksK|jdkrO|S|jd|||f�|S(svOverride implementation to report all exceptions to sentry.
        log_exception() is added in Tornado v3.1.
        i�iWRR(R
R5t
log_exceptionRKtWebHTTPErrortstatus_codeRQ(Rttyptvaluettbtrv((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyRT�s
-i�cK@s�ttt|�d�r1tt|�j||�Stt|�j||�}d|kocdknr�|jd|jd��n|SdS(s�Override implementation to report all exceptions to sentry, even
        after self.flush() or self.finish() is called, for pre-v3.1 Tornado.
        RTi�iWRRN(thasattrR
R5t
send_errorRQR(RRVRRZ((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyR\�sN(R2R3R4R8R@RERGRIRRPRQRSRTR\(((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyR5as(				
			N(R4t
__future__Rt	functoolsRttornadoRttornado.httpclientRRttornado.webRUt
raven.baseRRtobjectR5(((sO/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/tornado/__init__.pyt<module>sN