diff --git a/dotenv/main.py b/dotenv/main.py index ba74cb63..69521d70 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('\$\{[^\}]*\}') @@ -96,7 +97,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,12 +140,12 @@ 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: _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 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 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",