Your IP : 216.73.216.61


Current Path : /opt/alt/python35/lib/python3.5/site-packages/raven/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/raven/__pycache__/base.cpython-35.pyc



��Y�t�@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddl
mZddlmZddlmZejd	d
fkr�ddlZnddlZyddlmZWn"ek
r"ddlmZYnXddlZddlmZdd
lmZddl 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/m0Z0m1Z1ddl2m3Z3ddl4m5Z5m6Z6ddl7ZdfZ8da9dZ:dddej;iZ<da=ejd	d
fkrPe>Z?dd�Z@Gdd�deA�ZBGdd �d eC�ZDGd!d�deC�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�python�namezraven-python�versioncCs/tj}t|dd�}|dk	r+|SdS)N�raven_client)�sys�
excepthook�getattr)�hook�client�r&�;/opt/alt/python35/lib/python3.5/site-packages/raven/base.py�get_excepthook_clientEs	r(c@seZdZdd�ZdS)�ModuleProxyCachecCsG|jdd�\}}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)Lsr)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__\s		zClientState.__init__cCsV|j|jkrdS|jp2t|jd�d}tj�|j|krRdSdS)NT�r	F)r9r8r<�minr;�timer:)r.�intervalr&r&r'�
should_trybszClientState.should_trycCs7|j|_|jd7_tj�|_||_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_successss		zClientState.set_successcCs|j|jkS)N)r9rC)r.r&r&r'�did_failyszClientState.did_failN)
r4r5r6r8rCr=rBrDrErFr&r&r&r'r7Xsr7c
@s�eZdZdZejd�ZdZede	�Z
dddddddddd	�Zd
d�Zdddd
�Z
dd�Zdd�Zdd�Zedd��Zdd�Zdd�Zdd�Zdd�Zddd�Zd d!�Zd"d#�Zd$d%�Zddddddddd&d'�Zd(d)�Zed*d+��Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"dddddddd4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d<d=�Z'd>d?�Z(dd@dA�Z)ddBdC�Z*ddDdE�Z+dFdG�Z,dHdI�Z-dJdK�Z.dLdM�Z/ddNdO�Z0dPdQ�Z1ddRdS�Z2fddTdU�Z3dVdW�Z4dXdY�Z5e5Z6edZd[��Z7e7j8d\d[��Z7dS)]raU
    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�6Z
transportsNFTc	Ks�|	}
t�|_||_|j}t�|_tjd|j|j	f�|_
tjd�|_tjd�|_i|_
|j||�t|
jd�p�g�|_t|
jd�p�g�|_t|
jd�p�|
jd�p�tj�|_t|
jd�ptj�|_t|
jd	tj��|_t|
jd
�pRtj�|_t|
jd�pstj�|_ |
jd�|_!|
jd
d�|_"|
jd�|_#|j#dkr�tj$|_#|
jd�}|dkr
dt%t&dg�dd�i}||_'|
jd�p(i|_(|
jd�p@d|_)|
jd�pdt*j+jd�|_,|j-|
jd��|_.|
jd�dk	r�|
jd�nd|_/t0�|_1t|
jd�p�f�|_2t3�|_4t5|�|_6|j7�s|j
j8d�t9dkr%|a9t:�|_;||_<ddl=m>}
|
|�|_?|ri|j@�|ry|jA�|jB|�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_exceptionszaRaven 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			0"	$$			

zClient.__init__cCsf|s
iSi}xOt|�D]A\}}|ddkrTtjjt|�j�}|||<qW|S)Nr�/)rrm�path�abspathr-�__file__)r.�value�resultr��configr&r&r'ro�szClient._format_reposcCs�|r<tjjd�r<d}|jj|�tjd}||jkr�|sctd|�}ntj|d|d|j�}||j|<||_	n|j||_	|jjdj
|j	��dS)NZ
SENTRY_DSNz8Configuring Raven from environment variable 'SENTRY_DSN'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$�jd|dd�t|�dS)N�exc_info�level�fatal)�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'rzszClient.install_logging_hookcCsddlm}||�dS)Nr)r{)r�r{)r.�	librariesr{r&r&r'r{szClient.hook_librariescCs|jj||�dS)N)r��register_scheme)r��schemeZtransport_classr&r&r'r�"szClient.register_schemeccs*x#|jD]}|j||�Vq
WdS)N)rRrq)r.�	processorr&r&r'�get_processors&szClient.get_processorscCsN|js
iStj}t|j�}dj|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_versionscCstjdt�|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
7s	zClient.get_identcCs|j||�S)N)rq)r.rr&r&r'�get_handlerCszClient.get_handlercCs7|j�sdS|jj�}|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_dsncCs�d}d}yAt|do)|djj�}|drF|djpId}Wnttfk
rgYnX|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|j|�}||jjkS)N)r�rS�exceptions_to_skip)r.r�r/r&r&r'�skip_error_for_loggingiszClient.skip_error_for_loggingcCs&|j|�}|jjj|�dS)N)r�rSr��add)r.r�r/r&r&r'�record_exception_seenmszClient.record_exception_seenc
s�tj�j}t|jj|�}|jdi�|jdi�d|krZd|}|j|�}|j|
�}
|
j	dd�}|j
d�r�|d}x0t|
�D]"\}}||kr�|||<q�W|dkr�d|kr�|j}|rXd|krX|d	kr!t
�}n|}t|d
|jd|j�}|jd|i�|jrx�|j|�D]�}|j
d�dk	r�qq|j
d
���s�qq�jd�r�d|d<qqt�fdd�|jD��ot�fdd�|jD��|d<qqW|s%|jj�}|j
d�sP|
j
d�pItj|d<|j
d�sl|j|d<|j
d�s�|j�|d<|jdk	r�|j|d<|jdk	r�|j|d<t|j|d|�|d<t|j |d|�|d<|j	dd�p|j!}|r2|djd|�|rB||d<|	rR|	|d<x*|j"�D]}|j|j#|��q_Wd|kr�|
j
d|j$|��|d<x2t|d�D] \}}t%|�|d|<q�Wx5t|d�D]#\}}|j|�|d|<q�W|jd|j&j'�|jd|pEt(j)��|jd|�|jd|�|jdt*�|jd t+�|jd!|j,�|j-r�|jj.j/�}|r�|jd"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�
stacktraceTZtransformerrMZin_appr0zraven.Fc3s|]}�j|�VqdS)N)�
startswith)�.0�x)r�r&r'�	<genexpr>�sz#Client.build_msg.<locals>.<genexpr>c3s|]}�j|�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|d|jd|j�S)NrOrN)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|jjd|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_contexts	zClient.user_contextcKs|jjd|i�S)z|
        Update the http context for future events.

        >>> client.http_context({'url': 'http://example.com'})
        �request)rSr�)r.r�r�r&r&r'�http_contexts	zClient.http_contextcKs|jjd|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$s	zClient.extra_contextcKs|jjd|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.s	zClient.tags_contextc	
