Your IP : 18.222.182.226


Current Path : /opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/
Upload File :
Current File : //opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyc

�
��Yc@@s�dZddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZejd�Z
d�Zd	e	fd
��YZdS(s�
raven.contrib.awslambda
~~~~~~~~~~~~~~~~~~~~

Raven wrapper for AWS Lambda handlers.

:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
i(tabsolute_importN(tFunctionType(tClient(t
HTTPTransportssentry.errors.clientcC@s.idd6dd6dd6dd6d	d
6dd6S(
NtAWS_LAMBDA_FUNCTION_NAMEtlambdatAWS_LAMBDA_FUNCTION_VERSIONtversiontAWS_LAMBDA_FUNCTION_MEMORY_SIZEtmemory_sizetAWS_LAMBDA_LOG_GROUP_NAMEt	log_grouptAWS_LAMBDA_LOG_STREAM_NAMEt
log_streamt
AWS_REGIONtregion((((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pytget_default_tagsstLambdaClientcB@seeZdZd�Zd�Zd�Zddd�Zed��Z	ed��Z
ed��ZRS(	s�
    Raven decorator for AWS Lambda.

    By default, the lambda integration will capture unhandled exceptions and instrument logging.

    Usage:

    >>> from raven.contrib.awslambda import LambdaClient
    >>>
    >>>
    >>> client = LambdaClient()
    >>>
    >>> @client.capture_exceptions
    >>> def handler(event, context):
    >>>    ...
    >>>    raise Exception('I will be sent to sentry!')

    cO@s5|jdt�}tt|�jd|||�dS(Nt	transport(tgetRtsuperRt__init__(tselftargstkwargsR((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR8scO@s�d|kri|d<}n
|d}|jdd�}|jdd�}|j|�}|rp|j|�n|r�|j|�}|r�|j|�n|j||�|d<ntt|�j||�S(Ntdatateventtcontexttextra(	RtNonet_get_user_interfacetupdatet_get_http_interfacet_get_extra_dataRRtcapture(RRRRRRt	user_infot	http_info((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR"<s
cO@s�tt|�j||�}x=t�j�D],\}}|dj|tjj|��q+W|jdtjjd��|jdtjjd��|S(NttagstreleasetSENTRY_RELEASEtenvironmenttSENTRY_ENVIRONMENT(	RRt	build_msgRtitemst
setdefaulttostenvironR(RRRRtoptiontdefault((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR*Ms$c@s\t�t�s%tj�jd��S�p1tf�tj�����fd��}|S(s�
        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():
        >>>     ...

        ``kwargs`` are passed through to ``.captureException``.
        t
exceptionsc@sXy�||||�SWn:�k
rS�jd|d||��jj��nXdS(NRR(tcaptureExceptionRtclear(RRRR(R1tfR(sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pytwrappedts

(t
isinstanceRt	functoolstpartialtcapture_exceptionst	Exceptiontwraps(RR4R1R5((R1R4RsQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR9Vs
$cC@s�|jd�r�|dd}|r�i|jdd�pG|jdd�d6|jdd�d6|jdd�d6|jd	d�d
6|jdd�d6|jd
�d6}i|d6SndS(NtrequestContexttidentitytcognitoIdentityIdtusertidtusernametsourceIpt
ip_addresstcognitoIdentityPoolIdtcognito_identity_pool_idtcognitoAuthenticationTypetcognito_authentication_typet	userAgentt
user_agent(RR(RR=R?((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR~s%cC@s|jd�r{|jd�r{i|jd�d6|jd�d6|jdd�d6|jdd�pigd6}i|d6SdS(	Ntpatht
httpMethodturltmethodtqueryStringParameterstquery_stringtheaderstrequest(RR(RRQ((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR �scC@s�i|d6|jd6t|�d6}|jr�i|jjjd6|jjjd6|jjjd6|jjjd6|jjjd6|jj	d	6|jj
d
6|d<n|S(NRtaws_request_idRsclient.installation_idsclient.app_titlesclient.app_version_namesclient.app_version_codesclient.app_package_nametcustomtenvtclient_context(RRtvarsRUtclienttinstallation_idt	app_titletapp_version_nametapp_version_codetapp_package_nameRSRT(RRt
extra_context((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR!�s
	
N(t__name__t
__module__t__doc__RR"R*RR9tstaticmethodRR R!(((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyR$s				((R`t
__future__RR-tloggingR7ttypesRt
raven.baseRtraven.transport.httpRt	getLoggertloggerRR(((sQ/opt/alt/python27/lib/python2.7/site-packages/raven/contrib/awslambda/__init__.pyt<module>	s	

?>