Your IP : 3.129.210.35


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

B

��Y�t�@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddl
mZddlmZddlmZejd	kr�ddlZnddlZydd
lmZWn ek
r�dd
lmZYnXddlZddlmZddlmZdd
l m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddl2m3Z3ddl4m5Z5m6Z6ddl7ZdZ8da9dZ:dej;d�Z<da=ejd	k�r�e>Z?dd�Z@Gdd�deA�ZBGdd�deC�ZDGdd �d eC�ZEGd!d"�d"eE�ZFdS)#z�
raven.base
~~~~~~~~~~

:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
�)�absolute_importN)�datetime)�isclass)�Random)�FunctionType)�local)��)�	get_ident)�defaults)�RemoteConfig)�APIError�RateLimited)�json�get_versions�get_auth_header�merge_dicts)�	text_type�	iteritems)�
to_unicode)�	transform)�get_stack_info�iter_stack_frames)�TransactionStack)�TransportRegistry�default_transports)�Client�pythonzraven-python)�name�versioncCs"tj}t|dd�}|dk	r|SdS)N�raven_client)�sys�
excepthook�getattr)�hook�client�r&�;/opt/alt/python37/lib/python3.7/site-packages/raven/base.py�get_excepthook_clientEsr(c@seZdZdd�ZdS)�ModuleProxyCachecCs2|�dd�\}}tt|ii|g�|�}|||<|S)N�.�)�rsplitr#�
__import__)�self�key�module�
class_name�handlerr&r&r'�__missing__Ms
zModuleProxyCache.__missing__N)�__name__�
__module__�__qualname__r3r&r&r&r'r)Lsr)c@s>eZdZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Z	d
S)�ClientStater+rcCs|j|_d|_d|_d|_dS)Nr)�ONLINE�status�
last_check�retry_number�retry_after)r.r&r&r'�__init__\szClientState.__init__cCs@|j|jkrdS|jp$t|jd�d}t��|j|kr<dSdS)NT�r	F)r9r8r<�minr;�timer:)r.�intervalr&r&r'�
should_trybszClientState.should_trycCs*|j|_|jd7_t��|_||_dS)Nr+)�ERRORr9r;r@r:r<)r.r<r&r&r'�set_failms
zClientState.set_failcCs|j|_d|_d|_d|_dS)Nr)r8r9r:r;r<)r.r&r&r'�set_successsszClientState.set_successcCs|j|jkS)N)r9rC)r.r&r&r'�did_failyszClientState.did_failN)r)
r4r5r6r8rCr=rBrDrErFr&r&r&r'r7Xs
r7c@s�eZdZdZe�d�ZdZee	d�Z
d^dd	�Zd
d�Zd_dd
�Z
dd�Zdd�Zdd�Zedd��Zdd�Zdd�Zdd�Zdd�Zd`dd�Zd d!�Zd"d#�Zd$d%�Zdad&d'�Zd(d)�Zed*d+��Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"dbd4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d<d=�Z'd>d?�Z(dcd@dA�Z)dddBdC�Z*dedDdE�Z+dFdG�Z,dHdI�Z-dJdK�Z.dLdM�Z/dfdNdO�Z0dPdQ�Z1dgdRdS�Z2dhdUdV�Z3dWdX�Z4dYdZ�Z5e5Z6ed[d\��Z7e7j8d]d\��Z7dS)iraU
    The base Raven client.

    Will read default configuration from the environment variable
    ``SENTRY_DSN`` if available.

    >>> from raven import Client

    >>> # Read configuration from ``os.environ['SENTRY_DSN']``
    >>> client = Client()

    >>> # Specify a DSN explicitly
    >>> client = Client(dsn='https://public_key:secret_key@sentry.local/project_id')

    >>> # Record an exception
    >>> try:
    >>>     1/0
    >>> except ZeroDivisionError:
    >>>     ident = client.get_ident(client.captureException())
    >>>     print "Exception caught; reference is %s" % ident
    �raven�6)Z
transportsNFTc	Ks~|	}
t�|_||_|j}t�|_t�d|j|j	f�|_
t�d�|_t�d�|_i|_
|�||�t|
�d�ppg�|_t|
�d�p�g�|_t|
�d�p�|
�d�p�tj�|_t|
�d�p�tj�|_t|
�d	tj��|_t|
�d
�p�tj�|_t|
�d�p�tj�|_ |
�d�|_!|
�d
d�|_"|
�d�|_#|j#dk�r:tj$|_#|
�d�}|dk�rfdt%t&dg�dd�i}||_'|
�d��pzi|_(|
�d��p�d|_)|
�d��p�t*j+�d�|_,|�-|
�d��|_.|
�d�dk	�r�|
�d�nd|_/t0�|_1t|
�d��p�d�|_2t3�|_4t5|�|_6|�7��s"|j
�8d�t9dk�r0|a9t:�|_;||_<ddl=m>}
|
|�|_?|�rb|�@�|�rp|�A�|�B|�dS)Nz%s.%sz
sentry.errorszsentry.errors.uncaught�
include_paths�
exclude_pathsr�machine�auto_log_stacks�capture_locals�string_max_length�list_max_length�site�include_versionsT�
processors�contextzsys.argv�argv�tags�environment�releaseZHEROKU_SLUG_COMMIT�repos�sample_rater+�ignore_exceptionsr&zaRaven is not configured (logging is disabled). Please see the documentation for more information.r)�Context)Cr�_local_state�raise_send_errors�	__class__r7�state�logging�	getLoggerr5r4�logger�error_logger�uncaught_logger�_transport_cache�set_dsn�set�getrIrJrr�NAMEr�boolZAUTO_LOG_STACKSrLZCAPTURE_LOCALSrM�intZMAX_LENGTH_STRINGrNZMAX_LENGTH_LISTrOrPrQrRZ
PROCESSORSr#r!�extrarUrV�os�environrW�
_format_reposrXrYr�transactionrZr)�module_cacher�_random�
is_enabled�info�Raven�get_thread_identZmain_thread_id�enable_breadcrumbsZ
raven.contextr[�_context�install_sys_hook�install_logging_hook�hook_libraries)r.�dsnr]�	transportryrzr{rwZ_random_seed�options�o�clsrSr[r&r&r'r=�sn 





zClient.__init__cCsL|siSi}x:t|�D].\}}|ddkr<tj�t|�j�}|||<qW|S)Nr�/)rrm�path�abspathr-�__file__)r.�value�resultr��configr&r&r'ro�szClient._format_reposcCs�|s*tj�d�r*d}|j�|�tjd}||jkrh|sDt|d�}ntj|||jd�}||j|<||_	n|j||_	|j�d�
|j	��dS)NZ
SENTRY_DSNz8Configuring Raven from environment variable 'SENTRY_DSN')r})r}Ztransport_registryzConfiguring Raven for host: {0})rmrnrhrb�debugrerZfrom_string�	_registry�remote�format)r.r|r}�msgr�r&r&r'rf�s



zClient.set_dsncs*tdkrtja�fdd�}�|_|t_dS)Ncs�j|dd�t|�dS)N�fatal)�exc_info�level)�captureException�__excepthook__)r�)r.r&r'�handle_exceptionsz1Client.install_sys_hook.<locals>.handle_exception)r�r!r"r )r.r�r&)r.r'rys
zClient.install_sys_hookcCsddlm}|�dS)Nr)rz)�raven.breadcrumbsrz)r.rzr&r&r'rzszClient.install_logging_hookcCsddlm}||�dS)Nr)r{)r�r{)r.�	librariesr{r&r&r'r{szClient.hook_librariescCs|j�||�dS)N)r��register_scheme)r��schemeZtransport_classr&r&r'r�"szClient.register_schemeccs$x|jD]}|j||�VqWdS)N)rRrq)r.�	processorr&r&r'�get_processors&szClient.get_processorscCs<|js
iStj}t|j�}d�|d|d|d�|d<|S)Nz{0}.{1}.{2}rr+r	r)rQr!�version_inforrIr�)r.r��modulesr&r&r'�get_module_versions*s
zClient.get_module_versionscCst�dt�|S)z�
        Returns a searchable string representing a message.

        >>> result = client.capture(**kwargs)
        >>> ident = client.get_ident(result)
        zVClient.get_ident is deprecated. The event ID is now returned as the result of capture.)�warnings�warn�DeprecationWarning)r.r�r&r&r'r
7szClient.get_identcCs|j||�S)N)rq)r.rr&r&r'�get_handlerCszClient.get_handlercCs*|��sdS|j��}|s|Sd||fS)z�
        Returns a public DSN which is consumable by raven-js

        >>> # Return scheme-less DSN
        >>> print client.get_public_dsn()

        >>> # Specify a scheme to use (http or https)
        >>> print client.get_public_dsn('https')
        Nz%s:%s)rsr��get_public_dsn)r.r��urlr&r&r'r�Fs

zClient.get_public_dsnc	Csvd}d}y2t|do|djj�}|dr4|djp6d}Wnttfk
rRYnX|dt|d�|t|d�|fS)Nrr	r+)�id�tb_frame�f_code�tb_lasti�AttributeError�
IndexError)r.r�Zcode_idZlast_idr&r&r'�_get_exception_keyWs

zClient._get_exception_keycCs|�|�}||jjkS)N)r�rS�exceptions_to_skip)r.r�r/r&r&r'�skip_error_for_loggingis
zClient.skip_error_for_loggingcCs|�|�}|jj�|�dS)N)r�rSr��add)r.r�r/r&r&r'�record_exception_seenms
zClient.record_exception_seenc
s�t��j}t|jj|�}|�di�|�di�d|kr@d|}|�|�}|jf|
�}
|
�	dd�}|�
d�rt|d}x$t|
�D]\}}||kr~|||<q~W|dkr�d|kr�|j}|r�d|kr�|d	kr�t
�}n|}t||j|jd
�}|�d|i�|j�r�x�|�|�D]|}|�
d�dk	�r�q|�
d����s0�q��d
��rFd|d<n8t�fdd�|jD���oxt�fdd�|jD��|d<�qW|�s�|j��}|�
d��s�|
�
d��p�tj|d<|�
d��s�|j|d<|�
d��s�|��|d<|jdk	�r�|j|d<|jdk	�r|j|d<t|j|d|�|d<t|j |d|�|d<|�	dd��pN|j!}|�rf|d�d|�|�rt||d<|	�r�|	|d<x"|�"�D]}|�|�#|���q�Wd|k�r�|
�
d|�$|��|d<x*t|d�D]\}}t%|�|d|<�q�Wx,t|d�D]\}}|�|�|d|<�qW|�d|j&j'�|�d|�pBt(�)��|�d|�|�d|�|�dt*�|�dt+�|�d |j,�|j-�r�|jj.�/�}|�r�|�d!d"|i�|S)#z�
        Captures, processes and serializes an event into a dict object

        The result of ``build_msg`` should be a standardized dict, with
        all default values available.
        rUrlr*zraven.events.%s�culpritN�	exception�
stacktraceT)ZtransformerrMZin_appr0zraven.Fc3s|]}��|�VqdS)N)�
startswith)�.0�x)r�r&r'�	<genexpr>�sz#Client.build_msg.<locals>.<genexpr>c3s|]}��|�VqdS)N)r�)r�r�)r�r&r'r��sr�Zserver_namer�rWrVrP�fingerprint�message�project�	timestamp�
time_spent�event_id�platformZsdkrX�breadcrumbs�values)0�uuidZuuid4�hexrrS�data�
setdefaultr��capture�poprhrrLrrrrM�updaterI�_iter_framesr��anyrJrp�peekr`rCrr�rWrVrUrlrPr��processZ	to_stringrr�r�r�utcnow�
PLATFORM_NAME�	SDK_VALUErXrwr�Z
get_buffer)r.�
event_typer��dater�rl�stack�
public_keyrUr��kwargsr�r2r�r��k�v�frames�
stack_info�framerPr�r/r�Zcrumbsr&)r�r'�	build_msgqs�







