diff --git a/sendgrid/__init__.py b/sendgrid/__init__.py index fb743303a..2d4bca1c5 100644 --- a/sendgrid/__init__.py +++ b/sendgrid/__init__.py @@ -1,7 +1,5 @@ -from sendgrid import * -from message import * - -del sendgrid, message +from .sendgrid import * +from .message import * __version__ = "0.1.3" version_info = (0, 1, 3) diff --git a/sendgrid/message.py b/sendgrid/message.py index 8ef483a4a..67c49c758 100644 --- a/sendgrid/message.py +++ b/sendgrid/message.py @@ -1,5 +1,5 @@ -import rfc822 -from header import SmtpApiHeader +import email.utils as email_utils +from . header import SmtpApiHeader class Message(object): @@ -41,7 +41,7 @@ def __init__(self, addr_from, subject, text="", html=""): self.headers = {} self.attachments = [] self.header = SmtpApiHeader() - self.date = rfc822.formatdate() + self.date = email_utils.formatdate() def set_replyto(self, replyto): """ @@ -74,7 +74,7 @@ def add_to(self, recipients, names=None): if not recipients: raise ValueError('No recipients') - if isinstance(recipients, (str, unicode)): + if isinstance(recipients, str): self.to += [recipients] if names: self.to_name += [names] @@ -125,13 +125,13 @@ def add_cc(self, recipients): Returns: self """ - if isinstance(recipients, (str, unicode)): + if isinstance(recipients, str): self.cc += [recipients] else: self.cc += recipients self.header.add_cc(recipients) - + return self def add_bcc(self, recipients): @@ -144,13 +144,13 @@ def add_bcc(self, recipients): Returns: self """ - if isinstance(recipients, (str, unicode)): + if isinstance(recipients, str): self.bcc += [recipients] else: self.bcc += recipients self.header.add_bcc(recipients) - + return self def add_attachment(self, name, file, cid=None): @@ -179,7 +179,7 @@ def add_category(self, category): Returns: self """ - if isinstance(category, (str, unicode)): + if isinstance(category, str): self.header.add_category(category) else: for cat in category: diff --git a/sendgrid/sendgrid.py b/sendgrid/sendgrid.py index 65e572557..3373e0bb9 100644 --- a/sendgrid/sendgrid.py +++ b/sendgrid/sendgrid.py @@ -36,7 +36,7 @@ def web(self): """ Return web transport """ - from transport import web + from . transport import web return web.Http(self.username, self.password, ssl=self.secure, user=self.user) @@ -46,5 +46,5 @@ def smtp(self): """ Return smtp transport """ - from transport import smtp + from . transport import smtp return smtp.Smtp(self.username, self.password, tls=self.secure) diff --git a/sendgrid/transport/web.py b/sendgrid/transport/web.py index 1d543a30d..0126408be 100644 --- a/sendgrid/transport/web.py +++ b/sendgrid/transport/web.py @@ -1,5 +1,5 @@ import urllib -import urllib2 + try: import json except ImportError: @@ -87,18 +87,19 @@ def send(self, message): if optional_params[key]: data[key] = optional_params[key] - data = urllib.urlencode(data, 1) - req = urllib2.Request(url, data) + data = urllib.parse.urlencode(data, 1) + data = data.encode('utf8') + req = urllib.request.Request(url, data) try: - f = urllib2.urlopen(req) + f = urllib.request.urlopen(req) output = f.read() - except IOError, e: + except IOError as e: try: output = e.read() except AttributeError: raise exceptions.SGServiceException(e) - output = json.loads(output) + output = json.loads(output.decode('utf8')) if output['message'] == 'error': raise exceptions.SGServiceException(output['errors'])