mirror of
https://github.com/zoriya/Autopipe.git
synced 2026-05-29 13:11:51 +00:00
Adding tee & filters
This commit is contained in:
+2
-1
@@ -18,8 +18,9 @@ class Pipe(ABC):
|
||||
def name(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@abstractmethod
|
||||
def pipe(self, data: APData) -> APData:
|
||||
pass
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class Input(ABC):
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from typing import Callable
|
||||
from models import Pipe, APData
|
||||
|
||||
|
||||
class FilterPipe(Pipe):
|
||||
def __init__(self, filter: Callable[[APData], bool]):
|
||||
super().__init__()
|
||||
self.filter = filter
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return "Filter"
|
||||
|
||||
def pipe(self, data: APData) -> APData:
|
||||
return data if self.filter(data) else None
|
||||
@@ -0,0 +1,16 @@
|
||||
from models import Pipe, APData
|
||||
|
||||
|
||||
class TeePipe(Pipe):
|
||||
def __init__(self, *outputs):
|
||||
super().__init__()
|
||||
self.outputs = outputs
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return "Tee"
|
||||
|
||||
def pipe(self, data: APData) -> APData:
|
||||
for output in self.outputs:
|
||||
output.pipe(data)
|
||||
return data
|
||||
Reference in New Issue
Block a user