From d4ad82d3e3715d3d1e59ae92ffe52d5e5ec5906a Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Mon, 23 Oct 2017 08:49:10 +0200 Subject: [PATCH 1/3] Provide utf-8 as encoding explicitly when opening text files --- register.py | 7 ++++--- sendgrid/helpers/inbound/send.py | 3 ++- setup.py | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/register.py b/register.py index f7c0b9be0..4eb612387 100644 --- a/register.py +++ b/register.py @@ -1,10 +1,11 @@ import pypandoc +import io output = pypandoc.convert('README.md', 'rst') with open('README.txt' 'w+') as f: f.write(str(output.encode('utf-8'))) -readme_rst = open('./README.txt').read() +readme_rst = io.open('./README.txt', 'r', encoding='utf-8').read() replace = ''' .. figure:: https://uiux.s3.amazonaws.com/2016-logos/email-logo %402x.png\n :alt: SendGrid Logo\n\n SendGrid Logo\n @@ -15,5 +16,5 @@ \n :target: https://www.sendgrid.com ''' final_text = readme_rst.replace(replace, replacement) -with open('./README.txt', 'w') as f: - f.write(final_text) +with io.open('./README.txt', 'w', encoding='utf-8') as f: + f.write(final_text) diff --git a/sendgrid/helpers/inbound/send.py b/sendgrid/helpers/inbound/send.py index d786f678a..a7bbe01b8 100644 --- a/sendgrid/helpers/inbound/send.py +++ b/sendgrid/helpers/inbound/send.py @@ -2,6 +2,7 @@ Usage: ./send.py [path to file containing test data]""" import argparse import sys +import io try: from config import Config except ImportError: @@ -26,7 +27,7 @@ def test_payload(self, payload_filepath): "Content-Type": "multipart/form-data; boundary=xYzZY" } client = Client(host=self.url, request_headers=headers) - f = open(payload_filepath, 'r') + f = io.open(payload_filepath, 'r', encoding='utf-8') data = f.read() return client.post(request_body=data) diff --git a/setup.py b/setup.py index f95e4ee40..8826acb0c 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ import sys import os +import io from setuptools import setup, find_packages __version__ = None @@ -8,7 +9,7 @@ long_description = 'Please see our GitHub README' if os.path.exists('README.txt'): - long_description = open('README.txt').read() + long_description = io.open('README.txt', 'r', encoding='utf-8').read() def getRequires(): From 7dcccec86ba6551ac163cb4d33a407f03b477dee Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Tue, 31 Oct 2017 19:26:49 +0100 Subject: [PATCH 2/3] Fix ASM unit test (also use setter in constructor) --- sendgrid/helpers/mail/asm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sendgrid/helpers/mail/asm.py b/sendgrid/helpers/mail/asm.py index 59e49eee5..333f3e98c 100644 --- a/sendgrid/helpers/mail/asm.py +++ b/sendgrid/helpers/mail/asm.py @@ -13,10 +13,10 @@ def __init__(self, group_id=None, groups_to_display=None): self._groups_to_display = None if group_id is not None: - self._group_id = group_id + self.group_id = group_id if groups_to_display is not None: - self._groups_to_display = groups_to_display + self.groups_to_display = groups_to_display @property def group_id(self): From d6d83b5e1cf9be3a9128f33b6ea2bd171daff4b3 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Wed, 1 Nov 2017 09:52:36 +0100 Subject: [PATCH 3/3] Change io.open to open, since regular open in Python 3 already supports encoding --- register.py | 6 +++--- sendgrid/helpers/inbound/send.py | 4 ++-- setup.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/register.py b/register.py index 4eb612387..b71341a34 100644 --- a/register.py +++ b/register.py @@ -1,11 +1,11 @@ import pypandoc -import io +from io import open output = pypandoc.convert('README.md', 'rst') with open('README.txt' 'w+') as f: f.write(str(output.encode('utf-8'))) -readme_rst = io.open('./README.txt', 'r', encoding='utf-8').read() +readme_rst = open('./README.txt', 'r', encoding='utf-8').read() replace = ''' .. figure:: https://uiux.s3.amazonaws.com/2016-logos/email-logo %402x.png\n :alt: SendGrid Logo\n\n SendGrid Logo\n @@ -16,5 +16,5 @@ \n :target: https://www.sendgrid.com ''' final_text = readme_rst.replace(replace, replacement) -with io.open('./README.txt', 'w', encoding='utf-8') as f: +with open('./README.txt', 'w', encoding='utf-8') as f: f.write(final_text) diff --git a/sendgrid/helpers/inbound/send.py b/sendgrid/helpers/inbound/send.py index a7bbe01b8..053764cbb 100644 --- a/sendgrid/helpers/inbound/send.py +++ b/sendgrid/helpers/inbound/send.py @@ -2,7 +2,7 @@ Usage: ./send.py [path to file containing test data]""" import argparse import sys -import io +from io import open try: from config import Config except ImportError: @@ -27,7 +27,7 @@ def test_payload(self, payload_filepath): "Content-Type": "multipart/form-data; boundary=xYzZY" } client = Client(host=self.url, request_headers=headers) - f = io.open(payload_filepath, 'r', encoding='utf-8') + f = open(payload_filepath, 'r', encoding='utf-8') data = f.read() return client.post(request_body=data) diff --git a/setup.py b/setup.py index 8826acb0c..014691b61 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import sys import os -import io +from io import open from setuptools import setup, find_packages __version__ = None @@ -9,7 +9,7 @@ long_description = 'Please see our GitHub README' if os.path.exists('README.txt'): - long_description = io.open('README.txt', 'r', encoding='utf-8').read() + long_description = open('README.txt', 'r', encoding='utf-8').read() def getRequires():