Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_substitution(self, substitution):
"""Add a substitution to the email
:param value: Add a substitution to the email
:type value: Substitution
"""
if substitution.personalization:
try:
personalization = \
self._personalizations[substitution.personalization]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
personalization.add_substitution(substitution)
if not has_internal_personalization:
self.add_personalization(
personalization, index=substitution.personalization)
else:
if isinstance(substitution, list):
for s in substitution:
for p in self.personalizations:
p.add_substitution(s)
else:
for p in self.personalizations:
p.add_substitution(substitution)
def dynamic_template_data(self, value):
"""Data for a transactional template
:param value: Data for a transactional template
:type value: DynamicTemplateData, a JSON-serializeable structure
"""
if not isinstance(value, DynamicTemplateData):
value = DynamicTemplateData(value)
try:
personalization = self._personalizations[value.personalization]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
personalization.dynamic_template_data = value.dynamic_template_data
if not has_internal_personalization:
self.add_personalization(
personalization, index=value.personalization)
:param emails: An Email or list of Email objects
:type emails: Email, list(Email)
:param global_substitutions: A dict of substitutions for all recipients
:type global_substitutions: dict
:param is_multiple: Create a new personilization for each recipient
:type is_multiple: bool
:param p: p is the Personalization object or Personalization object
index
:type p: Personalization, integer, optional
"""
# Send multiple emails to multiple recipients
if is_multiple is True:
if isinstance(emails, list):
for email in emails:
personalization = Personalization()
personalization.add_email(email)
self.add_personalization(personalization)
else:
personalization = Personalization()
personalization.add_email(emails)
self.add_personalization(personalization)
if global_substitutions is not None:
if isinstance(global_substitutions, list):
for substitution in global_substitutions:
for p in self.personalizations:
p.add_substitution(substitution)
else:
for p in self.personalizations:
p.add_substitution(global_substitutions)
else:
try:
def add_header(self, header):
"""Add headers to the email globaly or to a specific Personalization
:param value: A Header object or a dict of header key/values
:type value: Header, dict
"""
if header.personalization is not None:
try:
personalization = \
self._personalizations[header.personalization]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
if isinstance(header, dict):
(k, v) = list(header.items())[0]
personalization.add_header(Header(k, v))
else:
personalization.add_header(header)
if not has_internal_personalization:
self.add_personalization(
personalization,
index=header.personalization)
else:
if isinstance(header, dict):
(k, v) = list(header.items())[0]
self._headers = self._ensure_append(
Header(k, v), self._headers)
personalization.add_email(emails)
self.add_personalization(personalization)
if global_substitutions is not None:
if isinstance(global_substitutions, list):
for substitution in global_substitutions:
for p in self.personalizations:
p.add_substitution(substitution)
else:
for p in self.personalizations:
p.add_substitution(global_substitutions)
else:
try:
personalization = self._personalizations[p]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
if isinstance(emails, list):
for email in emails:
personalization.add_email(email)
else:
personalization.add_email(emails)
if global_substitutions is not None:
if isinstance(global_substitutions, list):
for substitution in global_substitutions:
personalization.add_substitution(substitution)
else:
personalization.add_substitution(global_substitutions)
if not has_internal_personalization:
:type global_substitutions: dict
:param is_multiple: Create a new personilization for each recipient
:type is_multiple: bool
:param p: p is the Personalization object or Personalization object
index
:type p: Personalization, integer, optional
"""
# Send multiple emails to multiple recipients
if is_multiple is True:
if isinstance(emails, list):
for email in emails:
personalization = Personalization()
personalization.add_email(email)
self.add_personalization(personalization)
else:
personalization = Personalization()
personalization.add_email(emails)
self.add_personalization(personalization)
if global_substitutions is not None:
if isinstance(global_substitutions, list):
for substitution in global_substitutions:
for p in self.personalizations:
p.add_substitution(substitution)
else:
for p in self.personalizations:
p.add_substitution(global_substitutions)
else:
try:
personalization = self._personalizations[p]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
def subject(self, value):
"""The subject of the email(s)
:param value: The subject of the email(s)
:type value: Subject, string
"""
if isinstance(value, Subject):
if value.personalization is not None:
try:
personalization = \
self._personalizations[value.personalization]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
personalization.subject = value.subject
if not has_internal_personalization:
self.add_personalization(
personalization,
index=value.personalization)
else:
self._subject = value
else:
self._subject = Subject(value)
def add_custom_arg(self, custom_arg):
"""Add custom args to the email globaly or to a specific Personalization
:param value: A CustomArg object or a dict of custom arg key/values
:type value: CustomArg, dict
"""
if custom_arg.personalization is not None:
try:
personalization = \
self._personalizations[custom_arg.personalization]
has_internal_personalization = True
except IndexError:
personalization = Personalization()
has_internal_personalization = False
if isinstance(custom_arg, dict):
(k, v) = list(custom_arg.items())[0]
personalization.add_custom_arg(CustomArg(k, v))
else:
personalization.add_custom_arg(custom_arg)
if not has_internal_personalization:
self.add_personalization(
personalization, index=custom_arg.personalization)
else:
if isinstance(custom_arg, dict):
(k, v) = list(custom_arg.items())[0]
self._custom_args = self._ensure_append(
CustomArg(k, v), self._custom_args)
else: