DefStream 0.1.6__18-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 +126 -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 +57 -0
  11. DefStream/Descriptor/DataObject.py +384 -0
  12. DefStream/Descriptor/Types.py +229 -0
  13. DefStream/Descriptor/Value.py +132 -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 +396 -0
  18. DefStream/Inspector/Extensions/Dashboard.html +206 -0
  19. DefStream/Inspector/Extensions/Dashboard.py +114 -0
  20. DefStream/Inspector/Extensions/HealthCheck.py +92 -0
  21. DefStream/Inspector/Extensions/Metrics.py +281 -0
  22. DefStream/Inspector/Extensions/Specifications.py +160 -0
  23. DefStream/Inspector/Extensions/__init__.py +13 -0
  24. DefStream/Inspector/Inspector.py +216 -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 +298 -0
  44. DefStream/Worker/Message.py +179 -0
  45. DefStream/Worker/Pool.py +203 -0
  46. DefStream/Worker/Run.py +238 -0
  47. DefStream/Worker/Specification.py +91 -0
  48. DefStream/Worker/Startup.py +135 -0
  49. DefStream/Worker/Worker.py +315 -0
  50. DefStream/Worker/__init__.py +47 -0
  51. DefStream/__init__.py +0 -0
  52. defstream-0.1.6.dist-info/METADATA +608 -0
  53. defstream-0.1.6.dist-info/RECORD +56 -0
  54. defstream-0.1.6.dist-info/WHEEL +6 -0
  55. defstream-0.1.6.dist-info/licenses/LICENSE +674 -0
  56. defstream-0.1.6.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,126 @@
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
+ 'PrioritySupport',
25
+ )
26
+
27
+
28
+ class Connection(Protocol):
29
+ @abstractmethod
30
+ def connect(self) -> None: ...
31
+
32
+ @abstractmethod
33
+ def close(self) -> None: ...
34
+
35
+
36
+ class GetExchange(Protocol):
37
+ @abstractmethod
38
+ def exchange(
39
+ self,
40
+ name: str,
41
+ /,
42
+ ) -> Sendable: ...
43
+
44
+
45
+ class GetQueue(Protocol):
46
+ @abstractmethod
47
+ def queue(
48
+ self,
49
+ name: str,
50
+ /,
51
+ ) -> Sendable: ...
52
+
53
+
54
+ class GetStream(Protocol):
55
+ @abstractmethod
56
+ def stream(
57
+ self,
58
+ name: str,
59
+ /,
60
+ ) -> Sendable: ...
61
+
62
+
63
+ @runtime_checkable
64
+ class GetConsumer(Protocol):
65
+ @abstractmethod
66
+ def consumer(
67
+ self,
68
+ handler: Optional[EventHandler] = None,
69
+ ) -> Consumer: ...
70
+
71
+
72
+ @runtime_checkable
73
+ class Declarable(Protocol):
74
+ @abstractmethod
75
+ def declare(
76
+ self,
77
+ parameters: Any,
78
+ ) -> None: ...
79
+
80
+
81
+ @runtime_checkable
82
+ class TaskSender(Protocol):
83
+ @abstractmethod
84
+ def send(
85
+ self,
86
+ body: Any,
87
+ parameters: Any,
88
+ ) -> Any: ...
89
+
90
+
91
+ @runtime_checkable
92
+ class Requestable(Protocol):
93
+ @abstractmethod
94
+ def request(
95
+ self,
96
+ body: Any,
97
+ parameters: Any,
98
+ timeout: float = 5,
99
+ ) -> Any: ...
100
+
101
+
102
+ @runtime_checkable
103
+ class PrioritySupport(Protocol):
104
+ """작업 구독 설정의 우선순위 처리와 우선순위 발행을 지원하는 계약."""
105
+
106
+ def priority_parameters(
107
+ self,
108
+ parameters: Any,
109
+ ) -> Any: ...
110
+
111
+ def send(
112
+ self,
113
+ body: Any,
114
+ parameters: Any,
115
+ *,
116
+ priority: Optional[int] = None,
117
+ ) -> Any: ...
118
+
119
+ def request(
120
+ self,
121
+ body: Any,
122
+ parameters: Any,
123
+ timeout: float = 5,
124
+ *,
125
+ priority: Optional[int] = None,
126
+ ) -> 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,57 @@
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
+ PrioritySupport,
14
+ )
15
+ from .Protocol import (
16
+ Sendable,
17
+ Callable,
18
+ Poppable,
19
+ Readable,
20
+ )
21
+ from .Errors import RemoteError
22
+ from .Consumer import Consumer
23
+ from .Policies import (
24
+ Requeue,
25
+ Reject,
26
+ )
27
+ from .Priority import validate_priority
28
+ from .Event import (
29
+ Event,
30
+ EventHandler,
31
+ EventError,
32
+ )
33
+
34
+ __all__ = (
35
+ 'Configuration',
36
+ 'Connection',
37
+ 'GetExchange',
38
+ 'GetQueue',
39
+ 'GetStream',
40
+ 'GetConsumer',
41
+ 'Declarable',
42
+ 'TaskSender',
43
+ 'Requestable',
44
+ 'PrioritySupport',
45
+ 'Sendable',
46
+ 'Callable',
47
+ 'RemoteError',
48
+ 'Poppable',
49
+ 'Readable',
50
+ 'Consumer',
51
+ 'EventHandler',
52
+ 'Event',
53
+ 'EventError',
54
+ 'Requeue',
55
+ 'Reject',
56
+ 'validate_priority',
57
+ )