Skip to content

Commit

Permalink
Merge #121
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquebastos committed Sep 27, 2021
1 parent b8c514e commit 7c25f39
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions decouple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
from distutils.util import strtobool

# Useful for very coarse version differentiation.
PY3 = sys.version_info[0] == 3
PYVERSION = sys.version_info

if PY3:

if PYVERSION >= (3, 0, 0):
from configparser import ConfigParser
text_type = str
else:
from ConfigParser import SafeConfigParser as ConfigParser
text_type = unicode

if PYVERSION >= (3, 2, 0):
read_config = lambda parser, file: parser.read_file(file)
else:
read_config = lambda parser, file: parser.readfp(file)


DEFAULT_ENCODING = 'UTF-8'

class UndefinedValueError(Exception):
Expand Down Expand Up @@ -103,8 +110,7 @@ class RepositoryIni(RepositoryEmpty):
def __init__(self, source, encoding=DEFAULT_ENCODING):
self.parser = ConfigParser()
with open(source, encoding=encoding) as file_:
config_reader = self.parser.read_file if sys.version_info >= (3, 2, 0) else self.parser.readfp
config_reader(file_)
read_config(self.parser, file_)

def __contains__(self, key):
return (key in os.environ or
Expand Down
2 changes: 1 addition & 1 deletion tests/test_autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import pytest
from mock import patch, mock_open
from decouple import AutoConfig, UndefinedValueError, RepositoryEmpty, DEFAULT_ENCODING, PY3
from decouple import AutoConfig, UndefinedValueError, RepositoryEmpty, DEFAULT_ENCODING


def test_autoconfig_env():
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27, py37
envlist = py2, py3

[testenv]
deps =
Expand Down

0 comments on commit 7c25f39

Please sign in to comment.