7373 # In python 3, unicode -> str, and str -> bytes
7474 unicode = str
7575
76+ PY3 = (sys .version_info >= (3 , 0 ))
77+
7678
7779def is_bool_true (value ):
7880 """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
268270 try :
269271 self .read_config_file (configfile )
270272 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 :
272274 self .aws_credential_file ()
273275
274276 # override these if passed on the command-line
@@ -440,7 +442,8 @@ def role_refresh(self):
440442 def aws_credential_file (self ):
441443 try :
442444 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' )
444447 if credential_file_from_env and \
445448 os .path .isfile (credential_file_from_env ):
446449 aws_credential_file = base_unicodise (credential_file_from_env )
@@ -455,17 +458,23 @@ def aws_credential_file(self):
455458 config_string = fp .read ()
456459 try :
457460 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 )
461466 except MissingSectionHeaderError :
462467 # if header is missing, this could be deprecated
463468 # credentials file format as described here:
464469 # https://blog.csanchez.org/2011/05/
465470 # then do the hacky-hack and add default header
466471 # to be able to read the file with PyConfigParser()
467472 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 )
469478 except ParsingError as exc :
470479 raise ValueError (
471480 "Error reading aws_credential_file "
0 commit comments