Skip to content

Commit 7c25f39

Browse files
Merge #121
1 parent b8c514e commit 7c25f39

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

decouple.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
from distutils.util import strtobool
99

1010
# Useful for very coarse version differentiation.
11-
PY3 = sys.version_info[0] == 3
11+
PYVERSION = sys.version_info
1212

13-
if PY3:
13+
14+
if PYVERSION >= (3, 0, 0):
1415
from configparser import ConfigParser
1516
text_type = str
1617
else:
1718
from ConfigParser import SafeConfigParser as ConfigParser
1819
text_type = unicode
1920

21+
if PYVERSION >= (3, 2, 0):
22+
read_config = lambda parser, file: parser.read_file(file)
23+
else:
24+
read_config = lambda parser, file: parser.readfp(file)
25+
26+
2027
DEFAULT_ENCODING = 'UTF-8'
2128

2229
class UndefinedValueError(Exception):
@@ -103,8 +110,7 @@ class RepositoryIni(RepositoryEmpty):
103110
def __init__(self, source, encoding=DEFAULT_ENCODING):
104111
self.parser = ConfigParser()
105112
with open(source, encoding=encoding) as file_:
106-
config_reader = self.parser.read_file if sys.version_info >= (3, 2, 0) else self.parser.readfp
107-
config_reader(file_)
113+
read_config(self.parser, file_)
108114

109115
def __contains__(self, key):
110116
return (key in os.environ or

tests/test_autoconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import pytest
44
from mock import patch, mock_open
5-
from decouple import AutoConfig, UndefinedValueError, RepositoryEmpty, DEFAULT_ENCODING, PY3
5+
from decouple import AutoConfig, UndefinedValueError, RepositoryEmpty, DEFAULT_ENCODING
66

77

88
def test_autoconfig_env():

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27, py37
2+
envlist = py2, py3
33

44
[testenv]
55
deps =

0 commit comments

Comments
 (0)