Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: python
sudo: false
cache: pip
python:
- '2.6'
- '2.7'
- '3.4'
- '3.5'
Expand All @@ -11,7 +10,6 @@ env:
global:
- CC_TEST_REPORTER_ID=$TRAVIS_CODE_CLIMATE_TOKEN
install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.6* ]]; then pip install unittest2; fi
- python setup.py install
- pip install pyyaml
- pip install flask
Expand All @@ -30,7 +28,7 @@ before_script:
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then coverage run -m unittest2 discover; else coverage run -m unittest discover; fi
- coverage run -m unittest discover
after_script:
- codecov
- ./cc-test-reporter after-build --exit-code $?
Expand Down
11 changes: 2 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ You can use our Docker image to avoid setting up the development environment you

##### Prerequisites #####

- Python 2.6 through 3.6
- Python 2.7 and 3.4+
- [python_http_client](https://github.com/sendgrid/python-http-client)

##### Initial setup: #####
Expand Down Expand Up @@ -122,12 +122,6 @@ All test files are in the [`test`](https://github.com/sendgrid/sendgrid-python/t

For the purposes of contributing to this repo, please update the [`test_sendgrid.py`](https://github.com/sendgrid/sendgrid-python/tree/master/test/test_sendgrid.py) file with unit tests as you modify the code.

For Python 2.6.*:

`unit2 discover -v`

For Python 2.7.* and up:

`python -m unittest discover -v`

### Testing Multiple Versions of Python
Expand All @@ -149,7 +143,6 @@ You can install it by yourself in user dir by calling `source test/prism.sh`.
Add ```eval "$(pyenv init -)"``` to your shell environment (.profile, .bashrc, etc) after installing tox, you only need to do this once.

```
pyenv install 2.6.9
pyenv install 2.7.11
pyenv install 3.4.3
pyenv install 3.5.0
Expand All @@ -159,7 +152,7 @@ Make sure to change the current working directory to your local version of the r
python setup.py install
```
```
pyenv local 3.5.0 3.4.3 2.7.11 2.6.9
pyenv local 3.5.0 3.4.3 2.7.11
pyenv rehash
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ We appreciate your continued support, thank you!

## Prerequisites

- Python version 2.6, 2.7, 3.4, 3.5 or 3.6
- Python version 2.7 and 3.4+
- The SendGrid service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-python)

## Setup Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM ubuntu:xenial
ENV PYTHON_VERSIONS='python2.6 python2.7 python3.4 python3.5 python3.6' \
ENV PYTHON_VERSIONS='python2.7 python3.4 python3.5 python3.6' \
OAI_SPEC_URL="https://raw.githubusercontent.com/sendgrid/sendgrid-oai/master/oai_stoplight.json"

ARG SENDGRID-PYTHON_VERSION
Expand Down
1 change: 0 additions & 1 deletion examples/accesssettings/accesssettings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/alerts/alerts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/apikeys/apikeys.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/asm/asm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/browsers/browsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/campaigns/campaigns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/categories/categories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/clients/clients.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/contactdb/contactdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/devices/devices.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/geo/geo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
2 changes: 1 addition & 1 deletion examples/helpers/mail_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def send_kitchen_sink():
def transactional_template_usage():
# Assumes you set your environment variable:
# https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key

"""
Sample usage of dynamic (handlebars) transactional templates.
To make this work, you should have dynamic template created within your
Expand Down
4 changes: 3 additions & 1 deletion examples/helpers/stats/stats_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ def build_category_stats_sums():


def build_subuser_stats():
subuser_stats = SubuserStats('2017-10-20', ['aaronmakks','foo'])
subuser_stats = SubuserStats('2017-10-20', ['aaronmakks', 'foo'])
# subuser_stats.start_date = '2017-10-15'
# subuser_stats.add_subuser(Subuser("foo"))
# subuser_stats.add_subuser(Subuser("bar"))
return subuser_stats.get()


def build_subuser_stats_sums():
subuser_stats = SubuserStats()
subuser_stats.start_date = '2017-10-15'
Expand Down Expand Up @@ -92,6 +93,7 @@ def get_subuser_stats_sums():
print(response.headers)
pprint_json(response.body)


get_global_stats()
get_category_stats()
get_category_stats_sums()
Expand Down
1 change: 0 additions & 1 deletion examples/ips/ips.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/mail/mail.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/mailboxproviders/mailboxproviders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/mailsettings/mailsettings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/partnersettings/partnersettings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/scopes/scopes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/senders/senders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/stats/stats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/subusers/subusers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/suppression/suppression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/templates/templates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/trackingsettings/trackingsettings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/user/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
1 change: 0 additions & 1 deletion examples/whitelabel/whitelabel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sendgrid
import json
import os


Expand Down
2 changes: 1 addition & 1 deletion register.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
'''
final_text = readme_rst.replace(replace, replacement)
with open('./README.txt', 'w', encoding='utf-8') as f:
f.write(final_text)
f.write(final_text)
4 changes: 2 additions & 2 deletions sendgrid/helpers/endpoints/ip/unassigned.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def unassigned(data, as_json=False):
unassigned returns a listing of the IP addresses that are allocated
but have 0 users assigned

data (response.body from sg.client.ips.get())

data (response.body from sg.client.ips.get())
as_json False -> get list of dicts
True -> get json object

Expand Down
4 changes: 2 additions & 2 deletions sendgrid/helpers/inbound/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
See README.txt for usage instructions."""
try:
from config import Config
except:
except ImportError:
# Python 3+, Travis
from sendgrid.helpers.inbound.config import Config

try:
from parse import Parse
except:
except ImportError:
# Python 3+, Travis
from sendgrid.helpers.inbound.parse import Parse

Expand Down
5 changes: 4 additions & 1 deletion sendgrid/helpers/inbound/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import sys
from io import open

try:
from config import Config
except ImportError:
Expand Down Expand Up @@ -37,6 +38,7 @@ def url(self):
"""URL to send to."""
return self._url


def main():
config = Config()
parser = argparse.ArgumentParser(description='Test data and optional host.')
Expand All @@ -54,5 +56,6 @@ def main():
print(response.headers)
print(response.body)


if __name__ == '__main__':
main()
main()
1 change: 1 addition & 0 deletions sendgrid/helpers/mail/content.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .validators import ValidateAPIKey


class Content(object):
"""Content to be included in your email.

Expand Down
6 changes: 3 additions & 3 deletions sendgrid/helpers/mail/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Various types of extensible SendGrid related exceptions
################################################################


class SendGridException(Exception):
"""Wrapper/default SendGrid-related exception"""
pass
Expand All @@ -14,9 +15,8 @@ class APIKeyIncludedException(SendGridException):
message -- explanation of the error
"""

def __init__(self,
expression="Email body",
def __init__(self,
expression="Email body",
message="SendGrid API Key detected"):
self.expression = expression
self.message = message

10 changes: 4 additions & 6 deletions sendgrid/helpers/mail/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Various types of Validators
################################################################


class ValidateAPIKey(object):
"""Validates content to ensure SendGrid API key is not present"""

Expand All @@ -27,9 +28,8 @@ def __init__(self, regex_strings=None, use_default=True):
default_regex_string = 'SG\.[0-9a-zA-Z]+\.[0-9a-zA-Z]+'
self.regexes.add(re.compile(default_regex_string))


def validate_message_dict(self, request_body):
"""With the JSON dict that will be sent to SendGrid's API,
"""With the JSON dict that will be sent to SendGrid's API,
check the content for SendGrid API keys - throw exception if found
Args:
request_body (:obj:`dict`): message parameter that is
Expand All @@ -44,17 +44,16 @@ def validate_message_dict(self, request_body):

# Default param
elif isinstance(request_body, dict):

contents = request_body.get("content", list())

for content in contents:
if content is not None:
if (content.get("type") == "text/html" or
isinstance(content.get("value"), str)):
message_text = content.get("value", "")
self.validate_message_text(message_text)


def validate_message_text(self, message_string):
"""With a message string, check to see if it contains a SendGrid API Key
If a key is found, throw an exception
Expand All @@ -68,4 +67,3 @@ def validate_message_text(self, message_string):
for regex in self.regexes:
if regex.match(message_string) is not None:
raise APIKeyIncludedException()

Loading