Skip to content

Commit 841b68e

Browse files
committed
fix: python 2 compat conf parser
1 parent c90af3b commit 841b68e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

S3/Config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
# In python 3, unicode -> str, and str -> bytes
7474
unicode = str
7575

76+
PY32 = (sys.version_info >= (3, 2))
77+
7678

7779
def is_bool_true(value):
7880
"""Check to see if a string is true, yes, on, or 1
@@ -456,15 +458,23 @@ def aws_credential_file(self):
456458
config_string = fp.read()
457459
try:
458460
try:
459-
config.read_file(io.StringIO(config_string))
461+
buf = io.StringIO(config_string)
462+
if PY32:
463+
config.read_file(buf)
464+
else:
465+
config.readfp(buf)
460466
except MissingSectionHeaderError:
461467
# if header is missing, this could be deprecated
462468
# credentials file format as described here:
463469
# https://blog.csanchez.org/2011/05/
464470
# then do the hacky-hack and add default header
465471
# to be able to read the file with PyConfigParser()
466472
config_string = u'[default]\n' + config_string
467-
config.read_file(io.StringIO(config_string))
473+
buf = io.StringIO(config_string)
474+
if PY32:
475+
config.read_file(buf)
476+
else:
477+
config.readfp(buf)
468478
except ParsingError as exc:
469479
raise ValueError(
470480
"Error reading aws_credential_file "

0 commit comments

Comments
 (0)