diff --git a/LICENSE.md b/LICENSE.md index 29aba59..35244b0 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,13 +1,13 @@ -MIT License +The MIT License (MIT) Copyright (C) 2020, Twilio SendGrid, Inc. -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. diff --git a/smtpapi/__init__.py b/smtpapi/__init__.py index 13306e6..1ed55a7 100644 --- a/smtpapi/__init__.py +++ b/smtpapi/__init__.py @@ -1,10 +1,5 @@ -import decimal import json -import os - -dir_path = os.path.dirname(os.path.realpath(__file__)) -if os.path.isfile(os.path.join(dir_path, 'VERSION.txt')): - __version__ = open(os.path.join(dir_path, 'VERSION.txt')).read().strip() +import decimal class _CustomJSONEncoder(json.JSONEncoder): @@ -12,7 +7,8 @@ class _CustomJSONEncoder(json.JSONEncoder): def default(self, o): if isinstance(o, decimal.Decimal): return float(o) - # Provide a fallback to the default encoder if we haven't implemented special support for the object's class + # Provide a fallback to the default encoder if we haven't implemented + # special support for the object's class return super(_CustomJSONEncoder, self).default(o) @@ -42,34 +38,36 @@ def add_substitution(self, key, value): def set_substitutions(self, subs): self.data['sub'] = subs + def _add_key_value(self, index, key, value): + if index not in self.data: + self.data[index] = {} + self.data[index][key] = value + + def _add_key(self, index, key): + if index not in self.data: + self.data[index] = [] + self.data[index].append(key) + def add_unique_arg(self, key, value): - if 'unique_args' not in self.data: - self.data['unique_args'] = {} - self.data['unique_args'][key] = value + self._add_key_value('unique_args', key, value) def set_unique_args(self, value): self.data['unique_args'] = value def add_category(self, category): - if 'category' not in self.data: - self.data['category'] = [] - self.data['category'].append(category) + self._add_key('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 + self._add_key_value('section', key, 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) + self._add_key('send_each_at', time) def set_send_each_at(self, time): self.data['send_each_at'] = time