Merge "Use 'with' method rather than having to call close"

This commit is contained in:
Zuul 2018-02-05 21:57:25 +00:00 committed by Gerrit Code Review
commit 1da269b0e9
1 changed files with 2 additions and 3 deletions

View File

@ -292,9 +292,8 @@ def make_configdrive(path):
# Compress file
tmpfile.seek(0)
g = gzip.GzipFile(fileobj=tmpzipfile, mode='wb')
shutil.copyfileobj(tmpfile, g)
g.close()
with gzip.GzipFile(fileobj=tmpzipfile, mode='wb') as gz_file:
shutil.copyfileobj(tmpfile, gz_file)
tmpzipfile.seek(0)
return base64.encode_as_bytes(tmpzipfile.read())