public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/_emerge/
Date: Fri, 26 Aug 2011 19:55:37 +0000 (UTC)	[thread overview]
Message-ID: <42c96587b86ba8f551f605086e47a5cd96843a1a.zmedico@gentoo> (raw)

commit:     42c96587b86ba8f551f605086e47a5cd96843a1a
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 26 19:53:55 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Aug 26 19:53:55 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=42c96587

python3.2 fixes: ResourceWarning: unclosed file

---
 pym/_emerge/BinpkgEnvExtractor.py |    2 +-
 pym/portage/dbapi/vartree.py      |   15 +++++++++++----
 pym/portage/xpak.py               |    3 ++-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/pym/_emerge/BinpkgEnvExtractor.py b/pym/_emerge/BinpkgEnvExtractor.py
index f68971b..1c94718 100644
--- a/pym/_emerge/BinpkgEnvExtractor.py
+++ b/pym/_emerge/BinpkgEnvExtractor.py
@@ -59,7 +59,7 @@ class BinpkgEnvExtractor(CompositeTask):
 		# This is a signal to ebuild.sh, so that it knows to filter
 		# out things like SANDBOX_{DENY,PREDICT,READ,WRITE} that
 		# would be preserved between normal phases.
-		open(_unicode_encode(self._get_dest_env_path() + '.raw'), 'w')
+		open(_unicode_encode(self._get_dest_env_path() + '.raw'), 'wb').close()
 
 		self._current_task = None
 		self.returncode = os.EX_OK

diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 7f7873b..6e49f38 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -3192,17 +3192,22 @@ class dblink(object):
 					pass
 				continue
 
+			f = None
 			try:
-				val = io.open(_unicode_encode(
+				f = io.open(_unicode_encode(
 					os.path.join(inforoot, var_name),
 					encoding=_encodings['fs'], errors='strict'),
 					mode='r', encoding=_encodings['repo.content'],
-					errors='replace').readline().strip()
+					errors='replace')
+				val = f.readline().strip()
 			except EnvironmentError as e:
 				if e.errno != errno.ENOENT:
 					raise
 				del e
 				val = ''
+			finally:
+				if f is not None:
+					f.close()
 
 			if var_name == 'SLOT':
 				slot = val
@@ -3558,10 +3563,12 @@ class dblink(object):
 		# write local package counter for recording
 		if counter is None:
 			counter = self.vartree.dbapi.counter_tick(mycpv=self.mycpv)
-		io.open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER'),
+		f = io.open(_unicode_encode(os.path.join(self.dbtmpdir, 'COUNTER'),
 			encoding=_encodings['fs'], errors='strict'),
 			mode='w', encoding=_encodings['repo.content'],
-			errors='backslashreplace').write(_unicode_decode(str(counter)))
+			errors='backslashreplace')
+		f.write(_unicode_decode(str(counter)))
+		f.close()
 
 		self.updateprotect()
 

diff --git a/pym/portage/xpak.py b/pym/portage/xpak.py
index 01cfe7b..a05a860 100644
--- a/pym/portage/xpak.py
+++ b/pym/portage/xpak.py
@@ -99,7 +99,8 @@ def xpak(rootdir,outfile=None):
 			# CONTENTS is generated during the merge process.
 			continue
 		x = _unicode_encode(x, encoding=_encodings['fs'], errors='strict')
-		mydata[x] = open(os.path.join(rootdir, x), 'rb').read()
+		with open(os.path.join(rootdir, x), 'rb') as f:
+			mydata[x] = f.read()
 
 	xpak_segment = xpak_mem(mydata)
 	if outfile:



             reply	other threads:[~2011-08-26 19:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-26 19:55 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-10-24 17:55 [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/, pym/_emerge/ Zac Medico
2012-02-14 12:30 Zac Medico
2012-03-27 18:28 Zac Medico
2012-09-29  2:36 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42c96587b86ba8f551f605086e47a5cd96843a1a.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox