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/checksum.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'pym/portage/checksum.py') diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 30a9234e1..cd663e767 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -50,16 +50,15 @@ class _generate_hash_function(object): @type filename: String @return: The hash and size of the data """ - f = _open_file(filename) - blocksize = HASHING_BLOCKSIZE - data = f.read(blocksize) - size = 0 - checksum = self._hashobject() - while data: - checksum.update(data) - size = size + len(data) + with _open_file(filename) as f: + blocksize = HASHING_BLOCKSIZE + size = 0 + checksum = self._hashobject() data = f.read(blocksize) - f.close() + while data: + checksum.update(data) + size = size + len(data) + data = f.read(blocksize) return (checksum.hexdigest(), size) -- cgit v1.2.3-1-g7c22