summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-12-29 15:36:12 +0100
committerHelmut Grohne <helmut@subdivi.de>2021-12-29 15:47:29 +0100
commit6b87bc371b91917980884d6dd20e39d3cda47fc7 (patch)
tree0015db4d3e7b5274c2e895811bf5bd4cbb5404bd
parentc2b5909eff090ebb3f19ab88308f0cc7b913157e (diff)
downloaddebian-dedup-6b87bc371b91917980884d6dd20e39d3cda47fc7.tar.gz
DecompressedHash: also gain a name property for consistency
-rw-r--r--dedup/hashing.py7
-rwxr-xr-ximportpkg.py4
2 files changed, 7 insertions, 4 deletions
diff --git a/dedup/hashing.py b/dedup/hashing.py
index 27f303c..9cebcbb 100644
--- a/dedup/hashing.py
+++ b/dedup/hashing.py
@@ -84,7 +84,7 @@ class HashBlacklistContent:
class DecompressedHash:
"""Apply a decompression function before the hash. This class provides the
hashlib interface (update, hexdigest, copy) excluding digest and name."""
- def __init__(self, decompressor, hashobj):
+ def __init__(self, decompressor, hashobj, name="unnamed"):
"""
@param decompressor: a decompression object like bz2.BZ2Decompressor or
lzma.LZMADecompressor. It has to provide methods decompress and
@@ -92,9 +92,11 @@ class DecompressedHash:
method.
@param hashobj: a hashlib-like obj providing methods update, hexdigest
and copy
+ @param name: initialized the name property
"""
self.decompressor = decompressor
self.hashobj = hashobj
+ self.name = name
def update(self, data):
self.hashobj.update(self.decompressor.decompress(data))
@@ -113,7 +115,8 @@ class DecompressedHash:
return tmphash.hexdigest()
def copy(self):
- return DecompressedHash(self.decompressor.copy(), self.hashobj.copy())
+ return DecompressedHash(self.decompressor.copy(), self.hashobj.copy(),
+ self.name)
class SuppressingHash:
"""A hash that silences exceptions from the update and hexdigest methods of
diff --git a/importpkg.py b/importpkg.py
index 6988c1d..6772c4d 100755
--- a/importpkg.py
+++ b/importpkg.py
@@ -25,9 +25,9 @@ def sha512_nontrivial():
return HashBlacklistContent(hashlib.sha512(), boring_content)
def gziphash():
- hashobj = DecompressedHash(GzipDecompressor(), hashlib.sha512())
+ hashobj = hashlib.sha512()
+ hashobj = DecompressedHash(GzipDecompressor(), hashobj, "gzip_sha512")
hashobj = SuppressingHash(hashobj, (ValueError, zlib.error))
- hashobj.name = "gzip_sha512"
return HashBlacklistContent(hashobj, boring_content)
def pnghash():