Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Sun, 02 Oct 2011 05:18:15
Message-Id: 1ae379c59a5cdc2d729f2b33807e70548afcbfb4.zmedico@gentoo
1 commit: 1ae379c59a5cdc2d729f2b33807e70548afcbfb4
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun Oct 2 05:17:52 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun Oct 2 05:17:52 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1ae379c5
7
8 Convert _generate_hash_function into a class.
9
10 ---
11 pym/portage/checksum.py | 17 +++++++++++------
12 1 files changed, 11 insertions(+), 6 deletions(-)
13
14 diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
15 index 9e7e455..52e45d3 100644
16 --- a/pym/portage/checksum.py
17 +++ b/pym/portage/checksum.py
18 @@ -16,8 +16,16 @@ import tempfile
19 hashfunc_map = {}
20 hashorigin_map = {}
21
22 -def _generate_hash_function(hashtype, hashobject, origin="unknown"):
23 - def pyhash(filename):
24 +class _generate_hash_function(object):
25 +
26 + __slots__ = ("_hashobject",)
27 +
28 + def __init__(self, hashtype, hashobject, origin="unknown"):
29 + self._hashobject = hashobject
30 + hashfunc_map[hashtype] = self
31 + hashorigin_map[hashtype] = origin
32 +
33 + def __call__(self, filename):
34 """
35 Run a checksum against a file.
36
37 @@ -41,7 +49,7 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"):
38 blocksize = HASHING_BLOCKSIZE
39 data = f.read(blocksize)
40 size = 0
41 - checksum = hashobject()
42 + checksum = self._hashobject()
43 while data:
44 checksum.update(data)
45 size = size + len(data)
46 @@ -49,9 +57,6 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"):
47 f.close()
48
49 return (checksum.hexdigest(), size)
50 - hashfunc_map[hashtype] = pyhash
51 - hashorigin_map[hashtype] = origin
52 - return pyhash
53
54 # Define hash functions, try to use the best module available. Later definitions
55 # override earlier ones