diff options
author | Helmut Grohne <helmut@subdivi.de> | 2021-12-31 15:45:33 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2021-12-31 15:45:33 +0100 |
commit | f3ea68482e6c01053cb202573d953e8a2e89529f (patch) | |
tree | 4c08f6e5a99bbe5131c0949e7f97cc44cf4a2cbd /dedup/hashing.py | |
parent | f2eda3ba74e5bc5613e84381ebd8bfd343e1c8cc (diff) | |
parent | 5b359b10053cbade539246eec26e86b44793ca40 (diff) | |
download | debian-dedup-f3ea68482e6c01053cb202573d953e8a2e89529f.tar.gz |
Merge branch master into branch multiarchhints
Among other things, this drops Python 2.x support.
Diffstat (limited to 'dedup/hashing.py')
-rw-r--r-- | dedup/hashing.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/dedup/hashing.py b/dedup/hashing.py index 2a83929..9cebcbb 100644 --- a/dedup/hashing.py +++ b/dedup/hashing.py @@ -1,10 +1,6 @@ import itertools -try: - from itertools import imap as map -except ImportError: - pass # in python3 map is already imap -class HashBlacklist(object): +class HashBlacklist: """Turn a hashlib-like object into a hash that returns None for some blacklisted hashes instead of the real hash value. @@ -35,7 +31,7 @@ class HashBlacklist(object): def copy(self): return HashBlacklist(self.hashobj.copy(), self.blacklist) -class HashBlacklistContent(object): +class HashBlacklistContent: """Turn a hashlib-like object into a hash that returns None for some blacklisted content instead of the real hash value. Unlike HashBlacklist, not the output of the hash is considered, but its input.""" @@ -80,13 +76,15 @@ class HashBlacklistContent(object): return self.hashobj.hexdigest() def copy(self): - return HashBlacklistContent(self.hashobj.copy(), self.blacklist, - self.maxlen) + new = HashBlacklistContent(self.hashobj.copy(), self.blacklist, + self.maxlen) + new.stored = self.stored + return new -class DecompressedHash(object): +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 @@ -94,9 +92,11 @@ class DecompressedHash(object): 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)) @@ -115,9 +115,10 @@ class DecompressedHash(object): 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(object): +class SuppressingHash: """A hash that silences exceptions from the update and hexdigest methods of a hashlib-like object. If an exception has occurred, hexdigest always returns None.""" @@ -163,9 +164,8 @@ def hash_file(hashobj, filelike, blocksize=65536): while data: hashobj.update(data) data = filelike.read(blocksize) - return hashobj -class HashedStream(object): +class HashedStream: """A file-like object, that supports sequential reading and hashes the contents on the fly.""" def __init__(self, filelike, hashobj): |