ok

Mini Shell

Direktori : /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_exceptionsZextra)�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)r/)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_infor4r9�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'Zcontent_typerrrr>�szSentry.is_json_typecCs|jS)N)Zform)r'rrrrr@�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�methodrD�headers�env)r@rZurlsplitrEr	ZschemeZnetloc�pathZqueryrF�dictr�environr)r'rrBZurlpartsrDrrrrA�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_contextrCr+�loggerZ	exceptionr�user_contextr=)r'r1r2�errr�before_request�s$zSentry.before_requestcOs:|jr|j|jd<|jj��tjr6|jj�tjj	�|S)NzX-Sentry-ID)
r-rGr"�context�clearrrLrM�poprO)r'�senderZresponser1r2rrr�
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)	NFTZexclude)r#Zsentry_handler)rW�
extensionsZsentry)rr#r$�debugr%r r!r"rrr
r
rPZ	propagateZ
addHandlerr�send�SentryMiddlewareZwsgi_apprSrZconnectrXrr3r8rY)
r'rrr r#r!r$r%r2Zhandlerrrrr&�sJ



zSentry.init_appcOs:|jstd��|jj||�}|r0|j�|�|_nd|_|S)Nz5captureException called before application configured)r"�AssertionErrorr0�	get_identr-)r'r1r2�resultrrrr03szSentry.captureExceptioncOs:|jstd��|jj||�}|r0|j�|�|_nd|_|S)Nz3captureMessage called before application configured)r"r]�captureMessager^r-)r'r1r2r_rrrr`<szSentry.captureMessagecOs|jstd��|jj||�S)Nz1user_context called before application configured)r"r]rQ)r'r1r2rrrrQEszSentry.user_contextcOs|jstd��|jj||�S)Nz1tags_context called before application configured)r"r]�tags_context)r'r1r2rrrraIszSentry.tags_contextcOs|jstd��|jj||�S)Nz2extra_context called before application configured)r"r]�
extra_context)r'r1r2rrrrbMszSentry.extra_context)N)NNNNNN)�__name__�
__module__�__qualname__�__doc__rr ZNOTSETr(�propertyr-�setterr3r=rCr>r@r?rArSrXr&r0r`rQrarbrrrrr;s.&,


7		r)N)*rfZ
__future__rZflask_loginr�ImportErrorr7r ZblinkerZflaskrrrZ
flask.signalsrrZwerkzeug.exceptionsr	Z
raven.confr
Z
raven.baserZraven.middlewarerr\Zraven.handlers.loggingr
Zraven.utils.compatrZraven.utils.encodingrZraven.utils.wsgirrZraven.utils.confrZ	NamespaceZ
raven_signals�signalrr�objectrrrr�<module>s.




Zerion Mini Shell 1.0