From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RAERL-0007dp-MD for garchives@archives.gentoo.org; Sun, 02 Oct 2011 05:18:15 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0580D21C0F0; Sun, 2 Oct 2011 05:18:05 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id CD6D021C0F0 for ; Sun, 2 Oct 2011 05:18:05 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6632D1B4005 for ; Sun, 2 Oct 2011 05:18:05 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 90CCA80042 for ; Sun, 2 Oct 2011 05:18:04 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1ae379c59a5cdc2d729f2b33807e70548afcbfb4.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/checksum.py X-VCS-Directories: pym/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 1ae379c59a5cdc2d729f2b33807e70548afcbfb4 Date: Sun, 2 Oct 2011 05:18:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 89653beb8024dda793fd1d99323f2fd5 commit: 1ae379c59a5cdc2d729f2b33807e70548afcbfb4 Author: Zac Medico gentoo org> AuthorDate: Sun Oct 2 05:17:52 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Oct 2 05:17:52 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D1ae379c5 Convert _generate_hash_function into a class. --- pym/portage/checksum.py | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py index 9e7e455..52e45d3 100644 --- a/pym/portage/checksum.py +++ b/pym/portage/checksum.py @@ -16,8 +16,16 @@ import tempfile hashfunc_map =3D {} hashorigin_map =3D {} =20 -def _generate_hash_function(hashtype, hashobject, origin=3D"unknown"): - def pyhash(filename): +class _generate_hash_function(object): + + __slots__ =3D ("_hashobject",) + + def __init__(self, hashtype, hashobject, origin=3D"unknown"): + self._hashobject =3D hashobject + hashfunc_map[hashtype] =3D self + hashorigin_map[hashtype] =3D origin + + def __call__(self, filename): """ Run a checksum against a file. =09 @@ -41,7 +49,7 @@ def _generate_hash_function(hashtype, hashobject, origi= n=3D"unknown"): blocksize =3D HASHING_BLOCKSIZE data =3D f.read(blocksize) size =3D 0 - checksum =3D hashobject() + checksum =3D self._hashobject() while data: checksum.update(data) size =3D size + len(data) @@ -49,9 +57,6 @@ def _generate_hash_function(hashtype, hashobject, origi= n=3D"unknown"): f.close() =20 return (checksum.hexdigest(), size) - hashfunc_map[hashtype] =3D pyhash - hashorigin_map[hashtype] =3D origin - return pyhash =20 # Define hash functions, try to use the best module available. Later def= initions # override earlier ones