DefStream 0.1.27__119-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.
- DefStream/Broker/Configuration.py +17 -0
- DefStream/Broker/Connection.py +176 -0
- DefStream/Broker/Consumer.py +59 -0
- DefStream/Broker/Errors.py +14 -0
- DefStream/Broker/Event.py +35 -0
- DefStream/Broker/Implements/__init__.py +1 -0
- DefStream/Broker/Priority.py +26 -0
- DefStream/Broker/Protocol.py +54 -0
- DefStream/Broker/__init__.py +61 -0
- DefStream/Descriptor/DataObject.py +409 -0
- DefStream/Descriptor/Types.py +248 -0
- DefStream/Descriptor/Value.py +188 -0
- DefStream/Descriptor/__init__.py +172 -0
- DefStream/Inspector/Extension.py +69 -0
- DefStream/Inspector/Extensions/Metrics.py +316 -0
- DefStream/Inspector/Extensions/Ping.py +107 -0
- DefStream/Inspector/Extensions/Play.html +373 -0
- DefStream/Inspector/Extensions/Play.py +415 -0
- DefStream/Inspector/Extensions/Specifications.py +176 -0
- DefStream/Inspector/Extensions/Status.html +206 -0
- DefStream/Inspector/Extensions/Status.py +124 -0
- DefStream/Inspector/Extensions/__init__.py +13 -0
- DefStream/Inspector/Inspector.py +357 -0
- DefStream/Inspector/Response.py +14 -0
- DefStream/Inspector/__init__.py +9 -0
- DefStream/Validator/Pattern.py +36 -0
- DefStream/Validator/Patterns/Array.py +30 -0
- DefStream/Validator/Patterns/Common.py +92 -0
- DefStream/Validator/Patterns/Compare.py +180 -0
- DefStream/Validator/Patterns/Condition.py +60 -0
- DefStream/Validator/Patterns/DataObject.py +93 -0
- DefStream/Validator/Patterns/DateTime.py +111 -0
- DefStream/Validator/Patterns/Number.py +43 -0
- DefStream/Validator/Patterns/Object.py +158 -0
- DefStream/Validator/Patterns/Size.py +110 -0
- DefStream/Validator/Patterns/String.py +92 -0
- DefStream/Validator/Patterns/Type.py +355 -0
- DefStream/Validator/Patterns/__init__.py +137 -0
- DefStream/Validator/Validate.py +29 -0
- DefStream/Validator/Validator.py +30 -0
- DefStream/Validator/__init__.py +11 -0
- DefStream/Worker/Executor.py +525 -0
- DefStream/Worker/Message.py +260 -0
- DefStream/Worker/Pool.py +282 -0
- DefStream/Worker/Run.py +357 -0
- DefStream/Worker/Specification.py +87 -0
- DefStream/Worker/Startup.py +174 -0
- DefStream/Worker/Worker.py +571 -0
- DefStream/Worker/__init__.py +47 -0
- DefStream/__init__.py +0 -0
- defstream-0.1.27.dist-info/METADATA +94 -0
- defstream-0.1.27.dist-info/RECORD +55 -0
- defstream-0.1.27.dist-info/WHEEL +6 -0
- defstream-0.1.27.dist-info/licenses/LICENSE +674 -0
- defstream-0.1.27.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
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__))
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
'Timer',
|
|
19
|
+
'TimerCallback',
|
|
20
|
+
'SetTimer',
|
|
21
|
+
'GetExchange',
|
|
22
|
+
'GetQueue',
|
|
23
|
+
'GetStream',
|
|
24
|
+
'GetConsumer',
|
|
25
|
+
'Declarable',
|
|
26
|
+
'Emittable',
|
|
27
|
+
'Requestable',
|
|
28
|
+
'PrioritySupport',
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Connection(Protocol):
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def connect(self) -> None: ...
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def close(self) -> None: ...
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class BrokerFactory(Protocol):
|
|
41
|
+
"""호출마다 독립적인 새 브로커 연결을 반환하는 팩터리 계약."""
|
|
42
|
+
|
|
43
|
+
@abstractmethod
|
|
44
|
+
def __call__(self) -> Connection: ...
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@runtime_checkable
|
|
48
|
+
class Timer(Protocol):
|
|
49
|
+
"""
|
|
50
|
+
Cancelable timer handle.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def remove(self) -> None: ...
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class TimerCallback(Protocol):
|
|
58
|
+
"""
|
|
59
|
+
Callback invoked when a timer expires.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
def __call__(self) -> None: ...
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@runtime_checkable
|
|
66
|
+
class SetTimer(Protocol):
|
|
67
|
+
"""
|
|
68
|
+
Connection capability for registering one-shot timers.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
@abstractmethod
|
|
72
|
+
def set_timer(
|
|
73
|
+
self,
|
|
74
|
+
cb: TimerCallback,
|
|
75
|
+
seconds: int,
|
|
76
|
+
) -> Timer: ...
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@runtime_checkable
|
|
80
|
+
class GetExchange(Protocol):
|
|
81
|
+
@abstractmethod
|
|
82
|
+
def exchange(
|
|
83
|
+
self,
|
|
84
|
+
name: str,
|
|
85
|
+
/,
|
|
86
|
+
) -> Sendable: ...
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@runtime_checkable
|
|
90
|
+
class GetQueue(Protocol):
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def queue(
|
|
93
|
+
self,
|
|
94
|
+
name: str,
|
|
95
|
+
/,
|
|
96
|
+
) -> Sendable: ...
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@runtime_checkable
|
|
100
|
+
class GetStream(Protocol):
|
|
101
|
+
@abstractmethod
|
|
102
|
+
def stream(
|
|
103
|
+
self,
|
|
104
|
+
name: str,
|
|
105
|
+
/,
|
|
106
|
+
) -> Sendable: ...
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@runtime_checkable
|
|
110
|
+
class GetConsumer(Protocol):
|
|
111
|
+
@abstractmethod
|
|
112
|
+
def consumer(
|
|
113
|
+
self,
|
|
114
|
+
handler: Optional[EventHandler] = None,
|
|
115
|
+
) -> Consumer: ...
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@runtime_checkable
|
|
119
|
+
class Declarable(Protocol):
|
|
120
|
+
@abstractmethod
|
|
121
|
+
def declare(
|
|
122
|
+
self,
|
|
123
|
+
parameters: Any,
|
|
124
|
+
) -> None: ...
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@runtime_checkable
|
|
128
|
+
class Emittable(Protocol):
|
|
129
|
+
@abstractmethod
|
|
130
|
+
def emit(
|
|
131
|
+
self,
|
|
132
|
+
body: Any,
|
|
133
|
+
parameters: Any,
|
|
134
|
+
) -> Any: ...
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@runtime_checkable
|
|
138
|
+
class Requestable(Protocol):
|
|
139
|
+
@abstractmethod
|
|
140
|
+
def request(
|
|
141
|
+
self,
|
|
142
|
+
body: Any,
|
|
143
|
+
parameters: Any,
|
|
144
|
+
timeout: float = 5,
|
|
145
|
+
) -> Any: ...
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@runtime_checkable
|
|
149
|
+
class PrioritySupport(
|
|
150
|
+
Emittable,
|
|
151
|
+
Requestable,
|
|
152
|
+
Protocol,
|
|
153
|
+
):
|
|
154
|
+
"""작업 구독 설정의 우선순위 처리와 우선순위 발행을 지원하는 계약."""
|
|
155
|
+
|
|
156
|
+
def priority_parameters(
|
|
157
|
+
self,
|
|
158
|
+
parameters: Any,
|
|
159
|
+
) -> Any: ...
|
|
160
|
+
|
|
161
|
+
def emit(
|
|
162
|
+
self,
|
|
163
|
+
body: Any,
|
|
164
|
+
parameters: Any,
|
|
165
|
+
*,
|
|
166
|
+
priority: Optional[int] = None,
|
|
167
|
+
) -> Any: ...
|
|
168
|
+
|
|
169
|
+
def request(
|
|
170
|
+
self,
|
|
171
|
+
body: Any,
|
|
172
|
+
parameters: Any,
|
|
173
|
+
timeout: float = 5,
|
|
174
|
+
*,
|
|
175
|
+
priority: Optional[int] = None,
|
|
176
|
+
) -> 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
|
+
EventErrorPolicy,
|
|
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[EventErrorPolicy] = 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,35 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import (
|
|
3
|
+
Any,
|
|
4
|
+
Protocol,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
__all__ = (
|
|
8
|
+
'Event',
|
|
9
|
+
'EventHandler',
|
|
10
|
+
'EventErrorPolicy',
|
|
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 EventErrorPolicy(Protocol):
|
|
32
|
+
def __call__(
|
|
33
|
+
self,
|
|
34
|
+
event: Event,
|
|
35
|
+
) -> None: ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
@@ -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,54 @@
|
|
|
1
|
+
from typing import (
|
|
2
|
+
Any,
|
|
3
|
+
Generator,
|
|
4
|
+
Optional,
|
|
5
|
+
Protocol,
|
|
6
|
+
runtime_checkable,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from .Event import Event
|
|
10
|
+
|
|
11
|
+
__all__ = (
|
|
12
|
+
'Sendable',
|
|
13
|
+
'Callable',
|
|
14
|
+
'Poppable',
|
|
15
|
+
'Readable',
|
|
16
|
+
'Recoverable',
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@runtime_checkable
|
|
21
|
+
class Recoverable(Protocol):
|
|
22
|
+
"""Classify failures eligible for consumer recovery."""
|
|
23
|
+
|
|
24
|
+
def is_recoverable(self, error: BaseException) -> bool: ...
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Sendable(Protocol):
|
|
28
|
+
def send(
|
|
29
|
+
self,
|
|
30
|
+
body: Any,
|
|
31
|
+
) -> Any: ...
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Callable(Protocol):
|
|
35
|
+
def call(
|
|
36
|
+
self,
|
|
37
|
+
body: Any,
|
|
38
|
+
timeout: float = 5,
|
|
39
|
+
) -> Any: ...
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Poppable(Protocol):
|
|
43
|
+
def pop(
|
|
44
|
+
self,
|
|
45
|
+
timeout: Optional[int] = None,
|
|
46
|
+
) -> Optional[Event]: ...
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Readable(Protocol):
|
|
50
|
+
def read(
|
|
51
|
+
self,
|
|
52
|
+
offset: int = 0,
|
|
53
|
+
timeout: Optional[int] = None,
|
|
54
|
+
) -> Generator[Event, None, None]: ...
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from .Configuration import Configuration
|
|
4
|
+
from .Connection import (
|
|
5
|
+
Connection,
|
|
6
|
+
BrokerFactory,
|
|
7
|
+
Timer,
|
|
8
|
+
TimerCallback,
|
|
9
|
+
SetTimer,
|
|
10
|
+
GetExchange,
|
|
11
|
+
GetQueue,
|
|
12
|
+
GetStream,
|
|
13
|
+
GetConsumer,
|
|
14
|
+
Declarable,
|
|
15
|
+
Emittable,
|
|
16
|
+
Requestable,
|
|
17
|
+
PrioritySupport,
|
|
18
|
+
)
|
|
19
|
+
from .Protocol import (
|
|
20
|
+
Sendable,
|
|
21
|
+
Callable,
|
|
22
|
+
Poppable,
|
|
23
|
+
Readable,
|
|
24
|
+
Recoverable,
|
|
25
|
+
)
|
|
26
|
+
from .Errors import RemoteError
|
|
27
|
+
from .Consumer import Consumer
|
|
28
|
+
from .Priority import validate_priority
|
|
29
|
+
from .Event import (
|
|
30
|
+
Event,
|
|
31
|
+
EventHandler,
|
|
32
|
+
EventErrorPolicy,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
__all__ = (
|
|
36
|
+
'Configuration',
|
|
37
|
+
'Connection',
|
|
38
|
+
'BrokerFactory',
|
|
39
|
+
'Timer',
|
|
40
|
+
'TimerCallback',
|
|
41
|
+
'SetTimer',
|
|
42
|
+
'GetExchange',
|
|
43
|
+
'GetQueue',
|
|
44
|
+
'GetStream',
|
|
45
|
+
'GetConsumer',
|
|
46
|
+
'Declarable',
|
|
47
|
+
'Emittable',
|
|
48
|
+
'Requestable',
|
|
49
|
+
'PrioritySupport',
|
|
50
|
+
'Sendable',
|
|
51
|
+
'Callable',
|
|
52
|
+
'RemoteError',
|
|
53
|
+
'Poppable',
|
|
54
|
+
'Readable',
|
|
55
|
+
'Recoverable',
|
|
56
|
+
'Consumer',
|
|
57
|
+
'EventHandler',
|
|
58
|
+
'Event',
|
|
59
|
+
'EventErrorPolicy',
|
|
60
|
+
'validate_priority',
|
|
61
|
+
)
|