$




zClient.build_msgcCst||j|jd�S)N)rOrN)rrOrN)r.r�r&r&r'r�szClient.transformcCs|jS)aT
        Updates this clients thread-local context for future events.

        >>> def view_handler(view_func, *args, **kwargs):
        >>>     client.context.merge(tags={'key': 'value'})
        >>>     try:
        >>>         return view_func(*args, **kwargs)
        >>>     finally:
        >>>         client.context.clear()
        )rx)r.r&r&r'rSszClient.contextcCs|j�d|i�S)z{
        Update the user context for future events.

        >>> client.user_context({'email': 'foo@example.com'})
        �user)rS�merge)r.r�r&r&r'�user_contextszClient.user_contextcKs|j�d|i�S)z|
        Update the http context for future events.

        >>> client.http_context({'url': 'http://example.com'})
        Zrequest)rSr�)r.r�r�r&r&r'�http_contextszClient.http_contextcKs|j�d|i�S)zo
        Update the extra context for future events.

        >>> client.extra_context({'foo': 'bar'})
        rl)rSr�)r.r�r�r&r&r'�
extra_context$szClient.extra_contextcKs|j�d|i�S)zr
        Update the tags context for future events.

        >>> client.tags_context({'version': '1.0'})

        rU)rSr�)r.r�r�r&r&r'�tags_context.szClient.tags_contextc	Ks�|��sdS|	�d�}
