Your IP : 216.73.216.213


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__/breadcrumbs.cpython-35.pyc



��Y-�	@s�ddlmZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZddlm
Z
gZiZejd�Zdd�ZGd	d
�d
e�ZGdd�de�Zd
dd�Zdd�Zddddddddd�Zdd�Zddd�Zdd�Ze
dd��Zddd�Zdd�Zd d!�ZiZ d"d#�Z!e!d$�d%d&��Z"e!d'�d(d)��Z#d*d+�Z$ddl%Z&dS),�)�absolute_importN)�FunctionType)�	iteritems�get_code�	text_type�string_types)�once�ravencCsb|d|dkoa|d|dkoa|d|dkoa|d|dkoa|d|dkS)N�type�level�message�category�data�)�a�brr�B/opt/alt/python35/lib/python3.5/site-packages/raven/breadcrumbs.py�event_payload_considered_equals
rc	@sXeZdZddd�Zddddddddd�Zdd�Zd	d
�ZdS)�BreadcrumbBuffer�dcCsg|_||_dS)N)�buffer�limit)�selfrrrr�__init__s	zBreadcrumbBuffer.__init__Nc
Cs�|p|p|std��|dkr6tj�}|jjd|pKdd|d|d|d|d|i|f�|jd|j�=dS)	Nz6You must pass either `message`, `data`, or `processor`r
�default�	timestamprrr
r)�
ValueError�timer�appendr)rrrrr
rr
�	processorrrr�record#s		
zBreadcrumbBuffer.recordcCs|jdd�=dS)N)r)rrrr�clear4szBreadcrumbBuffer.clearcCs�g}x�t|j�D]�\}\}}|dk	r}y||�Wn%tk
ritjd�d}YnX|df|j|<|dk	r|s�t|d|�r|j|�qW|S)Nz&Failed to process breadcrumbs. Ignored����)�	enumerater�	Exception�logger�	exceptionrr)r�rv�idx�payloadrrrr�
get_buffer7s"

zBreadcrumbBuffer.get_buffer)�__name__�
__module__�__qualname__rr r!r+rrrrrs
	rc@seZdZdd�ZdS)�BlackholeBreadcrumbBuffercOsdS)Nr)r�args�kwargsrrrr Hsz BlackholeBreadcrumbBuffer.recordN)r,r-r.r rrrrr/Gsr/TcCs|r
t�St�S)N)rr/)�enabledrrr�make_bufferLsr3cOs||d<t||�S)Nr
)r )r
r0r1rrr�record_breadcrumbRs
r4c	CsX|dkrtj�}x9tjj�D](}|jj|||||||�q(WdS)z�Records a breadcrumb for all active clients.  This is what integration
    code should use rather than invoking the `captureBreadcrumb` method
    on a specific client.
    N)rr	�contextZget_active_contextsZbreadcrumbsr )rrrr
rr
r�ctxrrrr Xs
r cs�x0tD](}|������}|rdSqWtj�j�}|dk	rs|������}|rsdS�����fdd�}td|�dS)Ncs��}y t��}�r%��}Wntk
r:YnX�jdd�|jd|d�jdtj��j�d�i�dS)N�exc_inforr
rr)rr%�pop�update�name�logging�getLevelName�lower)rZ
formatted_msg)r0r1rr&�msgrrrqs
	z)_record_log_breadcrumb.<locals>.processorr)�special_logging_handlers�special_logger_handlers�getr:r )r&rr>r0r1�handlerr(rr)r0r1rr&r>r�_record_log_breadcrumbes
rCc	
Csft|t�s|j}n|}t|dd�r7dS|dkrRd}d}nd}d|}t|�}tj}|dkr�tjj	tj
jj�}i}t
tddd	|jd
d|jdd
j|�d|d|i|d�tj|�|d|t�}|j|_|jt|�jks9t�|j|jk|j|jkd|_|S)N�__patched_for_raven__Frr>z
level, msgz%d, msga%(offset)sif 1:
    def factory(original, record_crumb):
        def %(name)s(self, %(args)s, *args, **kwargs):
            record_crumb(self, %(fwd)s, *args, **kwargs)
            return original(self, %(args)s, *args, **kwargs)
        return %(name)s
    
