ó
º9—^c           @   sò   y d  d l  Z  Wn  e k
 r2 d  d l j Z  n Xd  d l Z e j d  d k rj d  d l Z e j Z nJ y d  d l	 m	 Z	 Wn! e k
 r¡ d  d l
 m	 Z	 n Xe	 ƒ  Z e j Z y
 e Z Wn e k
 r× e Z n Xd e f d „  ƒ  YZ d S(	   iÿÿÿÿNi   i   i    (   t
   HTMLParsert   Emailc           B   sÝ   e  Z d  Z d d d d d d „ Z e d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z e j d „  ƒ Z e d „  ƒ Z	 e	 j d „  ƒ Z	 e d	 „  ƒ Z
 e
 j d
 „  ƒ Z
 e d „  ƒ Z e j d „  ƒ Z d „  Z d „  Z RS(   s'   An email address with an optional name.i    c         C   sÆ   d |  _ d |  _ d |  _ d |  _ d |  _ | rJ | rJ |  j | ƒ n0 | d k	 rb | |  _ n  | d k	 rz | |  _ n  | d k	 r’ | |  _	 n  | d k	 rª | |  _
 n  | d k	 rÂ | |  _ n  d S(   s¨  Create an Email with the given address and name.

        Either fill the separate name and email fields, or pass all information
        in the email parameter (e.g. email="dude Fella <example@example.com>").
        :param email: Email address, or name and address in standard format.
        :type email: string, optional
        :param name: Name for this sender or recipient.
        :type name: string, optional
        :param subject: Subject for this sender or recipient.
        :type subject: string, optional
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        N(   t   Nonet   _namet   _emailt   _substitutionst   _subjectt   _personalizationt   parse_emailt   emailt   namet   substitutionst   subjectt   personalization(   t   selfR	   R
   R   R   t   p(    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyt   __init__   s"    					c         C   s   |  j  S(   sA   Name associated with this email.

        :rtype: string
        (   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR
   L   s    c         C   sx   | d k p t | t ƒ s* t d ƒ ‚ n  | d k	 rk d | k sN d | k rk t | ƒ } d | d } n  | |  _ d S(   s}   Name associated with this email.

        :param value: Name associated with this email.
        :type value: string
        s   name must be of type string.t   ,t   ;t   "N(   R   t
   isinstancet
   basestringt	   TypeErrort   html_entity_decodeR   (   R   t   value(    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR
   T   s    $c         C   s   |  j  S(   sç   Email address.

        See http://tools.ietf.org/html/rfc3696#section-3 and its errata
        http://www.rfc-editor.org/errata_search.php?rfc=3696 for information
        on valid email addresses.

        :rtype: string
        (   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR	   e   s    
c         C   s   | |  _  d S(   sÈ  Email address.

        See http://tools.ietf.org/html/rfc3696#section-3 and its errata
        http://www.rfc-editor.org/errata_search.php?rfc=3696 for information
        on valid email addresses.

        :param value: Email address.
        See http://tools.ietf.org/html/rfc3696#section-3 and its errata
        http://www.rfc-editor.org/errata_search.php?rfc=3696 for information
        on valid email addresses.
        :type value: string
        N(   R   (   R   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR	   q   s    c         C   s   |  j  S(   sl  A list of Substitution objects. These substitutions will apply to
           the text and html content of  the body of your email, in addition
           to the subject and reply-to parameters. The total collective size
           of your substitutions may not exceed 10,000 bytes per
           personalization object.

        :rtype: list(Substitution)
        (   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR      s    
c         C   s   | |  _  d S(   s¯  A list of Substitution objects. These substitutions will apply to
        the text and html content of  the body of your email, in addition to
        the subject and reply-to parameters. The total collective size of
        your substitutions may not exceed 10,000 bytes per personalization
        object.

        :param value: A list of Substitution objects. These substitutions will
        apply to the text and html content of  the body of your email, in
        addition to the subject and reply-to parameters. The total collective
        size of your substitutions may not exceed 10,000 bytes per
        personalization object.
        :type value: list(Substitution)
        N(   R   (   R   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR      s    c         C   s   |  j  S(   sF   Subject for this sender or recipient.

        :rtype: string
        (   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR   ž   s    c         C   s   | |  _  d S(   s‘   Subject for this sender or recipient.

        :param value: Subject for this sender or recipient.
        :type value: string, optional
        N(   R   (   R   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR   ¦   s    c         C   s   |  j  S(   sm   The Personalization object or Personalization object index

        :rtype: Personalization, integer
        (   R   (   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR   ¯   s    c         C   s   | |  _  d S(   sÙ   The Personalization object or Personalization object index

        :param value: The Personalization object or Personalization object
                      index
        :type value: Personalization, integer
        N(   R   (   R   R   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR   ·   s    c         C   sj   t  j | ƒ \ } } d | k r0 | } d } n  | s? d } n  | sN d } n  | |  _ | |  _ | | f S(   sÜ   Allows passing emails as "Example Name <example@example.com>"

        :param email_info: Allows passing emails as
                           "Example Name <example@example.com>"
        :type email_info: string
        t   @N(   t   rfc822t	   parseaddrR   R
   R	   (   R   t
   email_infoR
   R	   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR   Á   s    					c         C   sH   i  } |  j  d k	 r% |  j  | d <n  |  j d k	 rD |  j | d <n  | S(   s•   
        Get a JSON-ready representation of this Email.

        :returns: This Email, ready for use in a request body.
        :rtype: dict
        R
   R	   N(   R
   R   R	   (   R   R	   (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyt   getÙ   s    N(   t   __name__t
   __module__t   __doc__R   R   t   propertyR
   t   setterR	   R   R   R   R   R   (    (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyR      s$   )	
	(   i   i   i    (   R   t   ImportErrort   email.utilst   utilst   syst   version_infot   htmlt   unescapeR   R    t   html.parsert   __html_parser__R   t	   NameErrort   strt   objectR   (    (    (    s=   /tmp/pip-unpacked-wheel-v7av_c/sendgrid/helpers/mail/email.pyt   <module>   s$   		