|
dk	r^|�|
�r,dS|�|
�sT|jjd|
dt��d�dS|�|
�|j	||||||fd|i|	��}|dkr�|j
}|j��|kr�|j
f|�|d|j_|dS)a�
        Captures and processes an event and pipes it off to SentryClient.send.

        To use structured data (interfaces) with capture:

        >>> capture('raven.events.Message', message='foo', data={
        >>>     'request': {
        >>>         'url': '...',
        >>>         'data': {},
        >>>         'query_string': '...',
        >>>         'method': 'POST',
        >>>     },
        >>>     'logger': 'logger.name',
        >>> }, extra={
        >>>     'key': 'value',
        >>> })

        The finalized ``data`` structure contains the following (some optional)
        builtin values:

        >>> {
        >>>     # the culprit and version information
        >>>     'culprit': 'full.module.name', # or /arbitrary/path
        >>>
        >>>     # all detectable installed modules
        >>>     'modules': {
        >>>         'full.module.name': 'version string',
        >>>     },
        >>>
        >>>     # arbitrary data provided by user
        >>>     'extra': {
        >>>         'key': 'value',
        >>>     }
        >>> }

        :param event_type: the module path to the Event class. Builtins can use
                           shorthand class notation and exclude the full module
                           path.
        :param data: the data base, useful for specifying structured data
                           interfaces. Any key which contains a '.' will be
                           assumed to be a data interface.
        :param date: the datetime of this event
        :param time_spent: a integer value representing the duration of the
                           event (in milliseconds)
        :param extra: a dictionary of additional standard metadata
        :param stack: a stacktrace for the event
        :param tags: dict of extra tags
        :param sample_rate: a float in the range [0, 1] to sample this message
        :return: a tuple with a 32-length string identifying this event
        Nr�z*Not capturing exception due to filters: %sr)r�rUr�)rsrhr��should_capturerbrtr!r�r�r�rYrr�random�sendr\�
