U
    Fc                     @   s   G d d de ZdS )c                   @   sl  e Zd ZdZdd Zdd Zdd Zedd	 Zej	d
d	 Zdd Z
edd Zej	dd Zdd Zedd Zej	dd Zdd Zedd Zej	dd Zdd Zedd Zej	dd Zedd  Zej	d!d  Zd"d# Zed$d% Zej	d&d% Zd'd( Zed)d* Zej	d+d* Zd,d- Zed.d/ Zej	d0d/ Zed1d2 Zej	d3d2 Zd4d5 Zd6S )7PersonalizationzsA Personalization defines who should receive an individual message and
    how that message should be handled.
    c                 C   s@   g | _ d| _g | _g | _d| _g | _g | _g | _d| _d| _	dS )z@Create an empty Personalization and initialize member variables.N)
_tos_from_email_ccs_bccs_subject_headers_substitutions_custom_args_send_at_dynamic_template_dataself r   I/tmp/pip-unpacked-wheel-7j3043uk/sendgrid/helpers/mail/personalization.py__init__   s    zPersonalization.__init__c                 C   sp   t |}|jdkr | | d S |jdkr8| | d S |jdkrP| | d S |jdkrd|| _d S tdd S )NToCcZBccFromz(Please use a To, From, Cc or Bcc object.)type__name__add_toadd_ccadd_bcc
from_email
ValueError)r   emailZ
email_typer   r   r   	add_email   s    






zPersonalization.add_emailc                    sh   g }|D ]Z}t |tr"|d  n|j  t fdd|D rt |trP|n| }|| q|S )Nr   c                 3   s   | ]}|d     kV  qdS )r   N)lower).0Zunique_recipientZrecipient_emailr   r   	<genexpr>(   s    z9Personalization._get_unique_recipients.<locals>.<genexpr>)
isinstancedictr   r   allgetappend)r   Z
recipientsZunique_recipientsZ	recipientZnew_unique_recipientr   r   r   _get_unique_recipients#   s     z&Personalization._get_unique_recipientsc                 C   s   |  | jS )zSA list of recipients for this Personalization.

        :rtype: list(dict)
        )r&   r   r   r   r   r   tos1   s    zPersonalization.tosc                 C   s
   || _ d S N)r   r   valuer   r   r   r'   9   s    c                 C   s   |j r6t|j tr*|j D ]}| | qn| |j  |jrD|j| _|jrlt|jtr`|j| _n|j | _| j	|  dS )zTAdd a single recipient to this Personalization.

        :type email: Email
        N)
substitutionsr!   listadd_substitutiondynamic_template_datasubjectstrr$   r   r%   )r   r   substitutionr   r   r   r   =   s    

zPersonalization.add_toc                 C   s   | j S r(   r   r   r   r   r   r   T   s    zPersonalization.from_emailc                 C   s
   || _ d S r(   r2   r)   r   r   r   r   X   s    c                 C   s   |  | _d S r(   )r$   r   r   r   r   r   r   set_from\   s    zPersonalization.set_fromc                 C   s   |  | jS )z`A list of recipients who will receive copies of this email.

        :rtype: list(dict)
        )r&   r   r   r   r   r   ccs_   s    zPersonalization.ccsc                 C   s
   || _ d S r(   )r   r)   r   r   r   r5   g   s    c                 C   s   | j |  dS )zAdd a single recipient to receive a copy of this email.

        :param email: new recipient to be CCed
        :type email: Email
        N)r   r%   r$   r3   r   r   r   r   k   s    zPersonalization.add_ccc                 C   s   |  | jS )zmA list of recipients who will receive blind carbon copies of this email.

        :rtype: list(dict)
        )r&   r   r   r   r   r   bccss   s    zPersonalization.bccsc                 C   s
   || _ d S r(   )r   r)   r   r   r   r6   {   s    c                 C   s   | j |  dS )zAdd a single recipient to receive a blind carbon copy of this email.

        :param email: new recipient to be BCCed
        :type email: Email
        N)r   r%   r$   r3   r   r   r   r      s    zPersonalization.add_bccc                 C   s   | j S )zThe subject of your email (within this Personalization).

        Char length requirements, according to the RFC:
        https://stackoverflow.com/a/1592310

        :rtype: string
        r   r   r   r   r   r/      s    	zPersonalization.subjectc                 C   s
   || _ d S r(   r7   r)   r   r   r   r/      s    c                 C   s   | j S )zTThe headers for emails in this Personalization.

        :rtype: list(dict)
        r   r   r   r   r   headers   s    zPersonalization.headersc                 C   s
   || _ d S r(   r8   r)   r   r   r   r9      s    c                 C   s   | j |  dS )zSAdd a single Header to this Personalization.

        :type header: Header
        N)r   r%   r$   )r   headerr   r   r   
add_header   s    zPersonalization.add_headerc                 C   s   | j S )z]Substitutions to be applied within this Personalization.

        :rtype: list(dict)
        r   r   r   r   r   r+      s    zPersonalization.substitutionsc                 C   s
   || _ d S r(   r<   r)   r   r   r   r+      s    c                 C   s"   t |ts| }| j| dS )zbAdd a new Substitution to this Personalization.

        :type substitution: Substitution
        N)r!   r"   r$   r   r%   )r   r1   r   r   r   r-      s    
z Personalization.add_substitutionc                 C   s   | j S )ziThe CustomArgs that will be carried along with this Personalization.

        :rtype: list(dict)
        r	   r   r   r   r   custom_args   s    zPersonalization.custom_argsc                 C   s
   || _ d S r(   r=   r)   r   r   r   r>      s    c                 C   s   | j |  dS )zVAdd a CustomArg to this Personalization.

        :type custom_arg: CustomArg
        N)r	   r%   r$   )r   Z
custom_argr   r   r   add_custom_arg   s    zPersonalization.add_custom_argc                 C   s   | j S )zA unix timestamp allowing you to specify when you want emails from
        this Personalization to be delivered. Scheduling more than 72 hours in
        advance is forbidden.

        :rtype: int
        r
   r   r   r   r   send_at   s    zPersonalization.send_atc                 C   s
   || _ d S r(   r@   r)   r   r   r   rA      s    c                 C   s   | j S )zData for dynamic transactional template.
        Should be JSON-serializable structure.

        :rtype: JSON-serializable structure
        )r   r   r   r   r   r.      s    z%Personalization.dynamic_template_datac                 C   s   t |ts| }|| _d S r(   )r!   r"   r$   r   r)   r   r   r   r.      s    
c                 C   s   i }dD ]"}t | |}|r|||dd < qt | d}|rB||d< dD ]}t | |}|rF|||< qFdD ]2}t | |}|rfi }|D ]}|| |||< qqf|S )z
        Get a JSON-ready representation of this Personalization.

        :returns: This Personalization, ready for use in a request body.
        :rtype: dict
        )r'   r5   r6   Nr   from)r/   rA   r.   )r9   r+   r>   )getattrupdate)r   Zpersonalizationkeyr*   
from_valueZ	prop_namepropobjr   r   r   r$      s(    





zPersonalization.getN)r   
__module____qualname____doc__r   r   r&   propertyr'   setterr   r   r4   r5   r   r6   r   r/   r9   r;   r+   r-   r>   r?   rA   r.   r$   r   r   r   r   r      sh   


















	


r   N)objectr   r   r   r   r   <module>       