Skip to content
Closed
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
27 changes: 15 additions & 12 deletions smtpapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,37 @@ def add_substitution(self, key, value):
def set_substitutions(self, subs):
self.data['sub'] = subs


def add_attr(self, key, value, attr):
if attr not in self.data:
self.data[attr] = {}
self.data[attr][key] = value
Copy link

Choose a reason for hiding this comment

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

Maybe use EAFP instead of LBYL?

try:
    self.data[attr][key] = value
except KeyError:
    self.data[attr] = {key: value}


def add_unique_arg(self, key, value):
if 'unique_args' not in self.data:
self.data['unique_args'] = {}
self.data['unique_args'][key] = value
add_attr(self, key, value, 'unique_args')

def set_unique_args(self, value):
self.data['unique_args'] = value

def append_attr(self, value, attr):
if attr not in self.data:
self.data[attr] = []
self.data[attr].append(value)
Copy link

Choose a reason for hiding this comment

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

EAFP over LBYL?

try:
    self.data[attr].append(value)
except KeyError:
    self.data[attr] = [value]


def add_category(self, category):
if 'category' not in self.data:
self.data['category'] = []
self.data['category'].append(category)
append_attr(self, category, 'category')
Copy link

Choose a reason for hiding this comment

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

Is there some advantage to calling the method in the above manner instead of like this?

self.append_attr(category, 'category')


def set_categories(self, category):
self.data['category'] = category

def add_section(self, key, section):
if 'section' not in self.data:
self.data['section'] = {}
self.data['section'][key] = section
add_attr(self, key, section, 'section')
Copy link

Choose a reason for hiding this comment

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

self.add_attr(key, section, 'section')  # ?


def set_sections(self, value):
self.data['section'] = value

def add_send_each_at(self, time):
if 'send_each_at' not in self.data:
self.data['send_each_at'] = []
self.data['send_each_at'].append(time)
append_attr(self, time, 'send_each_at')

def set_send_each_at(self, time):
self.data['send_each_at'] = time
Expand Down