Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python style fixes #484

Merged
merged 5 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions sendgrid/helpers/mail/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ def __init__(self, group_id=None, groups_to_display=None):
:param groups_to_display: Unsubscribe groups to display
:type groups_to_display: list(int), optional
"""
self._group_id = None
self._groups_to_display = None

if group_id is not None:
self._group_id = group_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Shouldn't this...
self._group_id = group_id

# be this?
self.group_id = group_id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch - will fix typo in next commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrielkrell ,

I'm not sure how you are going to do this since you deleted this code already...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot - I thought that my replacement code had the typo, not the original. Github's not too great on mobile but I'll poke at it soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so with this and the other changes I kept the typo - my new code should use the setter and not assign directly to the private variables. Oops!


if groups_to_display is not None:
self._groups_to_display = groups_to_display
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Shouldn't this...
self._groups_to_display = groups_to_display

# be this?
self.groups_to_display = groups_to_display

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix in next push.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrielkrell ,

You deleted this code already too...

self.group_id = group_id
self.groups_to_display = groups_to_display

@property
def group_id(self):
Expand Down
10 changes: 2 additions & 8 deletions sendgrid/helpers/mail/bcc_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ def __init__(self, enable=None, email=None):
:param email: Who should be BCCed.
:type email: Email, optional
"""
self._enable = None
self._email = None

if enable is not None:
self.enable = enable

if email is not None:
self.email = email
self.enable = enable
self.email = email

@property
def enable(self):
Expand Down
5 changes: 1 addition & 4 deletions sendgrid/helpers/mail/bypass_list_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def __init__(self, enable=None):
:param enable: Whether emails should bypass list management.
:type enable: boolean, optional
"""
self._enable = None

if enable is not None:
self.enable = enable
self.enable = enable

@property
def enable(self):
Expand Down
4 changes: 1 addition & 3 deletions sendgrid/helpers/mail/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def __init__(self, name=None):
:param name: The name of this category
:type name: string, optional
"""
self._name = None
if name is not None:
self._name = name
self.name = name

@property
def name(self):
Expand Down
10 changes: 2 additions & 8 deletions sendgrid/helpers/mail/click_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ def __init__(self, enable=None, enable_text=None):
:param enable_text: If click tracking is on in your email's text/plain.
:type enable_text: boolean, optional
"""
self._enable = None
self._enable_text = None

if enable is not None:
self.enable = enable

if enable_text is not None:
self.enable_text = enable_text
self.enable = enable
self.enable_text = enable_text

@property
def enable(self):
Expand Down
10 changes: 2 additions & 8 deletions sendgrid/helpers/mail/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@ def __init__(self, type_=None, value=None):
:param value: The actual content.
:type value: string, optional
"""
self._type = None
self._value = None

if type_ is not None:
self.type = type_

if value is not None:
self.value = value
self.type = type_
self.value = value

@property
def type(self):
Expand Down
10 changes: 2 additions & 8 deletions sendgrid/helpers/mail/custom_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ class CustomArg(object):

def __init__(self, key=None, value=None):
"""Create a CustomArg with the given key and value."""
self._key = None
self._value = None

if key is not None:
self.key = key

if value is not None:
self.value = value
self.key = key
self.value = value

@property
def key(self):
Expand Down
29 changes: 13 additions & 16 deletions sendgrid/helpers/mail/email.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
try:
import rfc822
except ImportError:
import email.utils as rfc822


class Email(object):
"""An email address with an optional name."""

Expand All @@ -11,17 +17,13 @@ def __init__(self, email=None, name=None):
:param name: Name for this sender or recipient.
:type name: string
"""
self._name = None
self._email = None
if name or email:
if not name:
# allows passing emails as "dude Fella <[email protected]>"
self.parse_email(email)
else:
# allows backwards compatibility for Email(email, name)
if email is not None:
self.email = email
self.name = name
if email and not name:
# allows passing emails as "dude Fella <[email protected]>"
self.parse_email(email)
else:
# allows backwards compatibility for Email(email, name)
self.email = email
self.name = name

@property
def name(self):
Expand Down Expand Up @@ -65,11 +67,6 @@ def get(self):
return email

def parse_email(self, email_info):
try:
import rfc822
except ImportError:
import email.utils as rfc822

name, email = rfc822.parseaddr(email_info)

# more than likely a string was passed here instead of an email address
Expand Down
15 changes: 3 additions & 12 deletions sendgrid/helpers/mail/footer_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ def __init__(self, enable=None, text=None, html=None):
:param html: HTML content of this footer
:type html: string, optional
"""
self._enable = None
self._text = None
self._html = None

if enable is not None:
self.enable = enable

if text is not None:
self.text = text

if html is not None:
self.html = html
self.enable = enable
self.text = text
self.html = html

