AlkantarClanX12

Your IP : 18.117.158.10


Current Path : /opt/alt/python37/lib/python3.7/site-packages/raven/contrib/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/raven/contrib/__pycache__/flask.cpython-37.pyc

B

��Yw)�@sdZddlmZyddlmZWnek
r8dZYnXdZddlZddlZddl	m
Z
mZmZddl
mZmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlm Z m!Z!ddl"m#Z#e�$�Z%e%�&d�Z'ddd�Z(Gdd�de)�ZdS)z�
raven.contrib.flask
~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
�)�absolute_import)�current_userFTN)�request�current_app�g)�got_request_exception�request_finished)�ClientDisconnected)�
setup_logging)�Client)�Sentry)�
SentryHandler)�urlparse)�
to_unicode)�get_headers�get_environ)�convert_options�logging_configuredc
CsF|ft|j|t|j�dg��t|jg�B|j�dg�d|id�d��S)NZSENTRY_INCLUDE_PATHSZRAVEN_IGNORE_EXCEPTIONS�app)�dsnZ
include_pathsZignore_exceptions�extra)�defaults)r�config�set�getZimport_name)�
client_clsrr�r�D/opt/alt/python37/lib/python3.7/site-packages/raven/contrib/flask.py�make_client'src	@s�eZdZdZddedddejddf	dd�Zedd��Z	e	j
d	d��Z	d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zd(dd�Zdd�Zdd�Zd)dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS)*ra�
    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).
    NFTc

CsX|rt|t�std��||_||_||_||_||_||_||_	|	|_
|rT|�|�dS)Nz&client should be an instance of Client)�
isinstancer�	TypeErrorr�logging�logging_exclusionsr�client�level�	wrap_wsgi�register_signal�init_app)
�selfrr#rrr!r"r$r%r&rrr�__init__eszSentry.__init__cCs(ytjStk
rYnXt|dd�S)N�_last_event_id)r�sentry_event_id�	Exception�getattr)r(rrr�
last_event_idws
zSentry.last_event_idcCs*||_y
|t_Wntk
r$YnXdS)N)r*rr+r,)r(�valuerrrr.s

cOs |js
dS|j|�d�d�dS)N�exc_info)r0)r#�captureExceptionr)r(�args�kwargsrrr�handle_exception�szSentry.handle_exceptioncCs�i}y|jd}Wntk
r,|j}YnX|r:||d<tsB|Sttd�sP|Sy
tj}Wntk
rn|SXt	|�r~|�}|s�|St�
�|d<dtjkr�x*tjdD]}tt|�r�tt|�||<q�W|S)zu
        Requires Flask-Login (https://pypi.python.org/pypi/Flask-Login/)
        to be installed and setup.
        r�
ip_addressZ
login_manager�idZSENTRY_USER_ATTRS)
Zaccess_route�
IndexErrorZremote_addr�has_flask_login�hasattrrr�is_authenticated�AttributeError�callableZget_idrr-)r(rZ	user_infor5r:�attrrrr�
get_user_info�s2



zSentry.get_user_infocCs&|�|j�r|j}n|j}|�||�S)zR
        Determine how to retrieve actual data by using request.mimetype.
        )�is_json_typeZmimetype�
get_json_data�
get_form_data�get_http_info_with_retriever)r(r�	retrieverrrr�
get_http_info�szSentry.get_http_infocCs|dkS)Nzapplication/jsonr)r(�content_typerrrr?�szSentry.is_json_typecCs|jS)N)Zform)r(rrrrrA�szSentry.get_form_datacCs|jS)N)�data)r(rrrrr@�szSentry.get_json_datacCsz|dkr|j}t�|j�}y||�}Wntk
r>i}YnXd|j|j|jf|j|j	|t
t|j��t
t
|j��d�S)zT
        Exact method for getting http_info but with form data work around.
        Nz	%s://%s%s)�urlZquery_string�methodrF�headers�env)rAr�urlsplitrGr	�scheme�netloc�path�queryrH�dictr�environr)r(rrCZurlpartsrFrrrrB�s
z#Sentry.get_http_info_with_retrieverc
Os�d|_tjr|jj�tjj�y|j�|�t��Wn4t	k
rh}z|jj
�t|��Wdd}~XYnXy|j�
|�t��Wn4t	k
r�}z|jj
�t|��Wdd}~XYnXdS)N)r.r�url_ruler#�transaction�push�ruleZhttp_contextrDr,�logger�	exceptionr�user_contextr>)r(r2r3�errr�before_request�s$zSentry.before_requestcOs:|jr|j|jd<|jj��tjr6|jj�tjj	�|S)NzX-Sentry-ID)
r.rIr#�context�clearrrRrS�poprU)r(�sender�responser2r3rrr�
after_request�szSentry.after_requestc
Csd|dk	r||_|dk	r||_|dk	r,||_n"|jdkrN|rH|jrHd|_nd|_|dk	r\||_|dk	rj||_|dk	rx||_|js�t|j	||j�|_|jr�i}|jdk	r�|j|d<t
|j|jd�}	t|	f|�|jj
dkr�|j�|	�tj|fdt
i|��|j�rt|j|j�|_|�|j�tj|j|d�|j�rDtj|j|d�t|d��sVi|_||jd<dS)	NFT�exclude)r$Zsentry_handler)r^�
extensionsZsentry)rr$r%�debugr&r!r"r#rrr
r
rV�	propagate�
addHandlerr�send�SentryMiddlewareZwsgi_apprZr�connectr`rr4r9rb)
r(rrr!r$r"r%r&r3�handlerrrrr'�sJ



zSentry.init_appcOs:|jstd��|jj||�}|r0|j�|�|_nd|_|S)Nz5captureException called before application configured)r#�AssertionErrorr1�	get_identr.)r(r2r3�resultrrrr13szSentry.captureExceptioncOs:|jstd��|jj||�}|r0|j�|�|_nd|_|S)Nz3captureMessage called before application configured)r#rj�captureMessagerkr.)r(r2r3rlrrrrm<szSentry.captureMessagecOs|jstd��|jj||�S)Nz1user_context called before application configured)r#rjrX)r(r2r3rrrrXEszSentry.user_contextcOs|jstd��|jj||�S)Nz1tags_context called before application configured)r#rj�tags_context)r(r2r3rrrrnIszSentry.tags_contextcOs|jstd��|jj||�S)Nz2extra_context called before application configured)r#rj�
extra_context)r(r2r3rrrroMszSentry.extra_context)N)NNNNNN)�__name__�
__module__�__qualname__�__doc__rr!�NOTSETr)�propertyr.�setterr4r>rDr?rAr@rBrZr`r'r1rmrXrnrorrrrr;s.&,


7		r)N)*rs�
__future__rZflask_loginr�ImportErrorr8r!Zblinker�flaskrrrZ
flask.signalsrrZwerkzeug.exceptionsr	Z
raven.confr
Z
raven.baserZraven.middlewarerrgZraven.handlers.loggingr
Zraven.utils.compatrZraven.utils.encodingrZraven.utils.wsgirrZraven.utils.confr�	NamespaceZ
raven_signals�signalrr�objectrrrr�<module>s.