From c8e5a878e8d78aec88872ee879196ff54adb4241 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Wed, 23 Oct 2019 20:50:13 +0100 Subject: [PATCH] debian/lib/python/debian_linux/utils.py: Use 'with' to manage file handles --- debian/changelog | 1 + debian/lib/python/debian_linux/utils.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/debian/changelog b/debian/changelog index 02ff2513e56f..e3c4aaae89aa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ linux (5.3.7-2) UNRELEASED; urgency=medium * gencontrol: Generalise substitution of debhelper config template * Add maint scripts to meta-packages to convert doc directories to symlinks (Closes: #942861) + * debian/lib/python/debian_linux/utils.py: Use 'with' to manage file handles -- Ben Hutchings Wed, 23 Oct 2019 18:32:15 +0100 diff --git a/debian/lib/python/debian_linux/utils.py b/debian/lib/python/debian_linux/utils.py index 34c15536df05..577ad319c55d 100644 --- a/debian/lib/python/debian_linux/utils.py +++ b/debian/lib/python/debian_linux/utils.py @@ -23,12 +23,12 @@ class Templates(object): for dir in self.dirs: filename = "%s/%s%s" % (dir, name, suffix) if os.path.exists(filename): - f = codecs.open(filename, 'r', 'utf-8') - if prefix == 'control': - return read_control(f) - if prefix == 'tests-control': - return read_tests_control(f) - return f.read() + with codecs.open(filename, 'r', 'utf-8') as f: + if prefix == 'control': + return read_control(f) + if prefix == 'tests-control': + return read_tests_control(f) + return f.read() def get(self, key, default=None): if key in self._cache: