Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

load transports on demand

  • Loading branch information...
commit d8d0a0cbd2a0fed8a9ffc0ccb534fb4a16f4bcea 1 parent 6a533e7
Vyacheslav Kim (Kane) Kane-Sendgrid authored

Showing 1 changed file with 33 additions and 4 deletions. Show diff stats Hide diff stats

  1. +33 4 sendgrid/sendgrid.py
37 sendgrid/sendgrid.py
... ... @@ -1,10 +1,19 @@
1   -from transport import smtp, web
  1 +def memoize(f):
  2 + """
  3 + Memoization decorator
  4 + """
  5 + cache= {}
  6 + def func(*args):
  7 + if args not in cache:
  8 + cache[args] = f(*args)
  9 + return cache[args]
  10 + return func
  11 +
2 12
3 13 class Sendgrid(object):
4 14 """
5 15 Sendgrid API
6 16 """
7   -
8 17 def __init__(self, username, password, secure=True):
9 18 """
10 19 Construct Sendgrid API object
@@ -14,6 +23,26 @@ def __init__(self, username, password, secure=True):
14 23 password: Sendgrid password
15 24 ssl: Use SSL
16 25 """
  26 + self.username = username
  27 + self.password = password
  28 + self.secure = secure
  29 +
17 30
18   - self.web = web.Http(username, password, secure)
19   - self.smtp = smtp.Smtp(username, password, secure)
  31 + @property
  32 + @memoize
  33 + def web(self):
  34 + """
  35 + Return web transport
  36 + """
  37 + from transport import web
  38 + return web.Http(self.username, self.password, self.secure)
  39 +
  40 +
  41 + @property
  42 + @memoize
  43 + def smtp(self):
  44 + """
  45 + Return smtp transport
  46 + """
  47 + from transport import smtp
  48 + return smtp.Smtp(self.username, self.password, self.secure)

0 comments on commit d8d0a0c

Please sign in to comment.
Something went wrong with that request. Please try again.