orionis 0.472.0__py3-none-any.whl → 0.473.0__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,407 @@
1
+ from abc import ABC, abstractmethod
2
+ import asyncio
3
+
4
+ class ITestService(ABC):
5
+ """
6
+ Interface for a test service that provides a method to retrieve a message.
7
+
8
+ Methods
9
+ -------
10
+ get_message() : str
11
+ Retrieve a message as a string.
12
+
13
+ Returns
14
+ -------
15
+ str
16
+ The message provided by the service.
17
+ """
18
+
19
+ @abstractmethod
20
+ def get_message(self) -> str:
21
+ """
22
+ Retrieve a message as a string.
23
+
24
+ Returns
25
+ -------
26
+ str
27
+ The message provided by the service.
28
+ """
29
+ pass
30
+
31
+ class TestService(ITestService):
32
+ """
33
+ Concrete implementation of ITestService for synchronous operations.
34
+
35
+ Methods
36
+ -------
37
+ get_message() : str
38
+ Returns a greeting message from the synchronous test service.
39
+
40
+ Returns
41
+ -------
42
+ str
43
+ A greeting message from the synchronous service.
44
+ """
45
+
46
+ def get_message(self) -> str:
47
+ """
48
+ Returns a greeting message from the synchronous service.
49
+
50
+ Returns
51
+ -------
52
+ str
53
+ A greeting message from the synchronous service.
54
+ """
55
+ return "Hello from sync service"
56
+
57
+ class ITestServiceWithDependency(ABC):
58
+ """
59
+ Interface for a test service that depends on other components.
60
+
61
+ Methods
62
+ -------
63
+ get_combined_message() : str
64
+ Returns a combined message from the service and its dependencies.
65
+
66
+ Returns
67
+ -------
68
+ str
69
+ The combined message generated by the service and its dependencies.
70
+ """
71
+
72
+ @abstractmethod
73
+ def get_combined_message(self) -> str:
74
+ """
75
+ Returns a combined message as a string.
76
+
77
+ Returns
78
+ -------
79
+ str
80
+ The combined message generated by the service and its dependencies.
81
+ """
82
+ pass
83
+
84
+ class TestServiceWithDependency(ITestServiceWithDependency):
85
+ """
86
+ Test service class that depends on another service implementing ITestService.
87
+
88
+ This class demonstrates dependency injection by accepting an instance of ITestService
89
+ in its constructor and providing a method to return a combined message.
90
+
91
+ Parameters
92
+ ----------
93
+ service : ITestService
94
+ An instance of a service implementing the ITestService interface.
95
+
96
+ Methods
97
+ -------
98
+ get_combined_message() : str
99
+ Returns a string that combines a prefix with the message from the injected service.
100
+
101
+ Returns
102
+ -------
103
+ str
104
+ The combined message string.
105
+ """
106
+
107
+ def __init__(self, service: ITestService):
108
+ """
109
+ Initialize the class with the provided service.
110
+
111
+ Parameters
112
+ ----------
113
+ service : ITestService
114
+ An instance of ITestService to be used by this class.
115
+ """
116
+ self.service = service
117
+
118
+ def get_combined_message(self) -> str:
119
+ """
120
+ Returns a combined message string by prefixing the message from the service with 'Combined:'.
121
+
122
+ Returns
123
+ -------
124
+ str
125
+ The combined message string, prefixed with 'Combined:'.
126
+ """
127
+ return f"Combined: {self.service.get_message()}"
128
+
129
+ class IAsyncTestService(ABC):
130
+ """
131
+ Abstract base class that defines the interface for an asynchronous test service.
132
+
133
+ Methods
134
+ -------
135
+ get_async_message() : str
136
+ Asynchronously retrieves a message as a string.
137
+
138
+ Returns
139
+ -------
140
+ str
141
+ The message provided by the asynchronous service.
142
+ """
143
+
144
+ @abstractmethod
145
+ async def get_async_message(self) -> str:
146
+ """
147
+ Asynchronously retrieve a message as a string.
148
+
149
+ Returns
150
+ -------
151
+ str
152
+ The message provided by the asynchronous service.
153
+ """
154
+ pass
155
+
156
+ class AsyncTestService(IAsyncTestService):
157
+ """
158
+ Provides asynchronous test operations for demonstration purposes.
159
+
160
+ Methods
161
+ -------
162
+ get_async_message() : str
163
+ Asynchronously returns a test message after a short delay.
164
+
165
+ Returns
166
+ -------
167
+ str
168
+ A greeting message from the async service.
169
+ """
170
+
171
+ async def get_async_message(self) -> str:
172
+ """
173
+ Asynchronously retrieves a message after a short delay.
174
+
175
+ Returns
176
+ -------
177
+ str
178
+ A greeting message from the async service.
179
+ """
180
+ # Simulate asynchronous operation with a short delay
181
+ await asyncio.sleep(0.1)
182
+ return "Hello from async service"
183
+
184
+ class IAsyncTestServiceWithDependency(ABC):
185
+ """
186
+ An abstract base class representing an asynchronous test service with dependencies.
187
+ This interface defines a contract for services that provide a combined asynchronous message,
188
+ potentially aggregating results from dependent services.
189
+ Methods
190
+ -------
191
+ get_combined_async_message() -> str
192
+ Asynchronously retrieves a combined message from the service and its dependencies.
193
+ """
194
+
195
+ @abstractmethod
196
+ async def get_combined_async_message(self) -> str:
197
+ """
198
+ Asynchronously retrieves and returns a combined message as a string.
199
+
200
+ Returns:
201
+ str: The combined asynchronous message.
202
+ """
203
+ pass
204
+
205
+ class AsyncTestServiceWithDependency(IAsyncTestServiceWithDependency):
206
+ """
207
+ AsyncTestServiceWithDependency is a service class that depends on another asynchronous test service.
208
+
209
+ Parameters
210
+ ----------
211
+ service : IAsyncTestService
212
+ An instance of a service implementing asynchronous message retrieval.
213
+
214
+ Methods
215
+ -------
216
+ get_combined_async_message() -> str
217
+ Asynchronously retrieves a message from the dependent service and returns it combined with a prefix.
218
+ """
219
+
220
+ def __init__(self, service: IAsyncTestService):
221
+ """
222
+ Initialize the AsyncTestServiceWithDependency with the provided asynchronous test service.
223
+
224
+ Parameters
225
+ ----------
226
+ service : IAsyncTestService
227
+ An instance of the asynchronous test service to be used by this class.
228
+ """
229
+
230
+ # Store the dependency for later use
231
+ self.service = service
232
+
233
+ async def get_combined_async_message(self) -> str:
234
+ """
235
+ Asynchronously retrieve a message from the dependent service and return it combined with a prefix.
236
+
237
+ This method awaits the asynchronous message retrieval from the injected service and then
238
+ formats the result by prefixing it with 'Combined: '.
239
+
240
+ Returns
241
+ -------
242
+ str
243
+ The combined message in the format "Combined: <message>", where <message> is the result
244
+ from the dependent asynchronous service.
245
+ """
246
+
247
+ # Await the asynchronous message from the dependency
248
+ msg = await self.service.get_async_message()
249
+
250
+ # Combine the prefix with the retrieved message
251
+ return f"Combined: {msg}"
252
+
253
+ class MixedService:
254
+ """
255
+ Service that combines both synchronous and asynchronous test services.
256
+
257
+ This class demonstrates how to work with both sync and async dependencies,
258
+ providing methods to retrieve messages from each and a combined result.
259
+
260
+ Parameters
261
+ ----------
262
+ sync_service : ITestService
263
+ An instance of a synchronous test service.
264
+ async_service : IAsyncTestService
265
+ An instance of an asynchronous test service.
266
+ """
267
+
268
+ def __init__(self, sync_service: ITestService, async_service: IAsyncTestService):
269
+ """
270
+ Initialize MixedService with synchronous and asynchronous service dependencies.
271
+
272
+ Parameters
273
+ ----------
274
+ sync_service : ITestService
275
+ The synchronous service dependency.
276
+ async_service : IAsyncTestService
277
+ The asynchronous service dependency.
278
+ """
279
+ self.sync_service = sync_service
280
+ self.async_service = async_service
281
+
282
+ def get_sync_message(self) -> str:
283
+ """
284
+ Retrieve a message from the synchronous service and prefix it.
285
+
286
+ Returns
287
+ -------
288
+ str
289
+ The message from the synchronous service, prefixed with 'Mixed sync:'.
290
+ """
291
+
292
+ # Get message from the synchronous service and add a prefix
293
+ return f"Mixed sync: {self.sync_service.get_message()}"
294
+
295
+ async def get_async_message(self) -> str:
296
+ """
297
+ Asynchronously retrieve a message from the asynchronous service and prefix it.
298
+
299
+ Returns
300
+ -------
301
+ str
302
+ The message from the asynchronous service, prefixed with 'Mixed async:'.
303
+ """
304
+
305
+ # Await the message from the asynchronous service and add a prefix
306
+ async_msg = await self.async_service.get_async_message()
307
+ return f"Mixed async: {async_msg}"
308
+
309
+ async def get_both_messages(self) -> str:
310
+ """
311
+ Retrieve messages from both the synchronous and asynchronous services and combine them.
312
+
313
+ This method fetches the synchronous message and awaits the asynchronous message,
314
+ then returns a formatted string containing both.
315
+
316
+ Returns
317
+ -------
318
+ str
319
+ A combined string in the format "Both: sync='<sync_msg>', async='<async_msg>'".
320
+ """
321
+
322
+ # Get the synchronous message
323
+ sync_msg = self.sync_service.get_message()
324
+
325
+ # Await the asynchronous message
326
+ async_msg = await self.async_service.get_async_message()
327
+
328
+ # Combine both messages in a formatted string
329
+ return f"Both: sync='{sync_msg}', async='{async_msg}'"
330
+
331
+ def sync_callable() -> str:
332
+ """
333
+ Returns a fixed string result from a synchronous callable.
334
+
335
+ This function demonstrates a simple synchronous callable that does not take any arguments
336
+ and returns a static string value.
337
+
338
+ Returns
339
+ -------
340
+ str
341
+ The result string from the synchronous callable, specifically "Sync callable result".
342
+ """
343
+ # Return a static string result
344
+ return "Sync callable result"
345
+
346
+ async def async_callable() -> str:
347
+ """
348
+ Asynchronously performs a simulated I/O-bound operation and returns a result string.
349
+
350
+ This coroutine simulates an asynchronous operation by awaiting a short delay,
351
+ then returns a static string value.
352
+
353
+ Returns
354
+ -------
355
+ str
356
+ The result of the asynchronous operation after a short delay, specifically "Async callable result".
357
+ """
358
+ # Simulate an asynchronous I/O operation with a short delay
359
+ await asyncio.sleep(0.1)
360
+ # Return a static string result
361
+ return "Async callable result"
362
+
363
+ def sync_callable_with_dependency(service: ITestService) -> str:
364
+ """
365
+ Returns a formatted message using a provided ITestService dependency.
366
+
367
+ This synchronous callable accepts an instance of ITestService, retrieves its message,
368
+ and returns a formatted string containing that message.
369
+
370
+ Parameters
371
+ ----------
372
+ service : ITestService
373
+ An instance of a service implementing the ITestService interface.
374
+
375
+ Returns
376
+ -------
377
+ str
378
+ A string containing the message from the provided service, formatted as
379
+ "Callable with dependency: <service_message>".
380
+ """
381
+ # Retrieve the message from the dependency and format it
382
+ return f"Callable with dependency: {service.get_message()}"
383
+
384
+ async def async_callable_with_dependency(service: IAsyncTestService) -> str:
385
+ """
386
+ Asynchronously retrieves and formats a message from a provided IAsyncTestService dependency.
387
+
388
+ This coroutine awaits the asynchronous message retrieval from the given service,
389
+ then returns a formatted string containing that message.
390
+
391
+ Parameters
392
+ ----------
393
+ service : IAsyncTestService
394
+ An instance of a service implementing the asynchronous `get_async_message` method.
395
+
396
+ Returns
397
+ -------
398
+ str
399
+ A formatted string containing the message retrieved from the service, in the form
400
+ "Async callable with dependency: <service_message>".
401
+ """
402
+
403
+ # Await the asynchronous message from the dependency
404
+ msg = await service.get_async_message()
405
+
406
+ # Return the formatted result
407
+ return f"Async callable with dependency: {msg}"