last_event_id)r.r�r�r�r�rlr�rUrYr�r�r&r&r'r�9s*5



zClient.capturecCs
|j��S)zg
        Return a boolean describing whether the client should attempt to send
        events.
        )r�Z	is_active)r.r&r&r'rs�szClient.is_enabledccs\d|kr$x|ddD]
}|VqWd|krXx*|dddd�dg�D]
}|VqJWdS)Nr�r�r�r����)rh)r.r�r�r&r&r'r��s
"zClient._iter_framescCs|j��dS)N)r_rE)r.r&r&r'�_successful_send�szClient._successful_sendcCsnd}t|t�r8t|t�r|j}|j�dt|�j|j�n|jjd||dd|id�|�	|�|j
j|d�dS)Nrz*Sentry responded with an API error: %s(%s)z,Sentry responded with an error: %s (url: %s)Tr�)r�rl)r<)�
isinstancer
rr<rc�error�typer4r��_log_failed_submissionr_rD)r.�excr�r�r<r&r&r'�_failed_send�s


zClient._failed_sendc
Cs�|�dd�}|g}d|kr�d|dddkr�xR|dddd�dg�D]2}|�d|�d	d
�|�dd�|�dd
�d��qLW|j�|�dS)zj
        Log a reasonable representation of an event that should have been sent
        to Sentry
        r�z<no message value>r�r�r�r�r�z-  File "%(fn)s", line %(lineno)s, in %(func)s�filenameZunknown_filename�lineno�functionZunknown_function)�fnr��funcN)r�rh�appendrdr�)r.r�r��outputr�r&r&r'r��s"

