Skip to content

Commit

Permalink
remove _Process
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-vuillemot committed Jan 25, 2025
1 parent aa26259 commit d349a11
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions cshelve/_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from .exceptions import DataProcessingSignatureError


_Process = namedtuple("Process", ["signature", "function"])
_DataProcessing = namedtuple("DataProcessing", ["post_processes", "data"])
_DataProcessingMetadata = namedtuple(
"DataProcessingMetadata", ["len_post_processes", "len_data", "data_processing"]
Expand All @@ -34,8 +33,8 @@ def __init__(self, logger):
Initializes the DataProcessing class.
"""
self.logger = logger
self.pre_processing: List[_Process] = []
self.post_processing: List[_Process] = []
self.pre_processing: List[Callable[[bytes], bytes]] = []
self.post_processing: List[Callable[[bytes], bytes]] = []
self.post_processing_signature = b""

def add(
Expand All @@ -48,20 +47,16 @@ def add(
Adds functions for processing.
The signature is used to generate the signature of the data. If the processing functions don't interact with the data, it should be set to None.
"""
self.pre_processing.append(
_Process(signature=signature, function=pre_processing)
)
self.post_processing.insert(
0, _Process(signature=signature, function=post_processing)
)
self.pre_processing.append(pre_processing)
self.post_processing.insert(post_processing)
self.post_processing_signature = signature + self.post_processing_signature

def apply_pre_processing(self, data: bytes) -> bytes:
"""
Applies all pre-processing functions to the data.
"""
for p in self.pre_processing:
data = p.function(data)
for fct in self.pre_processing:
data = fct.function(data)

len_data_proc_signature = len(self.post_processing_signature)
len_data = len(data)
Expand Down Expand Up @@ -103,6 +98,6 @@ def apply_post_processing(self, data: bytes) -> bytes:
raise DataProcessingSignatureError("Wrong data processing signature.")

data = data_processing.data
for p in self.post_processing:
data = p.function(data)
for fct in self.post_processing:
data = fct.function(data)
return data

0 comments on commit d349a11

Please sign in to comment.