Skip to content

Commit

Permalink
Refractor: move 'to_env' to compat.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh Kumar committed May 22, 2019
1 parent 57f9639 commit 0681a87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
21 changes: 16 additions & 5 deletions src/dotenv/compat.py
@@ -1,12 +1,23 @@
import sys
from typing import Text
from typing import Text # noqa

if sys.version_info >= (3, 0):
from io import StringIO # noqa
else:
PY2 = sys.version_info[0] == 2 # type: bool

if PY2:
from StringIO import StringIO # noqa
else:
from io import StringIO # noqa

PY2 = sys.version_info[0] == 2 # type: bool

def to_env(text):
# type: (Text) -> str
"""
Encode a string the same way whether it comes from the environment or a `.env` file.
"""
if PY2:
return text.encode(sys.getfilesystemencoding() or "utf-8")
else:
return text


def to_text(string):
Expand Down
13 changes: 1 addition & 12 deletions src/dotenv/main.py
Expand Up @@ -14,7 +14,7 @@
from collections import OrderedDict
from contextlib import contextmanager

from .compat import StringIO, PY2
from .compat import StringIO, PY2, to_env
from .parser import parse_stream

if TYPE_CHECKING: # pragma: no cover
Expand All @@ -31,17 +31,6 @@
__posix_variable = re.compile(r'\$\{[^\}]*\}') # type: Pattern[Text]


def to_env(text):
# type: (Text) -> str
"""
Encode a string the same way whether it comes from the environment or a `.env` file.
"""
if PY2:
return text.encode(sys.getfilesystemencoding() or "utf-8")
else:
return text


class DotEnv():

def __init__(self, dotenv_path, verbose=False, encoding=None):
Expand Down

0 comments on commit 0681a87

Please sign in to comment.