def detect_credentials(config_name, extra_environ=None, filenames=None,<EOL>aws_profile_name=None, default_value=Ellipsis):
<EOL>if config_name is not None and config[config_name] is not None: return config[config_name]<EOL>if   extra_environ is None: extra_environ = []<EOL>elif pimms.is_str(extra_environ): extra_environ = [extra_environ]<EOL>elif pimms.is_vector(extra_environ):<EOL><INDENT>if pimms.is_vector(extra_environ, str):<EOL><INDENT>if len(extra_environ) == <NUM_LIT:2> and isinstance(extra_environ, _tuple_type):<EOL><INDENT>extra_environ = [extra_environ]<EOL><DEDENT><DEDENT><DEDENT>elif not pimms.is_matrix(extra_environ, str):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>for ee in extra_environ:<EOL><INDENT>if pimms.is_str(ee):<EOL><INDENT>if ee in os.environ:<EOL><INDENT>try:              return to_credentials(q)<EOL>except Exception: pass<EOL><DEDENT><DEDENT>elif pimms.is_vector(ee, str) and len(ee) == <NUM_LIT:2>:<EOL><INDENT>if ee[<NUM_LIT:0>] in os.environ and ee[<NUM_LIT:1>] in os.environ:<EOL><INDENT>(k,s) = [os.environ[q] for q in ee]<EOL>if len(k) > <NUM_LIT:0> and len(s) > <NUM_LIT:0>: continue<EOL>return (k,s)<EOL><DEDENT><DEDENT>else: raise ValueError('<STR_LIT>' % ee)<EOL><DEDENT>if filenames is None: filenames = []<EOL>elif pimms.is_str(filenames): filenames = [filenames]<EOL>for flnm in filenames:<EOL><INDENT>flnm = os.expanduser(os.expandvars(flnm))<EOL>if os.path.isfile(flnm):<EOL><INDENT>try:              return to_credentials(flnm)<EOL>except Exception: pass<EOL><DEDENT><DEDENT>if pimms.is_str(aws_profile_name): aws_profile_name = [aws_profile_name]<EOL>elif aws_profile_name is None or len(aws_profile_name) == <NUM_LIT:0>: aws_profile_name = None<EOL>elif not pimms.is_vector(aws_profile_name, str):<EOL><INDENT>raise ValueError('<STR_LIT>' % aws_profile_name)<EOL><DEDENT>if aws_profile_name is not None:<EOL><INDENT>try:<EOL><INDENT>cc = confparse.ConfigParser()<EOL>cc.read([os.expanduser(os.path.join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')),<EOL>os.expanduser(os.path.join('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')),<EOL>os.expanduser(os.path.join('<STR_LIT>', '<STR_LIT>'))])<EOL>for awsprof in aws_profile_names:<EOL><INDENT>try:<EOL><INDENT>aws_access_key_id     = cc.get(awsprof, '<STR_LIT>')<EOL>aws_secret_access_key = cc.get(awsprof, '<STR_LIT>')<EOL>return (aws_access_key_id, aws_secret_access_key)<EOL><DEDENT>except Exception: pass<EOL><DEDENT><DEDENT>except Exception: pass<EOL><DEDENT>if default_value is None:<EOL><INDENT>return None<EOL><DEDENT>elif default_value is Ellipsis:<EOL><INDENT>if config_name is None: raise ValueError('<STR_LIT>')<EOL>else: raise ValueError('<STR_LIT>' % config_name)<EOL><DEDENT>else: return to_credentials(default_value)<EOL>
detect_credentials(config_name) attempts to locate Amazon S3 Bucket credentials from the given
  configuration item config_name.

The following optional arguments are accepted:
  * extra_environ (default: None) may specify a string or a tuple (key_name, secret_name) or a
    list of strings or tuples; strings are treated as an additional environment variable that
    should be checked for credentials while tuples are treated as paired varialbes: if both are
    defined, then they are checked as separate holders of a key/secret pair. Note that a list
    of strings is considered a pair of solo environment varialbes while a tuple of strings is
    considered a single (key_name, secret_name) pair.
  * filenames (default: None) may specify a list of filenames that are checked in order for
    credentials.
  * aws_profile_name (default: None) may specify a profile name that appears in the
    ~/.aws/credentials file that will be checked for aws_access_key_id and aws_secret_access_key
    values. The files ~/.amazon/credentials and ~/.credentials are also checked. Note that this
    may be a list of profiles to check.
  * default_value (default: Ellipsis) may specify a value to return when no credentials are
    found; if this value is None, then it is always returned; otherwise, the value is passed
    through to_credentials() and any errors are allowed to propagate out of
    detect_credentials(). If default_value is Ellipsis then an error is simply raised stating
    that no credentials could be found.

The detect_credentials() function looks at the following locations in the following order,
assuming that it has been provided with the relevant information:
  * first, if the Neuropythy configuration variable config_name is set via either the npythyrc
    file or the associated environment variable, then it is coerced into credentials;
  * next, if the environment contains both the variables key_name and secret_name (from the 
    optional argument key_secret_environ), then these values are used;
  * next, if the filenames argument is given, then all files it refers to are checked for
    credentials; these files are expanded with both os.expanduser and os.expandvars.
  * finally, if no credentials were detected, an error is raised.