From 6a9c34a2b35e01aa114f7898f7efc10c0fb8122a Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 9 Nov 2017 22:42:47 +0900 Subject: [PATCH 1/4] Open dotenv_path with UTF-8 encoding --- dotenv/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotenv/main.py b/dotenv/main.py index ba74cb63..ca5f7b97 100644 --- a/dotenv/main.py +++ b/dotenv/main.py @@ -96,7 +96,7 @@ def dotenv_values(dotenv_path): def parse_dotenv(dotenv_path): - with open(dotenv_path) as f: + with open(dotenv_path, encoding='utf-8') as f: for line in f: line = line.strip() if not line or line.startswith('#') or '=' not in line: @@ -139,7 +139,7 @@ def _re_sub_callback(match_object): def flatten_and_write(dotenv_path, dotenv_as_dict, quote_mode="always"): - with open(dotenv_path, "w") as f: + with open(dotenv_path, "w", encoding='utf-8') as f: for k, v in dotenv_as_dict.items(): _mode = quote_mode if _mode == "auto" and " " in v: From 3dcad6f545cd83779b0e2faefa9633d50eee74b4 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Sat, 11 Nov 2017 20:59:24 +0900 Subject: [PATCH 2/4] Upgrade pytest --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 673cb101..7c4c26b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ flake8>=2.2.3 -pytest>=3.0.5 +pytest>=3.2 sh>=1.09 bumpversion wheel From 2c52614a39f3cb9cd0dda6aa185e00b2fce0cc94 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Sat, 11 Nov 2017 21:04:00 +0900 Subject: [PATCH 3/4] Use io.open for Python 2 --- dotenv/main.py | 1 + setup.py | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dotenv/main.py b/dotenv/main.py index ca5f7b97..4b4bf0a2 100644 --- a/dotenv/main.py +++ b/dotenv/main.py @@ -7,6 +7,7 @@ import warnings import re from collections import OrderedDict +from io import open __escape_decoder = codecs.getdecoder('unicode_escape') __posix_variable = re.compile('\$\{[^\}]*\}') diff --git a/setup.py b/setup.py index fb5ad75d..d0e82f36 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,9 @@ # -*- coding: utf-8 -*- from setuptools import setup +from io import open -# https://github.com/theskumar/python-dotenv/issues/45#issuecomment-277135416 -try: - with open('README.rst') as readme_file: - readme = readme_file.read() -except: - readme = 'Checkout http://github.com/theskumar/python-dotenv for more details.' +with open('README.rst', encoding='utf-8') as readme_file: + readme = readme_file.read() setup( name="python-dotenv", From bb1a28bae51f512fe5972270d25c0b3d26b3971a Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Sat, 11 Nov 2017 22:28:35 +0900 Subject: [PATCH 4/4] Use a Unicode string when writing to files --- dotenv/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotenv/main.py b/dotenv/main.py index 4b4bf0a2..69521d70 100644 --- a/dotenv/main.py +++ b/dotenv/main.py @@ -145,7 +145,7 @@ def flatten_and_write(dotenv_path, dotenv_as_dict, quote_mode="always"): _mode = quote_mode if _mode == "auto" and " " in v: _mode = "always" - str_format = '%s="%s"\n' if _mode == "always" else '%s=%s\n' + str_format = u'%s="%s"\n' if _mode == "always" else u'%s=%s\n' f.write(str_format % (k, v)) return True