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 3 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
@@ -1,14 +1,8 @@
class ASM(object):

def __init__(self, group_id=None, groups_to_display=None):
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
@@ -1,14 +1,8 @@
class BCCSettings(object):

def __init__(self, enable=None, email=None):
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
@@ -1,10 +1,7 @@
class BypassListManagement(object):

def __init__(self, enable=None):
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
@@ -1,9 +1,7 @@
class Category(object):

def __init__(self, name=None):
self._name = None
if name is not None:
self._name = name
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._name = name

# be this?
self.name = name

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 as well...

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
@@ -1,14 +1,8 @@
class ClickTracking(object):

def __init__(self, enable=None, enable_text=None):
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
@@ -1,14 +1,8 @@
class Content(object):

def __init__(self, type_=None, value=None):
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
@@ -1,14 +1,8 @@
class CustomArg(object):

def __init__(self, key=None, value=None):
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,17 +1,19 @@
try:
import rfc822
except ImportError:
import email.utils as rfc822


class Email(object):

def __init__(self, email=None, name=None):
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 @@ -39,11 +41,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
@@ -1,18 +1,9 @@
class FooterSettings(object):

def __init__(self, enable=None, text=None, html=None):
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 @@ -7,25 +7,12 @@ def __init__(self,
utm_term=None,
utm_content=None,
utm_campaign=None):
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
@@ -1,13 +1,8 @@
class Header(object):

def __init__(self, key=None, value=None):
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 @@ -16,13 +16,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 All @@ -46,38 +46,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 @@ -190,44 +190,34 @@ def personalizations(self):
return self._personalizations

def add_personalization(self, personalizations):
if self._personalizations is None:
self._personalizations = []
self._personalizations.append(personalizations)

@property
def contents(self):
return self._contents

def add_content(self, content):
if self._contents is None:
self._contents = []
self._contents.append(content)

@property
def attachments(self):
return self._attachments

def add_attachment(self, attachment):
if self._attachments is None:
self._attachments = []
self._attachments.append(attachment)

@property
def sections(self):
return self._sections

def add_section(self, section):
if self._sections is None:
self._sections = []
self._sections.append(section)

@property
def headers(self):
return self._headers

def add_header(self, header):
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 @@ -239,15 +229,11 @@ def categories(self):
return self._categories

def add_category(self, category):
if self._categories is None:
self._categories = []
self._categories.append(category)

@property
def custom_args(self):
return self._custom_args

def add_custom_arg(self, custom_arg):
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
@@ -1,13 +1,8 @@
class OpenTracking(object):

def __init__(self, enable=None, substitution_tag=None):
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