cleaner FileLikeWrapper with own __init__

This commit is contained in:
Thomas Waldmann 2023-01-30 03:31:27 +01:00
parent 9740767449
commit e772d70e05
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 6 additions and 2 deletions

View File

@ -13,6 +13,9 @@ logger = create_logger()
class FileLikeWrapper:
def __init__(self, fd):
self.fd = fd
def __enter__(self):
self.fd.__enter__()
return self
@ -59,7 +62,7 @@ class FileHashingWrapper(FileLikeWrapper):
FACTORY: Callable = None
def __init__(self, backing_fd, write):
self.fd = backing_fd
super().__init__(backing_fd)
self.writing = write
self.hash = self.FACTORY()
@ -142,7 +145,8 @@ class IntegrityCheckedFile(FileLikeWrapper):
# TODO: When we're reading but don't have any digests, i.e. no integrity file existed,
# TODO: then we could just short-circuit.
self.fd = self.hasher = hash_cls(backing_fd=self.file_fd, write=write)
self.hasher = hash_cls(backing_fd=self.file_fd, write=write)
super().__init__(self.hasher)
self.hash_filename(filename)
def load_integrity_data(self, path, integrity_data):