zClient._log_failed_submissionc
s�|dkri}�js4�j��s4���������dS�j�dt�������fdd�}y@�j�	�}|j
r�|���|�j|�n|�
��|����Wn2tk
r�}z�jr��||�Wdd}~XYnXdS)Nz"Sending message of length %d to %scs��|������dS)N)r��decode)�e)r�r.r�r&r'�failed_send�sz'Client.send_remote.<locals>.failed_send)r]r_rBr�r�rbr��lenr�Z
get_transportZis_asyncZ
async_sendr�r��	Exception)r.r�r��headersr�r}r�r&)r�r.r�r'�send_remote�s&


zClient.send_remotecKs|�|�}|j||d�S)zV
        Serializes the message and passes the payload onto ``send_encoded``.
        )�auth_header)�encode�send_encoded)r.r�r�r�r&r&r'r��s
zClient.sendcKsbdtjf}|s4t��}t|j|||jj|jjd�}|||��dd�}|j	f|jj
||d�|��S)z
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote``.
        zraven-python/%s)�protocolr�r%Zapi_keyZ
api_secretzapplication/octet-stream)z
User-Agentz
X-Sentry-AuthzContent-EncodingzContent-Type)r�r�r�)rG�VERSIONr@r�protocol_versionr�r�Z
secret_key�get_content_encodingr�Zstore_endpoint)r.r�r�r�Z
client_stringr�r�r&r&r'r��s$zClient.send_encodedcCsdS)N�deflater&)r.r&r&r'r�szClient.get_content_encodingcCst�t�|��d��S)z8
        Serializes ``data`` into a raw string.
        �utf8)�zlib�compressr�dumpsr�)r.r�r&r&r'r�
sz
Client.encodecCst�t�|��d��S)z2
        Unserializes a string, ``data``.
        r�)r�loadsr��
decompressr�)r.r�r&r&r'r�sz
Client.decodecKs|jdd|i|��S)zr
        Creates an event from ``message``.

        >>> client.captureMessage('My event just happened!')
        �raven.events.Messager�)r)r�)r.r�r�r&r&r'�captureMessageszClient.captureMessagecKs,|dks|dkrt��}|jdd|i|��S)a�
        Creates an event from an exception.

        >>> try:
        >>>     exc_info = sys.exc_info()
        >>>     client.captureException(exc_info)
        >>> finally:
        >>>     del exc_info

        If exc_info is not provided, or is set to True, then this method will
        perform the ``exc_info = sys.exc_info()`` and the requisite clean-up
        for you.

        ``kwargs`` are passed through to ``.capture``.
        NT�raven.events.Exceptionr�)r)r!r�r�)r.r�r�r&r&r'r�szClient.captureExceptioncs�|d�d�j�jf�|j}dd�|D�}dd�|D�}dd�|D�}�|krTdS�j|krbdS�|krndSt�fdd�|D��r�dSt�fd	d�|D��r�dSd
