ok

Mini Shell

Direktori : /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.Zintervalr&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)r9rB)r.r&r&r'�did_failyszClientState.did_failN)r)
r4r5r6r8rBr=rArCrDrEr&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�getrHrIrr�NAMEr�boolZAUTO_LOG_STACKSrKZCAPTURE_LOCALSrL�intZMAX_LENGTH_STRINGrMZMAX_LENGTH_LISTrNrOrPrQZ
PROCESSORSr#r!�extrarTrU�os�environrV�
_format_reposrWrXr�transactionrYr)�module_cacher�_random�
is_enabled�info�Raven�get_thread_identZmain_thread_id�enable_breadcrumbsZ
raven.contextrZ�_context�install_sys_hook�install_logging_hook�hook_libraries)r.�dsnr\�	transportrxryrzrvZ_random_seedZoptions�o�clsrRrZr&r&r'r=�sn 





zClient.__init__cCsL|siSi}x:t|�D].\}}|ddkr<tj�t|�j�}|||<qW|S)Nr�/)rrl�path�abspathr-�__file__)r.�value�resultr�Zconfigr&r&r'rn�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})rlrmrgra�debugrdrZfrom_string�	_registry�remote�format)r.r{r|�msgr�r&r&r're�s



zClient.set_dsncs*tdkrtja�fdd�}�|_|t_dS)Ncs�j|dd�t|�dS)NZfatal)�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'rxs
zClient.install_sys_hookcCsddlm}|�dS)Nr)ry)�raven.breadcrumbsry)r.ryr&r&r'ryszClient.install_logging_hookcCsddlm}||�dS)Nr)rz)r�rz)r.Z	librariesrzr&r&r'rzszClient.hook_librariescCs|j�||�dS)N)r��register_scheme)r~�schemeZtransport_classr&r&r'r�"szClient.register_schemeccs$x|jD]}|j||�VqWdS)N)rQrp)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)rPr!�version_inforrHr�)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)rp)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)rrr��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�rR�exceptions_to_skip)r.r�r/r&r&r'�skip_error_for_loggingis
zClient.skip_error_for_loggingcCs|�|�}|jj�|�dS)N)r�rRr��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.
        rTrkr*zraven.events.%s�culpritN�	exception�
stacktraceT)ZtransformerrLZin_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�rVrUrO�fingerprint�message�project�	timestamp�
time_spent�event_id�platformZsdkrW�breadcrumbs�values)0�uuidZuuid4�hexrrR�data�
setdefaultr��capture�poprgrrKrrrrL�updaterH�_iter_framesr��anyrIro�peekr_rBrr�rVrUrTrkrOr�ZprocessZ	to_stringrr�r�rZutcnow�
PLATFORM_NAME�	SDK_VALUErWrvr�Z
get_buffer)r.�
event_typer��dater�rk�stack�
public_keyrTr��kwargsr�r2r�r��k�v�framesZ
stack_info�framerOr�r/r�Zcrumbsr&)r�r'�	build_msgqs�







$




zClient.build_msgcCst||j|jd�S)N)rNrM)rrNrM)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()
        )rw)r.r&r&r'rRszClient.contextcCs|j�d|i�S)z{
        Update the user context for future events.

        >>> client.user_context({'email': 'foo@example.com'})
        �user)rR�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)rRr�)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'})
        rk)rRr�)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'})

        rT)rRr�)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�rTr�)rrrgr��should_capturerarsr!r�r�r�rXrq�random�sendr[�
last_event_id)r.r�r�r�r�rkr�rTrXr�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'rr�szClient.is_enabledccs\d|kr$x|ddD]
}|VqWd|krXx*|dddd�dg�D]
}|VqJWdS)Nr�r�r�r����)rg)r.r�r�r&r&r'r��s
"zClient._iter_framescCs|j��dS)N)r^rD)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�rk)r<)�
isinstancer
rr<rb�error�typer4r��_log_failed_submissionr^rC)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�rg�appendrcr�)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^rAr�r�rar��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)Zprotocolr�r%Zapi_keyZ
api_secretzapplication/octet-stream)z
User-Agentz
X-Sentry-AuthzContent-EncodingzContent-Type)r�r�r�)rF�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)NZdeflater&)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�Z
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)r5r4rYr�)r.r�Z
exclusionsZstring_exclusionsZwildcard_exclusionsZclass_exclusionsr&)rrr'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�rrZ	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.rr	r
r�r&r&r'�captureQueryxszClient.captureQuerycKst�dt�|jf|�S)Nz8captureExceptions is deprecated, used context() instead.)r�r�r�rR)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)rRr��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_r`rar�rrr�r=rnrerxryrz�classmethodr�r�r�r
r�r�r�r�r�r�r�propertyrRr�r�r�r�r�rrr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrZcapture_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)GrZ
__future__rr�r_rlr!r@r�r�r�inspectrr�r�typesrZ	threadingrr�rZcontextlib2Zthreadr
ru�ImportError�_threadrFZ
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�rt�strr�r(�dictr)�objectr7rrr&r&r&r'�<module>sf


%&

Zerion Mini Shell 1.0