73
73
# In python 3, unicode -> str, and str -> bytes
74
74
unicode = str
75
75
76
+ PY3 = (sys .version_info >= (3 , 0 ))
77
+
76
78
77
79
def is_bool_true (value ):
78
80
"""Check to see if a string is true, yes, on, or 1
@@ -268,7 +270,7 @@ def __init__(self, configfile = None, access_key=None, secret_key=None, access_t
268
270
try :
269
271
self .read_config_file (configfile )
270
272
except IOError :
271
- if 'AWS_CREDENTIAL_FILE' in os .environ or 'AWS_PROFILE' in os .environ :
273
+ if 'AWS_SHARED_CREDENTIALS_FILE' in os . environ or ' AWS_CREDENTIAL_FILE' in os .environ or 'AWS_PROFILE' in os .environ :
272
274
self .aws_credential_file ()
273
275
274
276
# override these if passed on the command-line
@@ -440,7 +442,8 @@ def role_refresh(self):
440
442
def aws_credential_file (self ):
441
443
try :
442
444
aws_credential_file = os .path .expanduser ('~/.aws/credentials' )
443
- credential_file_from_env = os .environ .get ('AWS_CREDENTIAL_FILE' )
445
+ credential_file_from_env = os .environ .get ('AWS_SHARED_CREDENTIALS_FILE' ) \
446
+ or os .environ .get ('AWS_CREDENTIAL_FILE' )
444
447
if credential_file_from_env and \
445
448
os .path .isfile (credential_file_from_env ):
446
449
aws_credential_file = base_unicodise (credential_file_from_env )
@@ -455,17 +458,23 @@ def aws_credential_file(self):
455
458
config_string = fp .read ()
456
459
try :
457
460
try :
458
- # readfp is replaced by read_file in python3,
459
- # but so far readfp it is still available.
460
- config .readfp (io .StringIO (config_string ))
461
+ buf = io .StringIO (config_string )
462
+ if PY3 :
463
+ config .read_file (buf )
464
+ else :
465
+ config .readfp (buf )
461
466
except MissingSectionHeaderError :
462
467
# if header is missing, this could be deprecated
463
468
# credentials file format as described here:
464
469
# https://blog.csanchez.org/2011/05/
465
470
# then do the hacky-hack and add default header
466
471
# to be able to read the file with PyConfigParser()
467
472
config_string = u'[default]\n ' + config_string
468
- config .readfp (io .StringIO (config_string ))
473
+ buf = io .StringIO (config_string )
474
+ if PY3 :
475
+ config .read_file (buf )
476
+ else :
477
+ config .readfp (buf )
469
478
except ParsingError as exc :
470
479
raise ValueError (
471
480
"Error reading aws_credential_file "
0 commit comments