@property
def enable(self):
Expand Down
25 changes: 6 additions & 19 deletions sendgrid/helpers/mail/ganalytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,12 @@ def __init__(self,
:param utm_campaign: The name of the campaign.
:type utm_campaign: string, optional
"""
self._enable = None
self._utm_source = None
self._utm_medium = None
self._utm_term = None
self._utm_content = None
self._utm_campaign = None

if enable is not None:
self.enable = enable
if utm_source is not None:
self.utm_source = utm_source
if utm_medium is not None:
self.utm_medium = utm_medium
if utm_term is not None:
self.utm_term = utm_term
if utm_content is not None:
self.utm_content = utm_content
if utm_campaign is not None:
self.utm_campaign = utm_campaign
self.enable = enable
self.utm_source = utm_source
self.utm_medium = utm_medium
self.utm_term = utm_term
self.utm_content = utm_content
self.utm_campaign = utm_campaign

@property
def enable(self):
Expand Down
9 changes: 2 additions & 7 deletions sendgrid/helpers/mail/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ def __init__(self, key=None, value=None):
:param value: The header's value (e.g. "2013-02-27 1:23:45 PM PDT")
:type value: string, optional
"""
self._key = None
self._value = None

if key is not None:
self.key = key
if value is not None:
self.value = value
self.key = key
self.value = value

@property
def key(self):
Expand Down
42 changes: 14 additions & 28 deletions sendgrid/helpers/mail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __init__(
self._mail_settings = None
self._tracking_settings = None
self._reply_to = None
self._personalizations = None
self._contents = None
self._attachments = None
self._sections = None
self._headers = None
self._categories = None
self._custom_args = None
self._personalizations = []
self._contents = []
self._attachments = []
self._sections = []
self._headers = []
self._categories = []
self._custom_args = []

# Minimum required to send an email
if from_email and subject and to_email and content:
Expand Down Expand Up @@ -67,38 +67,38 @@ def get(self):
if self.subject is not None:
mail["subject"] = self.subject

if self.personalizations is not None:
if self.personalizations:
mail["personalizations"] = [
personalization.get()
for personalization in self.personalizations
]

if self.contents is not None:
if self.contents:
mail["content"] = [ob.get() for ob in self.contents]

if self.attachments is not None:
if self.attachments:
mail["attachments"] = [ob.get() for ob in self.attachments]

if self.template_id is not None:
mail["template_id"] = self.template_id

if self.sections is not None:
if self.sections:
sections = {}
for key in self.sections:
sections.update(key.get())
mail["sections"] = sections

if self.headers is not None:
if self.headers:
headers = {}
for key in self.headers:
headers.update(key.get())
mail["headers"] = headers

if self.categories is not None:
if self.categories:
mail["categories"] = [category.get() for category in
self.categories]

if self.custom_args is not None:
if self.custom_args:
custom_args = {}
for key in self.custom_args:
custom_args.update(key.get())
Expand Down Expand Up @@ -277,8 +277,6 @@ def add_personalization(self, personalizations):

:type personalizations: Personalization
"""
if self._personalizations is None:
self._personalizations = []
self._personalizations.append(personalizations)

@property
Expand All @@ -295,8 +293,6 @@ def add_content(self, content):

:type content: Content
"""
if self._contents is None:
self._contents = []
self._contents.append(content)

@property
Expand All @@ -313,8 +309,6 @@ def add_attachment(self, attachment):

:type attachment: Attachment
"""
if self._attachments is None:
self._attachments = []
self._attachments.append(attachment)

@property
Expand All @@ -331,8 +325,6 @@ def add_section(self, section):

:type attachment: Section
"""
if self._sections is None:
self._sections = []
self._sections.append(section)

@property
Expand All @@ -351,8 +343,6 @@ def add_header(self, header):
key-value pair.
:type header: object
"""
if self._headers is None:
self._headers = []
if isinstance(header, dict):
(k, v) = list(header.items())[0]
self._headers.append(Header(k, v))
Expand All @@ -372,8 +362,6 @@ def add_category(self, category):

:type category: string
"""
if self._categories is None:
self._categories = []
self._categories.append(category)

@property
Expand All @@ -390,6 +378,4 @@ def add_custom_arg(self, custom_arg):

:type custom_arg: CustomArg
"""
if self._custom_args is None:
self._custom_args = []
self._custom_args.append(custom_arg)
9 changes: 2 additions & 7 deletions sendgrid/helpers/mail/open_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ def __init__(self, enable=None, substitution_tag=None):
:param substitution_tag: Tag in body to be replaced by tracking pixel.
:type substitution_tag: string, optional
"""
self._enable = None
self._substitution_tag = None

if enable is not None:
self.enable = enable
if substitution_tag is not None:
self.substitution_tag = substitution_tag
self.enable = enable
self.substitution_tag = substitution_tag

@property
def enable(self):
Expand Down
Loading