summaryrefslogtreecommitdiff
path: root/dedup/hashing.py
diff options
context:
space:
mode:
Diffstat (limited to 'dedup/hashing.py')
-rw-r--r--dedup/hashing.py28
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):