S)Nrz%s.%scss|]}t|t�r|VqdS)N)r��
basestring)r�r�r&r&r'r�8sz(Client.should_capture.<locals>.<genexpr>css|]}|�d�r|VqdS)�*N)�endswith)r�r�r&r&r'r�9scss|]}t|�r|VqdS)N)r)r�r�r&r&r'r�:sFc3s|]}t�|�VqdS)N)�
issubclass)r�r�)�exc_typer&r'r�Bsc3s |]}��|dd��VqdS)Nr�)r�)r�r�)�exc_namer&r'r�DsT)r5r4rZr�)r.r�Z
exclusionsZstring_exclusionsZwildcard_exclusionsZclass_exclusionsr&)rrr'r�4s"
zClient.should_capturecsRd}tf}t|t�r|}n|dk	r&|}tj��fdd��}||�}|rN||�S|S)a�
        Wrap a function or code block in try/except and automatically call
        ``.captureException`` if it raises an exception, then the exception
        is reraised.

        By default, it will capture ``Exception``

        >>> @client.capture_exceptions
        >>> def foo():
        >>>     raise Exception()

        >>> with client.capture_exceptions():
        >>>    raise Exception()

        You can also specify exceptions to be caught specifically

        >>> @client.capture_exceptions((IOError, LookupError))
        >>> def bar():
        >>>     ...

        >>> with client.capture_exceptions((IOError, LookupError)):
        >>>    ...

        ``kwargs`` are passed through to ``.captureException``.
        Nc3s2y
dVWn"|k
r,�jf���YnXdS)N)r�)�
exceptions)r�r.r&r'�make_decoratorjs

z1Client.capture_exceptions.<locals>.make_decorator)r�r�r�
contextlib�contextmanager)r.Zfunction_or_exceptionsr�r�r
r�	decoratorr&)r�r.r'�capture_exceptionsHs
zClient.capture_exceptionsr&cKs|jd|||d�|��S)zi
        Creates an event for a SQL query.

        >>> client.captureQuery('SELECT * FROM foo')
        �raven.events.Query)�query�params�engine)r)r�)r.rrrr�r&r&r'�captureQueryxszClient.captureQuerycKst�dt�|jf|�S)Nz8captureExceptions is deprecated, used context() instead.)r�r�r�rS)r.r�r&r&r'�captureExceptions�szClient.captureExceptionscOs|jjj||�dS)zp
        Records a breadcrumb with the current context.  They will be
        sent with the next event.
        N)rSr��record)r.�argsr�r&r&r'�captureBreadcrumb�szClient.captureBreadcrumbcCst|jdd�S)Nr�)r#r\)r.r&r&r'r��szClient.last_event_idcCs||j_dS)N)r\r�)r.r�r&r&r'r��s)NFNTTNTN)NN)N)NNNNNNNN)NNNNNNN)N)N)N)N)N)r&N)9r4r5r6�__doc__r`rarbr�rrr�r=rorfryrzr{�classmethodr�r�r�r
r�r�r�r�r�r�r�propertyrSr�r�r�r�r�rsr�r�r�r�r�r�r�r�r�r�rr�r�rrrrZcapture_breadcrumbr��setterr&r&r&r'r}sn


Q







Q




0


rc@seZdZdZdd�ZdS)�DummyClientz"Sends messages into an empty void.cKsdS)Nr&)r.r�r&r&r'r��szDummyClient.sendN)r4r5r6rr�r&r&r&r'r �sr )Gr�
__future__rr�r`rmr!r@r�r�r�inspectrr�r�typesr�	threadingrr�r�contextlib2�threadr
rv�ImportError�_threadrGZ
raven.confrZraven.conf.remoterZraven.exceptionsr
rZraven.utilsrrrrZraven.utils.compatrrZraven.utils.encodingrZraven.utils.serializerrZraven.utils.stacksrrZraven.utils.transactionrZraven.transport.registryrrZraven.events�__all__r�r�r�r�ru�strrr(�dictr)�objectr7rr r&r&r&r'�<module>sf


%&

?>