Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open dotenv_path with UTF-8 encoding #75

Closed
wants to merge 4 commits into from
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
7 changes: 4 additions & 3 deletions dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('\$\{[^\}]*\}')
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flake8>=2.2.3
pytest>=3.0.5
pytest>=3.2
sh>=1.09
bumpversion
wheel
Expand Down
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down