From 6b53f45e57fdcfbdf9a1c76f9ffa8e2f650e8700 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Tue, 30 Jan 2018 23:51:26 -0800 Subject: [PATCH] Use 'with' method rather than having to call close gzip.GzipFile() supports 'with' statement usage. Use that rather than having to call close() explicitly. Plus with a 'with' statement if there is an exception it will still call close() Change-Id: I8535dffd66ffd7244b8bdcc4d79d6cf437a4d779 --- ironicclient/common/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ironicclient/common/utils.py b/ironicclient/common/utils.py index 0f3038bf7..ac6200a01 100644 --- a/ironicclient/common/utils.py +++ b/ironicclient/common/utils.py @@ -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())