DefStream 0.1.17__64-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 (75) 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/RabbitMQ/Configuration.py +48 -0
  7. DefStream/Broker/Implements/RabbitMQ/Connection.py +542 -0
  8. DefStream/Broker/Implements/RabbitMQ/Consumer.py +359 -0
  9. DefStream/Broker/Implements/RabbitMQ/Event.py +127 -0
  10. DefStream/Broker/Implements/RabbitMQ/Exchange.py +278 -0
  11. DefStream/Broker/Implements/RabbitMQ/Policies.py +9 -0
  12. DefStream/Broker/Implements/RabbitMQ/Queue.py +319 -0
  13. DefStream/Broker/Implements/RabbitMQ/Serializer.py +61 -0
  14. DefStream/Broker/Implements/RabbitMQ/Stream.py +179 -0
  15. DefStream/Broker/Implements/RabbitMQ/Subscription.py +74 -0
  16. DefStream/Broker/Implements/RabbitMQ/__init__.py +47 -0
  17. DefStream/Broker/Implements/Redis/Configuration.py +59 -0
  18. DefStream/Broker/Implements/Redis/Connection.py +265 -0
  19. DefStream/Broker/Implements/Redis/Consumer.py +364 -0
  20. DefStream/Broker/Implements/Redis/Event.py +191 -0
  21. DefStream/Broker/Implements/Redis/Queue.py +284 -0
  22. DefStream/Broker/Implements/Redis/Serializer.py +48 -0
  23. DefStream/Broker/Implements/Redis/Subscription.py +46 -0
  24. DefStream/Broker/Implements/Redis/__init__.py +29 -0
  25. DefStream/Broker/Implements/__init__.py +1 -0
  26. DefStream/Broker/Policies.py +25 -0
  27. DefStream/Broker/Priority.py +26 -0
  28. DefStream/Broker/Protocol.py +45 -0
  29. DefStream/Broker/__init__.py +59 -0
  30. DefStream/Descriptor/DataObject.py +409 -0
  31. DefStream/Descriptor/Types.py +248 -0
  32. DefStream/Descriptor/Value.py +188 -0
  33. DefStream/Descriptor/__init__.py +172 -0
  34. DefStream/Inspector/Extension.py +69 -0
  35. DefStream/Inspector/Extensions/Console.html +373 -0
  36. DefStream/Inspector/Extensions/Console.py +415 -0
  37. DefStream/Inspector/Extensions/Metrics.py +316 -0
  38. DefStream/Inspector/Extensions/Ping.py +107 -0
  39. DefStream/Inspector/Extensions/Specifications.py +176 -0
  40. DefStream/Inspector/Extensions/Status.html +206 -0
  41. DefStream/Inspector/Extensions/Status.py +124 -0
  42. DefStream/Inspector/Extensions/__init__.py +13 -0
  43. DefStream/Inspector/Inspector.py +347 -0
  44. DefStream/Inspector/Response.py +14 -0
  45. DefStream/Inspector/__init__.py +9 -0
  46. DefStream/Validator/Pattern.py +36 -0
  47. DefStream/Validator/Patterns/Array.py +30 -0
  48. DefStream/Validator/Patterns/Common.py +92 -0
  49. DefStream/Validator/Patterns/Compare.py +180 -0
  50. DefStream/Validator/Patterns/Condition.py +60 -0
  51. DefStream/Validator/Patterns/DataObject.py +85 -0
  52. DefStream/Validator/Patterns/DateTime.py +111 -0
  53. DefStream/Validator/Patterns/Number.py +43 -0
  54. DefStream/Validator/Patterns/Object.py +150 -0
  55. DefStream/Validator/Patterns/Size.py +110 -0
  56. DefStream/Validator/Patterns/String.py +85 -0
  57. DefStream/Validator/Patterns/Type.py +350 -0
  58. DefStream/Validator/Patterns/__init__.py +137 -0
  59. DefStream/Validator/Validate.py +29 -0
  60. DefStream/Validator/Validator.py +30 -0
  61. DefStream/Validator/__init__.py +11 -0
  62. DefStream/Worker/Executor.py +371 -0
  63. DefStream/Worker/Message.py +180 -0
  64. DefStream/Worker/Pool.py +245 -0
  65. DefStream/Worker/Run.py +357 -0
  66. DefStream/Worker/Specification.py +87 -0
  67. DefStream/Worker/Startup.py +174 -0
  68. DefStream/Worker/Worker.py +421 -0
  69. DefStream/Worker/__init__.py +47 -0
  70. DefStream/__init__.py +0 -0
  71. defstream-0.1.17.dist-info/METADATA +1174 -0
  72. defstream-0.1.17.dist-info/RECORD +75 -0
  73. defstream-0.1.17.dist-info/WHEEL +6 -0
  74. defstream-0.1.17.dist-info/licenses/LICENSE +674 -0
  75. defstream-0.1.17.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,48 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from DefStream.Broker import Configuration as BaseConfiguration
4
+
5
+ from .Serializer import (
6
+ Encoder,
7
+ Decoder,
8
+ JavaScriptObjectNotationEncoder,
9
+ JavaScriptObjectNotationDecoder,
10
+ )
11
+
12
+
13
+ from pika import SSLOptions
14
+ from ssl import create_default_context
15
+
16
+ __all__ = (
17
+ 'Configuration'
18
+ )
19
+
20
+
21
+ class Configuration(BaseConfiguration):
22
+ """
23
+ Configuration of Event Broker for RabbitMQ
24
+ """
25
+ def __init__(
26
+ self,
27
+ host: str,
28
+ port: int,
29
+ username: str = None,
30
+ password: str = None,
31
+ ssl: bool = False,
32
+ vhost: str = '/',
33
+ timeout: int = None,
34
+ heartbeat: int = None,
35
+ encode: Encoder = JavaScriptObjectNotationEncoder(),
36
+ decode: Decoder = JavaScriptObjectNotationDecoder(),
37
+ ):
38
+ self.host = host
39
+ self.port = port
40
+ self.username = username
41
+ self.password = password
42
+ self.ssl = SSLOptions(create_default_context(), host) if ssl else None
43
+ self.vhost = vhost
44
+ self.timeout = timeout/1000 if timeout else None
45
+ self.heartbeat = int(heartbeat*2/1000) if heartbeat else None
46
+ self.encode = encode
47
+ self.decode = decode
48
+ return