DefStream 0.1.2__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.
Files changed (54) hide show
  1. DefStream/Broker/Configuration.py +18 -0
  2. DefStream/Broker/Connection.py +97 -0
  3. DefStream/Broker/Consumer.py +59 -0
  4. DefStream/Broker/Errors.py +14 -0
  5. DefStream/Broker/Event.py +35 -0
  6. DefStream/Broker/Implements/__init__.py +1 -0
  7. DefStream/Broker/Policies.py +25 -0
  8. DefStream/Broker/Protocol.py +45 -0
  9. DefStream/Broker/__init__.py +47 -0
  10. DefStream/Descriptor/DataObject.py +384 -0
  11. DefStream/Descriptor/Types.py +229 -0
  12. DefStream/Descriptor/Value.py +132 -0
  13. DefStream/Descriptor/__init__.py +172 -0
  14. DefStream/Inspector/Extension.py +69 -0
  15. DefStream/Inspector/Extensions/Console.html +373 -0
  16. DefStream/Inspector/Extensions/Console.py +396 -0
  17. DefStream/Inspector/Extensions/Dashboard.html +206 -0
  18. DefStream/Inspector/Extensions/Dashboard.py +114 -0
  19. DefStream/Inspector/Extensions/HealthCheck.py +92 -0
  20. DefStream/Inspector/Extensions/Metrics.py +281 -0
  21. DefStream/Inspector/Extensions/Specifications.py +160 -0
  22. DefStream/Inspector/Extensions/__init__.py +13 -0
  23. DefStream/Inspector/Inspector.py +216 -0
  24. DefStream/Inspector/Response.py +14 -0
  25. DefStream/Inspector/__init__.py +9 -0
  26. DefStream/Validator/Pattern.py +36 -0
  27. DefStream/Validator/Patterns/Array.py +30 -0
  28. DefStream/Validator/Patterns/Common.py +93 -0
  29. DefStream/Validator/Patterns/Compare.py +180 -0
  30. DefStream/Validator/Patterns/Condition.py +60 -0
  31. DefStream/Validator/Patterns/DataObject.py +85 -0
  32. DefStream/Validator/Patterns/DateTime.py +111 -0
  33. DefStream/Validator/Patterns/Number.py +43 -0
  34. DefStream/Validator/Patterns/Object.py +150 -0
  35. DefStream/Validator/Patterns/Size.py +110 -0
  36. DefStream/Validator/Patterns/String.py +85 -0
  37. DefStream/Validator/Patterns/Type.py +350 -0
  38. DefStream/Validator/Patterns/__init__.py +137 -0
  39. DefStream/Validator/Validate.py +29 -0
  40. DefStream/Validator/Validator.py +30 -0
  41. DefStream/Validator/__init__.py +11 -0
  42. DefStream/Worker/Executor.py +298 -0
  43. DefStream/Worker/Message.py +103 -0
  44. DefStream/Worker/Pool.py +203 -0
  45. DefStream/Worker/Run.py +187 -0
  46. DefStream/Worker/Specification.py +91 -0
  47. DefStream/Worker/Worker.py +321 -0
  48. DefStream/Worker/__init__.py +49 -0
  49. DefStream/__init__.py +0 -0
  50. defstream-0.1.2.dist-info/METADATA +1197 -0
  51. defstream-0.1.2.dist-info/RECORD +54 -0
  52. defstream-0.1.2.dist-info/WHEEL +5 -0
  53. defstream-0.1.2.dist-info/licenses/LICENSE +674 -0
  54. defstream-0.1.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from abc import (
4
+ ABCMeta,
5
+ abstractmethod,
6
+ )
7
+
8
+ __all__ = (
9
+ 'Configuration'
10
+ )
11
+
12
+
13
+ class Configuration(metaclass=ABCMeta):
14
+ """Configuration Interface for Event Broker"""
15
+ @abstractmethod
16
+ def __init__(self, *args, **kwargs):
17
+ raise NotImplementedError('{} must be implemented __init__'.format(self.__class__.__name__))
18
+
@@ -0,0 +1,97 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from abc import abstractmethod
4
+ from typing import (
5
+ Any,
6
+ Optional,
7
+ Protocol,
8
+ runtime_checkable,
9
+ )
10
+
11
+ from .Consumer import Consumer
12
+ from .Event import EventHandler
13
+ from .Protocol import Sendable
14
+
15
+ __all__ = (
16
+ 'Connection',
17
+ 'GetExchange',
18
+ 'GetQueue',
19
+ 'GetStream',
20
+ 'GetConsumer',
21
+ 'Declarable',
22
+ 'TaskSender',
23
+ 'Requestable',
24
+ )
25
+
26
+
27
+ class Connection(Protocol):
28
+ @abstractmethod
29
+ def connect(self) -> None: ...
30
+
31
+ @abstractmethod
32
+ def close(self) -> None: ...
33
+
34
+
35
+ class GetExchange(Protocol):
36
+ @abstractmethod
37
+ def exchange(
38
+ self,
39
+ name: str,
40
+ /,
41
+ ) -> Sendable: ...
42
+
43
+
44
+ class GetQueue(Protocol):
45
+ @abstractmethod
46
+ def queue(
47
+ self,
48
+ name: str,
49
+ /,
50
+ ) -> Sendable: ...
51
+
52
+
53
+ class GetStream(Protocol):
54
+ @abstractmethod
55
+ def stream(
56
+ self,
57
+ name: str,
58
+ /,
59
+ ) -> Sendable: ...
60
+
61
+
62
+ class GetConsumer(Protocol):
63
+ @abstractmethod
64
+ def consumer(
65
+ self,
66
+ handler: Optional[EventHandler] = None,
67
+ ) -> Consumer: ...
68
+
69
+
70
+ @runtime_checkable
71
+ class Declarable(Protocol):
72
+ @abstractmethod
73
+ def declare(
74
+ self,
75
+ parameters: Any,
76
+ ) -> None: ...
77
+
78
+
79
+ @runtime_checkable
80
+ class TaskSender(Protocol):
81
+ @abstractmethod
82
+ def send(
83
+ self,
84
+ body: Any,
85
+ parameters: Any,
86
+ ) -> Any: ...
87
+
88
+
89
+ @runtime_checkable
90
+ class Requestable(Protocol):
91
+ @abstractmethod
92
+ def request(
93
+ self,
94
+ body: Any,
95
+ parameters: Any,
96
+ timeout: float = 5,
97
+ ) -> Any: ...
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from abc import (
4
+ ABCMeta,
5
+ abstractmethod,
6
+ )
7
+ from typing import (
8
+ Any,
9
+ Callable,
10
+ Optional,
11
+ )
12
+
13
+ from .Event import (
14
+ Event,
15
+ EventHandler,
16
+ EventError,
17
+ )
18
+
19
+ __all__ = (
20
+ 'Consumer'
21
+ )
22
+
23
+
24
+ class Consumer(metaclass=ABCMeta):
25
+ """Consumer Interface of Event Broker"""
26
+ def complete(
27
+ self,
28
+ event: Event,
29
+ result: Any,
30
+ ) -> None:
31
+ event.ack()
32
+
33
+ def call(self, callback: Callable[[], None]) -> None:
34
+ """Schedule a callback on the connection owner thread."""
35
+ raise NotImplementedError('Consumer must implement thread-safe callback scheduling')
36
+
37
+ def fail(
38
+ self,
39
+ event: Event,
40
+ policy: Optional[EventError] = None,
41
+ ) -> None:
42
+ raise NotImplementedError('Consumer must implement failure policies')
43
+
44
+ def close(self) -> None:
45
+ raise NotImplementedError('Consumer must implement close')
46
+
47
+ @abstractmethod
48
+ def subs(
49
+ self,
50
+ queue: Any,
51
+ handler: Optional[EventHandler] = None,
52
+ ) -> None:
53
+ raise NotImplementedError('{} must implement subs'.format(self.__class__.__name__))
54
+ @abstractmethod
55
+ def run(self):
56
+ raise NotImplementedError('{} must be implemented run'.format(self.__class__.__name__))
57
+ @abstractmethod
58
+ def stop(self):
59
+ raise NotImplementedError('{} must be implemented stop'.format(self.__class__.__name__))
@@ -0,0 +1,14 @@
1
+ __all__ = (
2
+ 'RemoteError',
3
+ )
4
+
5
+
6
+ class RemoteError(RuntimeError):
7
+ def __init__(
8
+ self,
9
+ code: str,
10
+ message: str,
11
+ ):
12
+ self.code = code
13
+ self.message = message
14
+ super().__init__(f'{code}: {message}')
@@ -0,0 +1,35 @@
1
+ from abc import abstractmethod
2
+ from typing import (
3
+ Any,
4
+ Protocol,
5
+ )
6
+
7
+ __all__ = (
8
+ 'Event',
9
+ 'EventHandler',
10
+ 'EventError',
11
+ )
12
+
13
+
14
+ class Event(Protocol):
15
+ @property
16
+ def body(self) -> Any: ...
17
+
18
+ def ack(self) -> None: ...
19
+ def nack(self) -> None: ...
20
+ def reject(self) -> None: ...
21
+
22
+
23
+ class EventHandler(Protocol):
24
+ @abstractmethod
25
+ def __call__(
26
+ self,
27
+ event: Event,
28
+ ) -> None: ...
29
+
30
+
31
+ class EventError(Protocol):
32
+ def __call__(
33
+ self,
34
+ event: Event,
35
+ ) -> None: ...
@@ -0,0 +1 @@
1
+ # -*- coding: utf-8 -*-
@@ -0,0 +1,25 @@
1
+ from .Event import (
2
+ Event,
3
+ EventError,
4
+ )
5
+
6
+ __all__ = (
7
+ 'Requeue',
8
+ 'Reject',
9
+ )
10
+
11
+
12
+ class Requeue(EventError):
13
+ def __call__(
14
+ self,
15
+ event: Event,
16
+ ) -> None:
17
+ event.nack()
18
+
19
+
20
+ class Reject(EventError):
21
+ def __call__(
22
+ self,
23
+ event: Event,
24
+ ) -> None:
25
+ event.reject()
@@ -0,0 +1,45 @@
1
+ from typing import (
2
+ Any,
3
+ Iterable,
4
+ Optional,
5
+ Protocol,
6
+ )
7
+
8
+ from .Event import Event
9
+
10
+ __all__ = (
11
+ 'Sendable',
12
+ 'Callable',
13
+ 'Poppable',
14
+ 'Readable',
15
+ )
16
+
17
+
18
+ class Sendable(Protocol):
19
+ def send(
20
+ self,
21
+ body: Any,
22
+ ) -> Any: ...
23
+
24
+
25
+ class Callable(Protocol):
26
+ def call(
27
+ self,
28
+ body: Any,
29
+ timeout: float = 5,
30
+ ) -> Any: ...
31
+
32
+
33
+ class Poppable(Protocol):
34
+ def pop(
35
+ self,
36
+ timeout: Optional[int] = None,
37
+ ) -> Optional[Event]: ...
38
+
39
+
40
+ class Readable(Protocol):
41
+ def read(
42
+ self,
43
+ offset: int = 0,
44
+ timeout: Optional[int] = None,
45
+ ) -> Iterable[Event]: ...
@@ -0,0 +1,47 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Configuration import Configuration
4
+ from .Connection import (
5
+ Connection,
6
+ GetExchange,
7
+ GetQueue,
8
+ GetStream,
9
+ GetConsumer,
10
+ Declarable,
11
+ TaskSender,
12
+ Requestable,
13
+ )
14
+ from .Protocol import (
15
+ Sendable,
16
+ Callable,
17
+ Poppable,
18
+ Readable,
19
+ )
20
+ from .Errors import RemoteError
21
+ from .Consumer import Consumer
22
+ from .Event import (
23
+ Event,
24
+ EventHandler,
25
+ EventError,
26
+ )
27
+
28
+ __all__ = (
29
+ 'Configuration',
30
+ 'Connection',
31
+ 'GetExchange',
32
+ 'GetQueue',
33
+ 'GetStream',
34
+ 'GetConsumer',
35
+ 'Declarable',
36
+ 'TaskSender',
37
+ 'Requestable',
38
+ 'Sendable',
39
+ 'Callable',
40
+ 'RemoteError',
41
+ 'Poppable',
42
+ 'Readable',
43
+ 'Consumer',
44
+ 'EventHandler',
45
+ 'Event',
46
+ 'EventError',
47
+ )