σ
P'^c           @@  s!  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 y d d l m Z Wn' e k
 r£ d e f d	     YZ n Xd
 d d d g Z d a d   Z d
 e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d S(   sa   
    celery.utils.mail
    ~~~~~~~~~~~~~~~~~

    How task error emails are formatted and sent.

i    (   t   absolute_importN(   t   MIMETexti   (   t
   maybe_list(   t   SSLErrorR   c           B@  s   e  Z d  Z RS(   s+   fallback used when ssl module not compiled.(   t   __name__t
   __module__t   __doc__(    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR      s   t   SendmailWarningt   Messaget   Mailert	   ErrorMailc           C@  s   t  d  k r t j   a  n  t  S(   N(   t   _local_hostnamet   Nonet   sockett   getfqdn(    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   get_local_hostname   s    c           B@  s   e  Z d  Z RS(   s1   Problem happened while sending the email message.(   R   R   R   (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR   &   s   c           B@  s2   e  Z d d d d d  d  Z d   Z d   Z RS(   s   us-asciic         C@  s7   t  |  |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   t   tot   sendert   subjectt   bodyt   charset(   t   selfR   R   R   R   R   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   __init__,   s
    			c         C@  s   d j  |   S(   Ns*   <Email: To:{0.to!r} Subject:{0.subject!r}>(   t   format(   R   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   __repr__4   s    c         C@  sR   t  |  j d |  j  } |  j | d <|  j | d <d j |  j  | d <| j   S(   Nt   plaint   Subjectt   Froms   , t   To(   R   R   R   R   R   t   joinR   t	   as_string(   R   t   msg(    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   __str__7   s
    N(   R   R   R   R   R   R    (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR   *   s   		c           B@  s;   e  Z d  d d d d e e d  Z e d  Z d   Z RS(   t	   localhosti    i   c         C@  sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   hostt   portt   usert   passwordt   timeoutt   use_sslt   use_tls(   R   R"   R#   R$   R%   R&   R'   R(   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR   A   s    						c         K@  s   y |  j  | |  Wnd t k
 rz } | s2   n  t j t d j | i d j | j  d 6| j d 6t	 j
      n Xd  S(   Ns)   Mail could not be sent: {0!r} {1!r}
{2!r}s   , R   R   (   t   _sendt	   Exceptiont   warningst   warnR   R   R   R   R   t	   tracebackt   format_stack(   R   t   messaget   fail_silentlyt   kwargst   exc(    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   sendK   s    	
c         K@  sι   |  j  r t j n t j } | |  j |  j d |  j d t   | } |  j ro | j	   | j
   | j	   n  |  j r |  j r | j |  j |  j  n  | j | j | j t |   y | j   Wn t k
 rδ | j   n Xd  S(   NR&   t   local_hostname(   R'   t   smtplibt   SMTP_SSLt   SMTPR"   R#   R&   R   R(   t   ehlot   starttlsR$   R%   t   logint   sendmailR   R   t   strt   quitR   t   close(   R   R/   R1   t   Clientt   client(    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR)   W   s    	

N(   R   R   R   t   FalseR   R3   R)   (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR	   ?   s   	c           B@  s\   e  Z d  Z d Z d Z d j d e  Z d   Z d   Z d   Z	 d   Z
 e d	  Z RS(
   s8  Defines how and when task error e-mails should be sent.

    :param task: The task instance that raised the error.

    :attr:`subject` and :attr:`body` are format strings which
    are passed a context containing the following keys:

    * name

        Name of the task.

    * id

        UUID of the task.

    * exc

        String representation of the exception.

    * args

        Positional arguments.

    * kwargs

        Keyword arguments.

    * traceback

        String representation of the traceback.

    * hostname

        Worker nodename.

    s   -- s<           [{hostname}] Error: Task {name} ({id}): {exc!r}
    sτ   
Task {{name}} with id {{id}} raised exception:
{{exc!r}}


Task was called with args: {{args}} kwargs: {{kwargs}}.

The contents of the full traceback was:

{{traceback}}

{EMAIL_SIGNATURE_SEP}
Just to let you know,
py-celery at {{hostname}}.
t   EMAIL_SIGNATURE_SEPc         K@  s=   | |  _  | j d |  j  |  _ | j d |  j  |  _ d  S(   NR   R   (   t   taskt   getR   R   (   R   RC   R1   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR   ͺ   s    	c         C@  s   t  S(   se   Return true or false depending on if a task error mail
        should be sent for this type of error.(   t   True(   R   t   contextR2   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   should_send―   s    c         C@  s   |  j  j   j |   S(   N(   R   t   stripR   (   R   RF   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   format_subject΄   s    c         C@  s   |  j  j   j |   S(   N(   R   RH   R   (   R   RF   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   format_body·   s    c         C@  sG   |  j  | |  rC |  j j j |  j |  |  j |  d | n  d  S(   NR0   (   RG   RC   t   appt   mail_adminsRI   RJ   (   R   RF   R2   R0   (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR3   Ί   s    (   R   R   R   RB   R   R   R   R   RG   RI   RJ   RE   R3   (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyR
   k   s   $				(   R   t
   __future__R    R5   R   R-   R+   t   email.mime.textR   t
   functionalR   t   sslR   t   ImportErrorR*   t   __all__R   R   R   t   UserWarningR   t   objectR   R	   R
   (    (    (    s3   /tmp/pip-unpacked-wheel-gV1wwp/celery/utils/mail.pyt   <module>   s$   	,