�offset�
�r:r0z, �fwd�exec�factoryT)rr>)r>)�
isinstancerZim_func�getattrrr;�_srcfile�os�path�normpath�currentframe�__code__�co_filename�eval�compile�co_firstlinenor,�join�__dict__rC�__doc__�AssertionErrorr-rD)	�methr�funcr0rH�codeZlogging_srcfile�ns�new_funcrrr�_wrap_logging_method�s>	
			
	r`cCs�tj}dtjdtjdtjdtjdtjdtjdtjdtji}xEt	|�D]7\}}t
t||�|�}ttj||�qdWt
tjj
�tj_
dS)	N�debug�info�warning�warn�errorr'�critical�fatal)r;�Logger�DEBUG�INFO�WARNING�WARN�ERROR�CRITICAL�FATALrr`rL�setattr�log)�cls�methods�method_namerr_rrr�
_patch_logger�s								rucCst�dS)zXInstalls the logging hook if it was not installed yet.  Otherwise
    does nothing.
    N)rurrrr�install_logging_hook�srvcs#�fdd�}t||�dS)z�Ignores a logger for the regular breadcrumb code.  This is useful
    for framework integration code where some log messages should be
    specially handled.
    cs �dk	r|�krdSdS)NFTr)r&rr>r0r1)�allow_levelrrrB�szignore_logger.<locals>.handlerN)�register_special_log_handler)�name_or_loggerrwrBr)rwr�
ignore_logger�srzcCs/t|t�r|}n	|j}|t|<dS)aRegisters a callback for log handling.  The callback is invoked
    with give arguments: `logger`, `level`, `msg`, `args` and `kwargs`
    which are the values passed to the logging system.  If the callback
    returns `True` the default handling is disabled.
    N)rKrr:r@)ry�callbackr:rrrrx�s		rxcCstj|�dS)aRegisters a callback for log handling.  The callback is invoked
    with give arguments: `logger`, `level`, `msg`, `args` and `kwargs`
    which are the values passed to the logging system.  If the callback
    returns `True` the default handling is disabled.
    N)r?r)r{rrr�register_logging_handler
sr|cs�fdd�}|S)Ncst|�}|t�<|S)N)r�hooked_libraries)�f)r:rr�	decorators
zlibraryhook.<locals>.decoratorr)r:rr)r:r�libraryhooksr��requestscshyddlm}Wntk
r,dSYnX|j��fdd�}||_tddtj�dS)Nr)�Sessioncs[�fdd�}y�|�||�}Wntk
rL|d��YnX||�|S)NcsYtdddddd�jd�jd|r6|jp9dd	|rK|jpNdi�dS)
Nr
�httpr
r�r�url�method�status_code�reason)r r�r�r�r�)�response)�requestrr�_record_request(s
		z5_hook_requests.<locals>.send.<locals>._record_request)r%)rr�r0r1r�Zresp)�	real_send)r�r�send's


z_hook_requests.<locals>.sendz(requests.packages.urllib3.connectionpoolrw)Zrequests.sessionsr��ImportErrorr�rzr;rk)r�r�r)r�r�_hook_requestss
				r��httplibcs�yddlm}Wn"tk
r8ddlm}YnX|j�|j��fdd�}�fdd�}||_||_dS)Nr)�HTTPConnectioncsxi|_�|j�|j�|j�������fdd�}tddddd|��|��||�S)Ncs~�}|jd�sSd�dkr*dp-d���krFd�pId�f}d	|d
�i|d<|dj��|S)
N�http://�https://z%s://%s%s%si��httpsr�z:%s�r�r�r)r�r�)�
startswithr9)rZreal_url)�default_port�hostr��port�statusr�rrrNs
z7_install_httplib.<locals>.putrequest.<locals>.processorr
r�r
r�r)�_raven_status_dictr�r�r�r )rr�r�r0r1r)�real_putrequest)r�r�r�r�r�r�r�
putrequestHs
			!z$_install_httplib.<locals>.putrequestcsZ�|||�}t|dd�}|dk	rVd|krV|j|d<|j|d<|S)Nr�r�r�)rLr�r�)rr0r1r(r�)�real_getresponserr�getresponse`s

z%_install_httplib.<locals>.getresponse)r�r�r�Zhttp.clientr�r�)r�r�r�r)r�r�r�_install_httplib>s
			r�cCs_|dkrtj�}x@|D]8}tj|�}|dkrPtd|��|�qWdS)NzUnknown library %r for hooking)r}�keysrA�RuntimeError)�	libraries�libr\rrr�hook_librariesls
r�)'�
__future__rrNrr;�typesrZraven.utils.compatrrrrZraven.utilsrr?r@�	getLoggerr&r�objectrr/r3r4r rCr`rurvrzrxr|r}r�r�r�r�Z
raven.contextr	rrrr�<module>s:"
*&F

	 .