misc: use with-statement to open files (#61362)
gitea/authentic2-auth-fedict/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-05-25 09:17:20 +02:00
parent 6d92e2a30b
commit 6cd2fc25a6
1 changed files with 4 additions and 2 deletions

View File

@ -66,7 +66,8 @@ class AuthenticAdapter(DefaultAdapter):
if os.path.exists(metadata_cache_filename):
stat_info = os.stat(metadata_cache_filename)
if stat_info.st_size and stat_info.st_mtime > (time.time() - 86400):
idp['METADATA'] = force_text(open(metadata_cache_filename).read())
with open(metadata_cache_filename) as fd:
idp['METADATA'] = force_text(fd.read())
continue
verify_ssl_certificate = mellon_utils.get_setting(idp, 'VERIFY_SSL_CERTIFICATE')
try:
@ -75,7 +76,8 @@ class AuthenticAdapter(DefaultAdapter):
except requests.exceptions.RequestException:
if os.path.exists(metadata_cache_filename):
# accept older cache in case of error
idp['METADATA'] = force_text(open(metadata_cache_filename).read())
with open(metadata_cache_filename) as fd:
idp['METADATA'] = force_text(fd.read())
continue
idp['METADATA'] = response.text
with open(metadata_cache_filename, 'wb') as fd: