wattleflow 0.0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,173 @@
1
+ # Author: (wattleflow@outlook.com)
2
+ # Copyright: (c) 2022-2024 WattleFlow
3
+ # License: Apache 2 Licence
4
+
5
+ from .framework import IWattleflow
6
+ from .behavioral import (
7
+ IHandler,
8
+ ICommand,
9
+ IInvoker,
10
+ IExpression,
11
+ IIterator,
12
+ IAsyncIterator,
13
+ IAggregate,
14
+ IMediator,
15
+ IColleague,
16
+ IMemento,
17
+ IOriginator,
18
+ IObserver,
19
+ IObservable,
20
+ IState,
21
+ IStateContext,
22
+ IStrategy,
23
+ IStrategyContext,
24
+ ITemplate,
25
+ IVisitor,
26
+ IElement,
27
+ )
28
+ from .concurent import (
29
+ IFuture,
30
+ IPromise,
31
+ ICallback,
32
+ IObserverReactive,
33
+ IObservableReactive,
34
+ IEventLoop,
35
+ IPublisher,
36
+ ISubscriber,
37
+ IMessageQueue,
38
+ IThreadPool,
39
+ ICoroutine,
40
+ IMapper,
41
+ IReducer,
42
+ ISuperstep,
43
+ IBSPSystem,
44
+ IForkJoinTask,
45
+ IForkJoinPool,
46
+ IBarrier,
47
+ IDivideAndConquer,
48
+ IDataParallelTask,
49
+ IWorkStealingScheduler,
50
+ IWorker,
51
+ IStencil,
52
+ IGraphProcessing,
53
+ ISPMDProgram,
54
+ )
55
+ from .creational import (
56
+ IFactory,
57
+ IBuilder,
58
+ IProduct,
59
+ ICreator,
60
+ IPrototype,
61
+ ISingleton
62
+ )
63
+ from .structural import (
64
+ ITarget,
65
+ IAdaptee,
66
+ IAdapter,
67
+ IImplementor,
68
+ IAbstraction,
69
+ IComponent,
70
+ IComposite,
71
+ IDecorator,
72
+ IFacade,
73
+ IGraph,
74
+ IFlyweight,
75
+ IFlyweightFactory,
76
+ IProxy,
77
+ )
78
+ from .transactional import (
79
+ IActor,
80
+ ISystem,
81
+ IEventListener,
82
+ IEventSource,
83
+ IDataflowComponent,
84
+ IRepository,
85
+ IBlackboard,
86
+ IModule,
87
+ IPipeline,
88
+ IProcessor,
89
+ IQuery,
90
+ ISaga,
91
+ IUnitOfWork,
92
+ )
93
+
94
+ __all__ = [
95
+ "IWattleflow",
96
+ "IHandler",
97
+ "ICommand",
98
+ "IInvoker",
99
+ "IExpression",
100
+ "IIterator",
101
+ "IAsyncIterator",
102
+ "IAggregate",
103
+ "IMediator",
104
+ "IColleague",
105
+ "IMemento",
106
+ "IOriginator",
107
+ "IObserver",
108
+ "IObservable",
109
+ "IState",
110
+ "IStateContext",
111
+ "IStrategy",
112
+ "IStrategyContext",
113
+ "ITemplate",
114
+ "IVisitor",
115
+ "IElement",
116
+ "IFuture",
117
+ "IPromise",
118
+ "ICallback",
119
+ "IObserverReactive",
120
+ "IObservableReactive",
121
+ "IEventLoop",
122
+ "IPublisher",
123
+ "ISubscriber",
124
+ "IMessageQueue",
125
+ "IThreadPool",
126
+ "ICoroutine",
127
+ "IMapper",
128
+ "IReducer",
129
+ "ISuperstep",
130
+ "IBSPSystem",
131
+ "IForkJoinTask",
132
+ "IForkJoinPool",
133
+ "IBarrier",
134
+ "IDivideAndConquer",
135
+ "IDataParallelTask",
136
+ "IWorkStealingScheduler",
137
+ "IWorker",
138
+ "IStencil",
139
+ "IGraphProcessing",
140
+ "ISPMDProgram",
141
+ "IFactory",
142
+ "IBuilder",
143
+ "IProduct",
144
+ "ICreator",
145
+ "IPrototype",
146
+ "ISingleton",
147
+ "ITarget",
148
+ "IAdaptee",
149
+ "IAdapter",
150
+ "IImplementor",
151
+ "IAbstraction",
152
+ "IComponent",
153
+ "IComposite",
154
+ "IDecorator",
155
+ "IFacade",
156
+ "IGraph",
157
+ "IFlyweight",
158
+ "IFlyweightFactory",
159
+ "IProxy",
160
+ "IActor",
161
+ "ISystem",
162
+ "IEventListener",
163
+ "IEventSource",
164
+ "IDataflowComponent",
165
+ "IRepository",
166
+ "IBlackboard",
167
+ "IModule",
168
+ "IPipeline",
169
+ "IProcessor",
170
+ "IQuery",
171
+ "ISaga",
172
+ "IUnitOfWork",
173
+ ]
@@ -0,0 +1,379 @@
1
+ # Module Name: behavioural.py
2
+ # Author: (wattleflow@outlook.com)
3
+ # Copyright: (c) 2022-2024 WattleFlow
4
+ # License: Apache 2 Licence
5
+ # Description: This modul contains abstract design pattern interfaces.
6
+
7
+ from abc import ABC, abstractmethod
8
+ from .framework import IWattleflow
9
+ from typing import (
10
+ Any,
11
+ AsyncIterator,
12
+ Generic,
13
+ Iterator,
14
+ Type,
15
+ TypeVar,
16
+ )
17
+
18
+
19
+ T = TypeVar("T")
20
+
21
+ """
22
+ Behavioral Interfaces
23
+ Chain of Responsibility
24
+ IHandler
25
+ Command
26
+ ICommand
27
+ Interpreter
28
+ IExpression
29
+ Iterator
30
+ IIterator
31
+ IAggregate
32
+ Mediator
33
+ IMediator
34
+ Memento
35
+ IMemento
36
+ IOriginator
37
+ Observer
38
+ IObserver
39
+ IObservable
40
+ State
41
+ IState
42
+ IStateContext
43
+ Strategy
44
+ IStrategy
45
+ IStrategyContext
46
+ Template Method
47
+ ITemplate
48
+ Visitor
49
+ IVisitor
50
+ IElement
51
+ """
52
+
53
+
54
+ # Behavioural interfaces
55
+ # Chain of responsiblity interfaces (IHandler, ICommand, IInvoker)
56
+ # IHandler
57
+ class IHandler(IWattleflow, ABC):
58
+ """
59
+ IHandler - Chain of responsibilty abstract interface.
60
+
61
+ Interface:
62
+ set_next(self, handler)
63
+ handle(self, request)
64
+ """
65
+
66
+ @abstractmethod
67
+ def set_next(self, handler: "IHandler"):
68
+ pass
69
+
70
+ @abstractmethod
71
+ def handle(self, request):
72
+ pass
73
+
74
+
75
+ class ICommand(IWattleflow, ABC):
76
+ """
77
+ ICommand - Chain of responsibilty abstract interface.
78
+
79
+ Interface:
80
+ execute(self, *args, **kwargs)
81
+ """
82
+
83
+ @abstractmethod
84
+ def execute(self, *args, **kwargs) -> Any:
85
+ pass
86
+
87
+
88
+ class IInvoker(IWattleflow, ABC):
89
+ """
90
+ IInvoker - Chain of responsibilty abstract interface.
91
+
92
+ Interface:
93
+ set_command(self, command)
94
+ invoke(self)
95
+ """
96
+
97
+ @abstractmethod
98
+ def set_command(self, command: ICommand):
99
+ pass
100
+
101
+ @abstractmethod
102
+ def invoke(self) -> Any:
103
+ pass
104
+
105
+
106
+ # Interpreter Interface
107
+ class IExpression(IWattleflow, ABC):
108
+ """
109
+ IExpression - abstract interface.
110
+
111
+ Interface:
112
+ interpret(self)
113
+ """
114
+
115
+ @abstractmethod
116
+ def interpret(self, context):
117
+ pass
118
+
119
+
120
+ # Iterator interfaces (IIterator, IAsyncIterator)
121
+ # IIterator
122
+ class IIterator(Generic[T], ABC):
123
+ """
124
+ IIterator - Interface for synchronous iterators.
125
+
126
+ Methods:
127
+ - __iter__() -> Iterator[T]: Enables iteration using 'for'.
128
+ - __next__() -> T: Retrieves next item synchronously.
129
+ - create_iterator() -> Iterator[T]: Returns an iterator instance.
130
+ """
131
+
132
+ _cycle: int = 0
133
+ _iterator: Iterator[T] = None # Sinkroni iterator
134
+
135
+ def __iter__(self) -> Iterator[T]:
136
+ return self
137
+
138
+ def __next__(self) -> T:
139
+ """Returns the item synchronously in iteration | StopIteration."""
140
+ try:
141
+ current = next(self._iterator)
142
+ self._cycle += 1
143
+ return current
144
+ except StopIteration:
145
+ raise
146
+
147
+ @abstractmethod
148
+ def create_iterator(self) -> Iterator[T]:
149
+ """
150
+ Must implement: a new instance of the iterator.
151
+ """
152
+ pass
153
+
154
+
155
+ # IAsyncIterator
156
+ class IAsyncIterator(Generic[T], ABC):
157
+ """
158
+ IAsyncIterator - Interface for asynchronous iterators.
159
+ """
160
+
161
+ _cycle: int = 0
162
+ _iterator: AsyncIterator[T] = None
163
+
164
+ def __aiter__(self) -> AsyncIterator[T]:
165
+ return self
166
+
167
+ async def __anext__(self) -> T:
168
+ """Returns the item asynchronously or raises StopAsyncIteration."""
169
+ try:
170
+ current = await anext(self._iterator)
171
+ self._cycle += 1
172
+ return current
173
+ except StopAsyncIteration:
174
+ raise
175
+
176
+ @abstractmethod
177
+ async def create_iterator(self) -> AsyncIterator[T]:
178
+ """Must implement: a new instance of the async iterator."""
179
+ pass
180
+
181
+
182
+ class IAggregate(IWattleflow, Type[IIterator], ABC):
183
+ """
184
+ IAggregate - abstract interface.
185
+
186
+ Interface:
187
+ create_iterator(self) -> IITerator
188
+ """
189
+
190
+ @abstractmethod
191
+ def create_iterator(self) -> IIterator:
192
+ pass
193
+
194
+
195
+ # Mediator interfaces
196
+ class IMediator(IWattleflow, ABC):
197
+ """
198
+ IMediator - abstract interface.
199
+
200
+ Interface:
201
+ notify(self, sender, event)
202
+ """
203
+
204
+ @abstractmethod
205
+ def notify(self, sender, event):
206
+ pass
207
+
208
+
209
+ class IColleague(IWattleflow, ABC):
210
+ """
211
+ IColleage - abstract interface.
212
+
213
+ Interface:
214
+ set_mediator(self, mediator)
215
+ event_occurred(self, event)
216
+ """
217
+
218
+ @abstractmethod
219
+ def set_mediator(self, mediator):
220
+ pass
221
+
222
+ @abstractmethod
223
+ def event_occurred(self, event):
224
+ pass
225
+
226
+
227
+ # Memento Interfaces (IMemento, IOriginator)
228
+ # IMemento
229
+ class IMemento(IWattleflow, ABC):
230
+ """
231
+ IMemento - abstract interface.
232
+
233
+ Interface:
234
+ get_state(self)
235
+ """
236
+
237
+ @abstractmethod
238
+ def get_state(self):
239
+ pass
240
+
241
+
242
+ class IOriginator(IWattleflow, ABC):
243
+ """
244
+ IOriginator - abstract interface.
245
+
246
+ Interface:
247
+ save_state(self)
248
+ restore_state(self, memento)
249
+ """
250
+
251
+ @abstractmethod
252
+ def save_state(self):
253
+ pass
254
+
255
+ @abstractmethod
256
+ def restore_state(self, memento: IMemento):
257
+ pass
258
+
259
+
260
+ # Observer interfaces
261
+ # Reactive Programming Interfaces
262
+ class IObserver(IWattleflow, ABC):
263
+ """
264
+ IObserver - Observer/Reactive Programming Interface desing pattern
265
+ abstract interface.
266
+
267
+ Interface:
268
+ subscribe(self,observer)
269
+ """
270
+
271
+ @abstractmethod
272
+ def update(self, *args, **kwargs):
273
+ pass
274
+
275
+
276
+ class IObservable(IWattleflow, ABC):
277
+ """
278
+ IObservable - Observer/Reactive Programming Interface desing pattern
279
+ abstract interface.
280
+
281
+ Interface:
282
+ subscribe(self, observer: IObserver):
283
+ """
284
+
285
+ @abstractmethod
286
+ def subscribe(self, observer: IObserver):
287
+ pass
288
+
289
+
290
+ # State interfaces
291
+ # State (IState, IStateContext)
292
+ class IState(IWattleflow, ABC):
293
+ """
294
+ IState - State abstract interface.
295
+ """
296
+
297
+ pass
298
+
299
+
300
+ class IStateContext(IWattleflow, ABC):
301
+ """
302
+ IStateContext - State abstract interface.
303
+ """
304
+
305
+ pass
306
+
307
+
308
+ # Strategy interfaces
309
+ # Strategy IStrategy, IStrategyContext
310
+ class IStrategy(IWattleflow, ABC):
311
+ """
312
+ IStrategy - Strategy abstract interface.
313
+ """
314
+
315
+ pass
316
+
317
+ @abstractmethod
318
+ def execute(self, *args, **kwargs):
319
+ pass
320
+
321
+
322
+ class IStrategyContext(IWattleflow, ABC):
323
+ """
324
+ IStrategyContext - Strategy abstract interface.
325
+ """
326
+
327
+ @abstractmethod
328
+ def set_strategy(self, strategy: IStrategy) -> None:
329
+ pass
330
+
331
+ @abstractmethod
332
+ def execute_strategy(self, *args, **kwargs) -> Any:
333
+ pass
334
+
335
+
336
+ # Template method (ITemplate)
337
+ class ITemplate(IWattleflow, ABC):
338
+ def process(self):
339
+ """The template method defining the steps of the process."""
340
+ self.initialise()
341
+ self.perform_task()
342
+ self.finalise()
343
+
344
+ @abstractmethod
345
+ def initialise(self):
346
+ """Step to be implemented by subclasses for initial setup."""
347
+ pass
348
+
349
+ @abstractmethod
350
+ def perform_task(self):
351
+ """The main task to be implemented by subclasses."""
352
+ pass
353
+
354
+ @abstractmethod
355
+ def finalise(self):
356
+ """Step to be implemented by subclasses to clean up or finalise."""
357
+ pass
358
+
359
+
360
+ # Visitor interfaces
361
+ # Visitor (IVisitor IElement)
362
+ class IVisitor(IWattleflow, ABC):
363
+ """
364
+ IVisitor - Abstract interface for Visitor pattern.
365
+ """
366
+
367
+ @abstractmethod
368
+ def visit(self, element: "IElement") -> Any:
369
+ pass
370
+
371
+
372
+ class IElement(IWattleflow, ABC):
373
+ """
374
+ IElement - Abstract interface for elements that accept visitors.
375
+ """
376
+
377
+ @abstractmethod
378
+ def accept(self, visitor: IVisitor):
379
+ pass