DefStream 0.1.9__25-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 (56) hide show
  1. DefStream/Broker/Configuration.py +18 -0
  2. DefStream/Broker/Connection.py +141 -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/Priority.py +26 -0
  9. DefStream/Broker/Protocol.py +45 -0
  10. DefStream/Broker/__init__.py +59 -0
  11. DefStream/Descriptor/DataObject.py +409 -0
  12. DefStream/Descriptor/Types.py +248 -0
  13. DefStream/Descriptor/Value.py +188 -0
  14. DefStream/Descriptor/__init__.py +172 -0
  15. DefStream/Inspector/Extension.py +69 -0
  16. DefStream/Inspector/Extensions/Console.html +373 -0
  17. DefStream/Inspector/Extensions/Console.py +414 -0
  18. DefStream/Inspector/Extensions/Dashboard.html +206 -0
  19. DefStream/Inspector/Extensions/Dashboard.py +124 -0
  20. DefStream/Inspector/Extensions/HealthCheck.py +107 -0
  21. DefStream/Inspector/Extensions/Metrics.py +314 -0
  22. DefStream/Inspector/Extensions/Specifications.py +175 -0
  23. DefStream/Inspector/Extensions/__init__.py +13 -0
  24. DefStream/Inspector/Inspector.py +347 -0
  25. DefStream/Inspector/Response.py +14 -0
  26. DefStream/Inspector/__init__.py +9 -0
  27. DefStream/Validator/Pattern.py +36 -0
  28. DefStream/Validator/Patterns/Array.py +30 -0
  29. DefStream/Validator/Patterns/Common.py +93 -0
  30. DefStream/Validator/Patterns/Compare.py +180 -0
  31. DefStream/Validator/Patterns/Condition.py +60 -0
  32. DefStream/Validator/Patterns/DataObject.py +85 -0
  33. DefStream/Validator/Patterns/DateTime.py +111 -0
  34. DefStream/Validator/Patterns/Number.py +43 -0
  35. DefStream/Validator/Patterns/Object.py +150 -0
  36. DefStream/Validator/Patterns/Size.py +110 -0
  37. DefStream/Validator/Patterns/String.py +85 -0
  38. DefStream/Validator/Patterns/Type.py +350 -0
  39. DefStream/Validator/Patterns/__init__.py +137 -0
  40. DefStream/Validator/Validate.py +29 -0
  41. DefStream/Validator/Validator.py +30 -0
  42. DefStream/Validator/__init__.py +11 -0
  43. DefStream/Worker/Executor.py +371 -0
  44. DefStream/Worker/Message.py +180 -0
  45. DefStream/Worker/Pool.py +245 -0
  46. DefStream/Worker/Run.py +311 -0
  47. DefStream/Worker/Specification.py +91 -0
  48. DefStream/Worker/Startup.py +135 -0
  49. DefStream/Worker/Worker.py +416 -0
  50. DefStream/Worker/__init__.py +47 -0
  51. DefStream/__init__.py +0 -0
  52. defstream-0.1.9.dist-info/METADATA +674 -0
  53. defstream-0.1.9.dist-info/RECORD +56 -0
  54. defstream-0.1.9.dist-info/WHEEL +6 -0
  55. defstream-0.1.9.dist-info/licenses/LICENSE +674 -0
  56. defstream-0.1.9.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,141 @@
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
+ 'BrokerFactory',
18
+ 'GetExchange',
19
+ 'GetQueue',
20
+ 'GetStream',
21
+ 'GetConsumer',
22
+ 'Declarable',
23
+ 'Emittable',
24
+ 'Requestable',
25
+ 'PrioritySupport',
26
+ )
27
+
28
+
29
+ class Connection(Protocol):
30
+ @abstractmethod
31
+ def connect(self) -> None: ...
32
+
33
+ @abstractmethod
34
+ def close(self) -> None: ...
35
+
36
+
37
+ class BrokerFactory(Protocol):
38
+ """호출마다 독립적인 새 브로커 연결을 반환하는 팩터리 계약."""
39
+
40
+ @abstractmethod
41
+ def __call__(self) -> Connection: ...
42
+
43
+
44
+ @runtime_checkable
45
+ class GetExchange(Protocol):
46
+ @abstractmethod
47
+ def exchange(
48
+ self,
49
+ name: str,
50
+ /,
51
+ ) -> Sendable: ...
52
+
53
+
54
+ @runtime_checkable
55
+ class GetQueue(Protocol):
56
+ @abstractmethod
57
+ def queue(
58
+ self,
59
+ name: str,
60
+ /,
61
+ ) -> Sendable: ...
62
+
63
+
64
+ @runtime_checkable
65
+ class GetStream(Protocol):
66
+ @abstractmethod
67
+ def stream(
68
+ self,
69
+ name: str,
70
+ /,
71
+ ) -> Sendable: ...
72
+
73
+
74
+ @runtime_checkable
75
+ class GetConsumer(Protocol):
76
+ @abstractmethod
77
+ def consumer(
78
+ self,
79
+ handler: Optional[EventHandler] = None,
80
+ ) -> Consumer: ...
81
+
82
+
83
+ @runtime_checkable
84
+ class Declarable(Protocol):
85
+ @abstractmethod
86
+ def declare(
87
+ self,
88
+ parameters: Any,
89
+ ) -> None: ...
90
+
91
+
92
+ @runtime_checkable
93
+ class Emittable(Protocol):
94
+ @abstractmethod
95
+ def emit(
96
+ self,
97
+ body: Any,
98
+ parameters: Any,
99
+ ) -> Any: ...
100
+
101
+
102
+ @runtime_checkable
103
+ class Requestable(Protocol):
104
+ @abstractmethod
105
+ def request(
106
+ self,
107
+ body: Any,
108
+ parameters: Any,
109
+ timeout: float = 5,
110
+ ) -> Any: ...
111
+
112
+
113
+ @runtime_checkable
114
+ class PrioritySupport(
115
+ Emittable,
116
+ Requestable,
117
+ Protocol,
118
+ ):
119
+ """작업 구독 설정의 우선순위 처리와 우선순위 발행을 지원하는 계약."""
120
+
121
+ def priority_parameters(
122
+ self,
123
+ parameters: Any,
124
+ ) -> Any: ...
125
+
126
+ def emit(
127
+ self,
128
+ body: Any,
129
+ parameters: Any,
130
+ *,
131
+ priority: Optional[int] = None,
132
+ ) -> Any: ...
133
+
134
+ def request(
135
+ self,
136
+ body: Any,
137
+ parameters: Any,
138
+ timeout: float = 5,
139
+ *,
140
+ priority: Optional[int] = None,
141
+ ) -> 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,26 @@
1
+ from typing import Optional
2
+
3
+
4
+ def validate_priority(
5
+ value: Optional[int],
6
+ maximum: Optional[int],
7
+ *,
8
+ minimum: int = 0,
9
+ name: str = 'priority',
10
+ ) -> None:
11
+ """우선순위 타입과 범위를 검증하며, 최대값이 없으면 하한만 검사한다."""
12
+ if value is None:
13
+ return
14
+ if isinstance(
15
+ value,
16
+ bool,
17
+ ) or not isinstance(
18
+ value,
19
+ int,
20
+ ):
21
+ raise TypeError(name + ' must be an integer or None')
22
+ if value < minimum:
23
+ raise ValueError(f'{name} must be at least {minimum}')
24
+ if maximum is not None and value > maximum:
25
+ raise ValueError(f'{name} must be between {minimum} and {maximum}')
26
+ return
@@ -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,59 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .Configuration import Configuration
4
+ from .Connection import (
5
+ Connection,
6
+ BrokerFactory,
7
+ GetExchange,
8
+ GetQueue,
9
+ GetStream,
10
+ GetConsumer,
11
+ Declarable,
12
+ Emittable,
13
+ Requestable,
14
+ PrioritySupport,
15
+ )
16
+ from .Protocol import (
17
+ Sendable,
18
+ Callable,
19
+ Poppable,
20
+ Readable,
21
+ )
22
+ from .Errors import RemoteError
23
+ from .Consumer import Consumer
24
+ from .Policies import (
25
+ Requeue,
26
+ Reject,
27
+ )
28
+ from .Priority import validate_priority
29
+ from .Event import (
30
+ Event,
31
+ EventHandler,
32
+ EventError,
33
+ )
34
+
35
+ __all__ = (
36
+ 'Configuration',
37
+ 'Connection',
38
+ 'BrokerFactory',
39
+ 'GetExchange',
40
+ 'GetQueue',
41
+ 'GetStream',
42
+ 'GetConsumer',
43
+ 'Declarable',
44
+ 'Emittable',
45
+ 'Requestable',
46
+ 'PrioritySupport',
47
+ 'Sendable',
48
+ 'Callable',
49
+ 'RemoteError',
50
+ 'Poppable',
51
+ 'Readable',
52
+ 'Consumer',
53
+ 'EventHandler',
54
+ 'Event',
55
+ 'EventError',
56
+ 'Requeue',
57
+ 'Reject',
58
+ 'validate_priority',
59
+ )