Ks�|j�sdS|	jd�}
|
dk	r�|j|
�r>dS|j|
�st|jjd|
ddtj��dS|j|
�|j	||||||d||	�}|dkr�|j
}|jj�|kr�|j
|�|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: %srrUr�)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
|jj�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_enabledccsld|kr*x|ddD]}|VqWd|krhx/|ddddjdg�D]}|VqYWdS)Nr�r�r�r�r+���)rh)r.r�r�r&r&r'r��s	)zClient._iter_framescCs|jj�dS)N)r_rE)r.r&r&r'�_successful_send�szClient._successful_sendc	Cs�d}t|t�rRt|t�r-|j}|jjdt|�j|j�n(|jjd||dddd|i�|j	|�|j
jd|�dS)	Nrz*Sentry responded with an API error: %s(%s)z,Sentry responded with an error: %s (url: %s)r�Trlr�r<)�
isinstancer
rr<rc�error�typer4r��_log_failed_submissionr_rD)r.�excr�r�r<r&r&r'�_failed_send�s				

zClient._failed_sendcCs�|jdd�}|g}d|kr�d|dddkr�xq|ddddjdg�D]M}|jdd	|jd
d�d|jdd�d
|jdd�i�qbW|jj|�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�fn�filenameZunknown_filename�lineno�func�functionZunknown_functionNr�r�r�)r�rh�appendrdr�)r.r�r��outputr�r&r&r'r��s	$)	zClient._log_failed_submissioncs|dkri}�jrL�jj�rL�j����j��dS�jjdt�������fdd�}yX�jj	�}|j
r�|j��|�j|�n|j
��|��j�Wn;tk
r}z�jr��||�WYdd}~XnXdS)Nz"Sending message of length %d to %scs �j|��j���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|�}|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��szClient.sendcKs�dtjf}|sXtj�}td|jd|d|d|jjd|jj�}d|d|d	|j�d
di}|j	d|jj
d
|d||�S)z
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote``.
        zraven-python/%sZprotocolr�r%Zapi_keyZ
api_secretz
User-Agentz
X-Sentry-AuthzContent-EncodingzContent-Typezapplication/octet-streamr�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_encodingcCstjtj|�jd��S)z8
        Serializes ``data`` into a raw string.
        �utf8)�zlib�compressr�dumpsr�)r.r�r&r&r'r�
sz
Client.encodecCstjtj|�jd��S)z2
        Unserializes a string, ``data``.
        r�)r�loadsr��
decompressr�)r.r�r&r&r'r�sz
Client.decodecKs|jdd||�S)zr
        Creates an event from ``message``.

        >>> client.captureMessage('My event just happened!')
        zraven.events.Messager�)r�)r.r�r�r&r&r'�captureMessageszClient.captureMessagecKs:|dks|dkr$tj�}|jdd||�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``.
        NTzraven.events.Exceptionr�)r!r�r�)r.r�r�r&r&r'r�szClient.captureExceptioncs�|d�d�j�jf�|j}dd�|D�}dd�|D�}dd�|D�}�|krrdS�j|kr�dS�|kr�dSt�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$|]}|jd�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(|]}�j|dd��VqdS)Nr+r�)r�)r�r�)�exc_namer&r'r�DsT)r5r4rZr�)r.r�Z
exclusionsZstring_exclusionsZwildcard_exclusionsZclass_exclusionsr&)r
r	r'r�4s"
	zClient.should_capturecswd}tf}t|t�r'|}n|dk	r9|}tj��fdd��}||�}|rs||�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-�j���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�rr�	decoratorr&)r�r.r'�capture_exceptionsHs		
zClient.capture_exceptionsc	Ks"|jdd|d|d||�S)zi
        Creates an event for a SQL query.

        >>> client.captureQuery('SELECT * FROM foo')
        zraven.events.Query�query�params�engine)r�)r.rrrr�r&r&r'�captureQueryxszClient.captureQuerycKstjdt�|j|�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)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}sl	Q
�


	Q0

c@s"eZdZdZdd�ZdS)�DummyClientz"Sends messages into an empty void.cKsdS)Nr&)r.r�r&r&r'r��szDummyClient.sendN)r4r5r6rr�r&r&r&r'r�sr)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)�objectr7rrr&r&r&r'�<module>s`
"	%���#