AlkantarClanX12

Your IP : 18.188.113.185


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

�
��Yc@@skdZddlmZyddlmZWnek
rCeZnXeZddl	Z	ddl
Z
ddlmZm
Z
mZddlmZmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lm Z ddl!m"Z"m#Z#ddl$m%Z%e
j&�Z'e'j(d�Z)dd�Z+de,fd��YZdS(s�
raven.contrib.flask
~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
i(tabsolute_import(tcurrent_userN(trequesttcurrent_apptg(tgot_request_exceptiontrequest_finished(tClientDisconnected(t
setup_logging(tClient(tSentry(t
SentryHandler(turlparse(t
to_unicode(tget_headerstget_environ(tconvert_optionstlogging_configuredc	C@sp|t|jdi|d6t|jjdg��t|jg�Bd6|jjdg�d6i|d6d6��S(	NtdefaultstdsntSENTRY_INCLUDE_PATHSt
include_pathstRAVEN_IGNORE_EXCEPTIONStignore_exceptionstapptextra(Rtconfigtsettgettimport_name(t
client_clsRR((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pytmake_client's	R
c
B@s�eZdZddededejded�	Z	e
d��Zejd��Zd�Z
d�Zd�Zd�Zd�Zd	�Zdd
�Zd�Zd�Zddddddd
�Zd�Zd�Zd�Zd�Zd�ZRS(s�
    Flask 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!')

    By default, the Flask integration will do the following:

    - Hook into the `got_request_exception` signal. This can be disabled by
      passing `register_signal=False`.
    - Wrap the WSGI application. This can be disabled by passing
      `wrap_wsgi=False`.
    - Capture information from Flask-Login (if available).
    c

C@s�|r%t|t�r%td��n||_||_||_||_||_||_||_	|	|_
|r�|j|�ndS(Ns&client should be an instance of Client(t
isinstanceR	t	TypeErrorRtloggingtlogging_exclusionsRtclienttlevelt	wrap_wsgitregister_signaltinit_app(
tselfRR$RRR"R#R%R&R'((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyt__init__es								cC@s/ytjSWntk
rnXt|dd�S(Nt_last_event_id(Rtsentry_event_idt	ExceptiontgetattrtNone(R)((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyt
last_event_idws

cC@s.||_y
|t_Wntk
r)nXdS(N(R+RR,R-(R)tvalue((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR0s
	

cO@s*|js
dS|jd|jd��dS(Ntexc_info(R$tcaptureExceptionR(R)targstkwargs((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pythandle_exception�s	cC@si}y|jd}Wntk
r3|j}nX|rG||d<ntsQ|Sttd�sd|Sy
tj}Wntk
r�|SXt	|�r�|�}n|s�|Stj
�|d<dtjkrx=tjdD]+}tt|�r�tt|�||<q�q�Wn|S(su
        Requires Flask-Login (https://pypi.python.org/pypi/Flask-Login/)
        to be installed and setup.
        it
ip_addresst
login_managertidtSENTRY_USER_ATTRS(
taccess_routet
IndexErrortremote_addrthas_flask_loginthasattrRRtis_authenticatedtAttributeErrortcallabletget_idRR.(R)Rt	user_infoR7R@tattr((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyt
get_user_info�s2




cC@s7|j|j�r|j}n	|j}|j||�S(sR
        Determine how to retrieve actual data by using request.mimetype.
        (tis_json_typetmimetypet
get_json_datat
get_form_datatget_http_info_with_retriever(R)Rt	retriever((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyt
get_http_info�s	cC@s
|dkS(Nsapplication/json((R)tcontent_type((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyRG�scC@s|jS(N(tform(R)R((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyRJ�scC@s|jS(N(tdata(R)R((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyRI�scC@s�|dkr|j}ntj|j�}y||�}Wntk
rSi}nXid|j|j|jfd6|j	d6|j
d6|d6tt|j
��d6tt|j
��d6S(	sT
        Exact method for getting http_info but with form data work around.
        s	%s://%s%sturltquery_stringtmethodRPtheaderstenvN(R/RJRturlsplitRQRtschemetnetloctpathtqueryRStdictRtenvironR(R)RRLturlpartsRP((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyRK�s



cO@s�d|_tjr.|jjjtjj�ny|jj|j	t��Wn,t
k
ry}|jjjt
|��nXy|jj|jt��Wn,t
k
r�}|jjjt
|��nXdS(N(R/R0Rturl_ruleR$ttransactiontpushtrulethttp_contextRMR-tloggert	exceptionR
tuser_contextRF(R)R4R5te((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pytbefore_request�s		cO@sU|jr|j|jd<n|jjj�tjrQ|jjjtjj	�n|S(NsX-Sentry-ID(
R0RTR$tcontexttclearRR^R_tpopRa(R)tsendertresponseR4R5((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyt
after_request�s		c
C@s|dk	r||_n|dk	r0||_n|dk	rH||_n6|jdkr~|rr|jrrt|_q~t|_n|dk	r�||_n|dk	r�||_n|dk	r�||_	n|j
s�t|j||j�|_
n|jr~i}|j	dk	r|j	|d<nt
|j
d|j�}	t|	|�|jjtkre|jj|	�ntj|dt
|�n|jr�t|j|j
�|_n|j|j�tj|jd|�|jr�tj|jd|�nt|d�si|_n||jd<dS(NtexcludeR%tsentry_handlerRkt
extensionstsentry(R/RR%R&tdebugtFalsetTrueR'R"R#R$RRRRRct	propagatet
addHandlerRtsendtSentryMiddlewaretwsgi_appRgRtconnectRmRR6R?Rp(
R)RRR"R%R#R&R'R5thandler((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR(�sJ		
		cO@sU|jstd��|jj||�}|rH|jj|�|_n	d|_|S(Ns5captureException called before application configured(R$tAssertionErrorR3t	get_identR0R/(R)R4R5tresult((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR33s	cO@sU|jstd��|jj||�}|rH|jj|�|_n	d|_|S(Ns3captureMessage called before application configured(R$R|tcaptureMessageR}R0R/(R)R4R5R~((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR<s	cO@s(|jstd��|jj||�S(Ns1user_context called before application configured(R$R|Re(R)R4R5((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyReEscO@s(|jstd��|jj||�S(Ns1tags_context called before application configured(R$R|ttags_context(R)R4R5((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR�IscO@s(|jstd��|jj||�S(Ns2extra_context called before application configured(R$R|t
extra_context(R)R4R5((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR�MsN(t__name__t
__module__t__doc__R/R	RsR"tNOTSETRtR*tpropertyR0tsetterR6RFRMRGRJRIRKRgRmR(R3RReR�R�(((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyR
;s.&		,	
						7						(-R�t
__future__Rtflask_loginRtImportErrorRsR>RtR"tblinkertflaskRRRt
flask.signalsRRtwerkzeug.exceptionsRt
raven.confRt
raven.baseR	traven.middlewareR
Rxtraven.handlers.loggingRtraven.utils.compatRtraven.utils.encodingR
traven.utils.wsgiRRtraven.utils.confRt	Namespacet
raven_signalstsignalRR/Rtobject(((sD/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/flask.pyt<module>s.