From 5e5a5cddfdeb3aa05932114fc1dce65b5be11ae9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 28 Dec 2012 22:30:09 -0800 Subject: Use 'with file' more. This helps to minimize ResourceWarning triggered by ^C with python3. --- pym/portage/cache/flat_hash.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'pym/portage/cache') diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py index b71e118d5..b1c94313b 100644 --- a/pym/portage/cache/flat_hash.py +++ b/pym/portage/cache/flat_hash.py @@ -1,4 +1,4 @@ -# Copyright: 2005-2011 Gentoo Foundation +# Copyright: 2005-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Author(s): Brian Harring (ferringb@gentoo.org) @@ -42,11 +42,10 @@ class database(fs_template.FsBased): # Don't use os.path.join, for better performance. fp = self.location + _os.sep + cpv try: - myf = io.open(_unicode_encode(fp, + with io.open(_unicode_encode(fp, encoding=_encodings['fs'], errors='strict'), mode='r', encoding=_encodings['repo.content'], - errors='replace') - try: + errors='replace') as myf: lines = myf.read().split("\n") if not lines[-1]: lines.pop() @@ -56,8 +55,6 @@ class database(fs_template.FsBased): # that uses mtime mangling. d['_mtime_'] = _os.fstat(myf.fileno())[stat.ST_MTIME] return d - finally: - myf.close() except (IOError, OSError) as e: if e.errno != errno.ENOENT: raise cache_errors.CacheCorruption(cpv, e) -- cgit v1.2.3-1-g7c22