summaryrefslogtreecommitdiffstats
path: root/pym/portage/output.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-08-24 19:25:59 -0700
committerZac Medico <zmedico@gentoo.org>2011-08-24 19:25:59 -0700
commita12c63842b28e29f3bc6718e6d940d5b697f010f (patch)
treecb1e1f4a102a369591dc70355987e8c81e7c2f4d /pym/portage/output.py
parentf4d5667a09cb308f30bb7eb5ee14b9ef061c3604 (diff)
downloadportage-a12c63842b28e29f3bc6718e6d940d5b697f010f.tar.gz
portage-a12c63842b28e29f3bc6718e6d940d5b697f010f.tar.bz2
portage-a12c63842b28e29f3bc6718e6d940d5b697f010f.zip
python3.2 fixes: ResourceWarning: unclosed file
Diffstat (limited to 'pym/portage/output.py')
-rw-r--r--pym/portage/output.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/pym/portage/output.py b/pym/portage/output.py
index 0e8245f9a..763d74a7a 100644
--- a/pym/portage/output.py
+++ b/pym/portage/output.py
@@ -162,11 +162,14 @@ def _parse_color_map(config_root='/', onerror=None):
if token[0] in quotes and token[0] == token[-1]:
token = token[1:-1]
return token
+
+ f = None
try:
- lineno=0
- for line in io.open(_unicode_encode(myfile,
+ f = io.open(_unicode_encode(myfile,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['content'], errors='replace'):
+ mode='r', encoding=_encodings['content'], errors='replace')
+ lineno = 0
+ for line in f:
lineno += 1
commenter_pos = line.find("#")
@@ -226,6 +229,9 @@ def _parse_color_map(config_root='/', onerror=None):
elif e.errno == errno.EACCES:
raise PermissionDenied(myfile)
raise
+ finally:
+ if f is not None:
+ f.close()
def nc_len(mystr):
tmp = re.sub(esc_seq + "^m]+m", "", mystr);