def checksum(path): """ Computes the md5 checksum of the file """ if not path: raise ValueError("'path' must be an absolute path.") #read the file in chunks for performance reasons h = hashlib.md5() SIZE = 1 << 16 fd = open(path, "rb") for chunk in iter(lambda: fd.read(SIZE), ""): h.update(chunk) return h.hexdigest() fd.close()
def a_better_digest(*args, **kwargs): """ Digest using a generator instead of recursion """ digester = hashlib.md5() digester.update("/") digester.update("/".join(_flattening_generator(args))) return digester.digest()