Skip to content

Commit

Permalink
Merge pull request #250 from andriisoldatenko/fix-pep8-errors
Browse files Browse the repository at this point in the history
Improve code quality
  • Loading branch information
SendGrid's DX Team authored Mar 29, 2017
2 parents 9086caf + ecc37bb commit beed6e4
Show file tree
Hide file tree
Showing 13 changed files with 1,615 additions and 940 deletions.
8 changes: 4 additions & 4 deletions sendgrid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .version import __version__
#v3 API
from .sendgrid import SendGridAPIClient
from .helpers.mail.mail import Email
from .version import __version__ # noqa
# v3 API
from .sendgrid import SendGridAPIClient # noqa
from .helpers.mail.mail import Email # noqa
4 changes: 2 additions & 2 deletions sendgrid/helpers/inbound/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .config import *
from .parse import *
from .config import * # noqa
from .parse import * # noqa
6 changes: 4 additions & 2 deletions sendgrid/helpers/inbound/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
class Config(object):
"""All configuration for this app is loaded here"""
def __init__(self, **opts):
if (os.environ.get('ENV') != 'prod'): # We are not in Heroku
if os.environ.get('ENV') != 'prod': # We are not in Heroku
self.init_environment()

"""Allow variables assigned in config.yml available the following variables
via properties"""
self.path = opts.get('path', os.path.abspath(os.path.dirname(__file__)))
self.path = opts.get(
'path', os.path.abspath(os.path.dirname(__file__))
)
with open(self.path + '/config.yml') as stream:
config = yaml.load(stream)
self._debug_mode = config['debug_mode']
Expand Down
16 changes: 10 additions & 6 deletions sendgrid/helpers/inbound/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ def __init__(self, config, request):
self._raw_payload = request.data

def key_values(self):
"""Return a dictionary of key/values in the payload received from
the webhook"""
"""
Return a dictionary of key/values in the payload received from
the webhook
"""
key_values = {}
for key in self.keys:
if key in self.payload:
key_values[key] = self.payload[key]
return key_values

def get_raw_email(self):
"""This only applies to raw payloads:
https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Raw-Parameters"""
if 'email' in self.payload:
"""
This only applies to raw payloads:
https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Raw-Parameters
"""
if 'email' in self.payload:
raw_email = email.message_from_string(self.payload['email'])
return raw_email
else:
else:
return None

def attachments(self):
Expand Down
3 changes: 1 addition & 2 deletions sendgrid/helpers/inbound/send.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""A module for sending test SendGrid Inbound Parse messages
Usage: ./send.py [path to file containing test data]"""
import argparse
import os
import sys
try:
from config import Config
except:
except ImportError:
# Python 3+, Travis
from sendgrid.helpers.inbound.config import Config
from python_http_client import Client
Expand Down
2 changes: 1 addition & 1 deletion sendgrid/helpers/mail/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .mail import *
from .mail import * # noqa
Loading

0 comments on commit beed6e4

Please sign in to comment.