python3.2 fixes: ResourceWarning: unclosed file
authorZac Medico <zmedico@gentoo.org>
Mon, 29 Aug 2011 05:20:49 +0000 (22:20 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 29 Aug 2011 05:20:49 +0000 (22:20 -0700)
pym/portage/update.py

index 548d19cef268ba3c0ad345caf8628daf7182f593..1a2c86cc25fe1e89f6781512b50e3b7920c02cd3 100644 (file)
@@ -253,14 +253,19 @@ def update_config_files(config_root, protect, protect_mask, update_iter, match_c
                        recursivefiles.append(x)
        myxfiles = recursivefiles
        for x in myxfiles:
+               f = None
                try:
-                       file_contents[x] = io.open(
+                       f = io.open(
                                _unicode_encode(os.path.join(abs_user_config, x),
                                encoding=_encodings['fs'], errors='strict'),
                                mode='r', encoding=_encodings['content'],
-                               errors='replace').readlines()
+                               errors='replace')
+                       file_contents[x] = f.readlines()
                except IOError:
                        continue
+               finally:
+                       if f is not None:
+                               f.close()
 
        # update /etc/portage/packages.*
        ignore_line_re = re.compile(r'^#|^\s*$')