Re: [gentoo-portage-dev] [PATCHES] portage.checksum hacking, pt. 4

2017-03-13 Thread Michał Górny
W dniu 12.03.2017, nie o godzinie 21∶31 -0700, użytkownik Zac Medico
napisał:
> On Sun, Mar 12, 2017 at 11:59 AM, Michał Górny  wrote:
> > Hi,
> > 
> > Here's a huge batch of patches for portage.checksum and relevant stuff.
> > It's not a complete rewrite as I have originally planned, and it's still
> > not the code I'd like to see but functionally it has been improved a lot.
> 
> The series looks good to me, except we should change the
> get_valid_checksum_keys function to return a frozenset.

Thanks a lot, all merged now.

-- 
Best regards,
Michał Górny


signature.asc
Description: This is a digitally signed message part


Re: [gentoo-portage-dev] [PATCH] portage.checksum: Store supported hash types in a frozenset

2017-03-13 Thread Zac Medico
On Mon, Mar 13, 2017 at 7:45 AM, Michał Górny  wrote:
> Copy the list of supported hash types (hashfunc_map dict) into
> a frozenset to support efficient access in the public API.
> ---
>  pym/portage/checksum.py | 25 ++---
>  1 file changed, 14 insertions(+), 11 deletions(-)

Looks good. Thanks!
-- 
Thanks,
Zac



[gentoo-portage-dev] [PATCH] portage.checksum: Store supported hash types in a frozenset

2017-03-13 Thread Michał Górny
Copy the list of supported hash types (hashfunc_map dict) into
a frozenset to support efficient access in the public API.
---
 pym/portage/checksum.py | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index df896533f..ff132751b 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -278,6 +278,9 @@ class SizeHash(object):
 
 hashfunc_map["size"] = SizeHash()
 
+# cache all supported hash methods in a frozenset
+hashfunc_keys = frozenset(hashfunc_map)
+
 # end actual hash functions
 
 
@@ -312,15 +315,15 @@ def _perform_md5_merge(x, **kwargs):
 
 def perform_all(x, calc_prelink=0):
mydict = {}
-   for k in hashfunc_map:
+   for k in hashfunc_keys:
mydict[k] = perform_checksum(x, k, calc_prelink)[0]
return mydict
 
 def get_valid_checksum_keys():
-   return list(hashfunc_map)
+   return hashfunc_keys
 
 def get_hash_origin(hashtype):
-   if hashtype not in hashfunc_map:
+   if hashtype not in hashfunc_keys:
raise KeyError(hashtype)
return hashorigin_map.get(hashtype, "unknown")
 
@@ -334,7 +337,7 @@ def _filter_unaccelarated_hashes(digests):
due to minimization of dependencies.
"""
if _whirlpool_unaccelerated and "WHIRLPOOL" in digests:
-   verifiable_hash_types = set(digests).intersection(hashfunc_map)
+   verifiable_hash_types = set(digests).intersection(hashfunc_keys)
verifiable_hash_types.discard("size")
if len(verifiable_hash_types) > 1:
digests = dict(digests)
@@ -383,7 +386,7 @@ def _apply_hash_filter(digests, hash_filter):
@type hash_filter: callable
"""
 
-   verifiable_hash_types = set(digests).intersection(hashfunc_map)
+   verifiable_hash_types = set(digests).intersection(hashfunc_keys)
verifiable_hash_types.discard("size")
modified = False
if len(verifiable_hash_types) > 1:
@@ -430,10 +433,10 @@ def verify_all(filename, mydict, calc_prelink=0, 
strict=0):
raise portage.exception.FileNotFound(filename)
return False, (str(e), None, None)
 
-   verifiable_hash_types = set(mydict).intersection(hashfunc_map)
+   verifiable_hash_types = set(mydict).intersection(hashfunc_keys)
verifiable_hash_types.discard("size")
if not verifiable_hash_types:
-   expected = set(hashfunc_map)
+   expected = set(hashfunc_keys)
expected.discard("size")
expected = list(expected)
expected.sort()
@@ -448,7 +451,7 @@ def verify_all(filename, mydict, calc_prelink=0, strict=0):
for x in sorted(mydict):
if   x == "size":
continue
-   elif x in hashfunc_map:
+   elif x in hashfunc_keys:
myhash = perform_checksum(filename, x, 
calc_prelink=calc_prelink)[0]
if mydict[x] != myhash:
if strict:
@@ -504,7 +507,7 @@ def perform_checksum(filename, hashname="MD5", 
calc_prelink=0):
# This happens during uninstallation of prelink.
prelink_capable = False
try:
-   if hashname not in hashfunc_map:
+   if hashname not in hashfunc_keys:
raise 
portage.exception.DigestException(hashname + \
" hash function not available (needs 
dev-python/pycrypto)")
myhash, mysize = 
hashfunc_map[hashname].checksum_file(myfilename)
@@ -541,7 +544,7 @@ def perform_multiple_checksums(filename, hashes=["MD5"], 
calc_prelink=0):
"""
rVal = {}
for x in hashes:
-   if x not in hashfunc_map:
+   if x not in hashfunc_keys:
raise portage.exception.DigestException(x+" hash 
function not available (needs dev-python/pycrypto or >=dev-lang/python-2.5)")
rVal[x] = perform_checksum(filename, x, calc_prelink)[0]
return rVal
@@ -558,7 +561,7 @@ def checksum_str(data, hashname="MD5"):
@rtype: String
@return: The hash (hex-digest) of the data
"""
-   if hashname not in hashfunc_map:
+   if hashname not in hashfunc_keys:
raise portage.exception.DigestException(hashname + \
" hash function not available (needs 
dev-python/pycrypto)")
return hashfunc_map[hashname].checksum_str(data)
-- 
2.12.0