summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-10-01 22:17:52 -0700
committerZac Medico <zmedico@gentoo.org>2011-10-01 22:17:52 -0700
commit1ae379c59a5cdc2d729f2b33807e70548afcbfb4 (patch)
tree60343456d03890a1cceb1f41cdeb176315a8075d
parentc246c6db51b97f1c556c8bddfb955e7f55db700f (diff)
downloadportage-1ae379c59a5cdc2d729f2b33807e70548afcbfb4.tar.gz
portage-1ae379c59a5cdc2d729f2b33807e70548afcbfb4.tar.bz2
portage-1ae379c59a5cdc2d729f2b33807e70548afcbfb4.zip
Convert _generate_hash_function into a class.
-rw-r--r--pym/portage/checksum.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 9e7e455d1..52e45d388 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -16,8 +16,16 @@ import tempfile
hashfunc_map = {}
hashorigin_map = {}
-def _generate_hash_function(hashtype, hashobject, origin="unknown"):
- def pyhash(filename):
+class _generate_hash_function(object):
+
+ __slots__ = ("_hashobject",)
+
+ def __init__(self, hashtype, hashobject, origin="unknown"):
+ self._hashobject = hashobject
+ hashfunc_map[hashtype] = self
+ hashorigin_map[hashtype] = origin
+
+ def __call__(self, filename):
"""
Run a checksum against a file.
@@ -41,7 +49,7 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"):
blocksize = HASHING_BLOCKSIZE
data = f.read(blocksize)
size = 0
- checksum = hashobject()
+ checksum = self._hashobject()
while data:
checksum.update(data)
size = size + len(data)
@@ -49,9 +57,6 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"):
f.close()
return (checksum.hexdigest(), size)
- hashfunc_map[hashtype] = pyhash
- hashorigin_map[hashtype] = origin
- return pyhash
# Define hash functions, try to use the best module available. Later definitions
# override earlier ones