AMQPStorm 3.1.1__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 (99) hide show
  1. amqpstorm/__init__.py +17 -0
  2. amqpstorm/base.py +204 -0
  3. amqpstorm/basic.py +501 -0
  4. amqpstorm/channel.py +591 -0
  5. amqpstorm/channel0.py +250 -0
  6. amqpstorm/compatibility.py +115 -0
  7. amqpstorm/connection.py +438 -0
  8. amqpstorm/exception.py +129 -0
  9. amqpstorm/exchange.py +156 -0
  10. amqpstorm/heartbeat.py +142 -0
  11. amqpstorm/io.py +391 -0
  12. amqpstorm/management/__init__.py +3 -0
  13. amqpstorm/management/api.py +266 -0
  14. amqpstorm/management/base.py +13 -0
  15. amqpstorm/management/basic.py +117 -0
  16. amqpstorm/management/channel.py +47 -0
  17. amqpstorm/management/connection.py +75 -0
  18. amqpstorm/management/exception.py +37 -0
  19. amqpstorm/management/exchange.py +230 -0
  20. amqpstorm/management/healthchecks.py +29 -0
  21. amqpstorm/management/http_client.py +226 -0
  22. amqpstorm/management/queue.py +244 -0
  23. amqpstorm/management/user.py +167 -0
  24. amqpstorm/management/virtual_host.py +78 -0
  25. amqpstorm/message.py +496 -0
  26. amqpstorm/py.typed +0 -0
  27. amqpstorm/queue.py +182 -0
  28. amqpstorm/rpc.py +163 -0
  29. amqpstorm/tests/__init__.py +48 -0
  30. amqpstorm/tests/functional/__init__.py +0 -0
  31. amqpstorm/tests/functional/management/__init__.py +0 -0
  32. amqpstorm/tests/functional/management/test_api.py +100 -0
  33. amqpstorm/tests/functional/management/test_basic.py +65 -0
  34. amqpstorm/tests/functional/management/test_channel.py +21 -0
  35. amqpstorm/tests/functional/management/test_connection.py +88 -0
  36. amqpstorm/tests/functional/management/test_exchange.py +126 -0
  37. amqpstorm/tests/functional/management/test_healthcheck.py +26 -0
  38. amqpstorm/tests/functional/management/test_queue.py +259 -0
  39. amqpstorm/tests/functional/management/test_user.py +103 -0
  40. amqpstorm/tests/functional/management/test_virtual_host.py +51 -0
  41. amqpstorm/tests/functional/ssl/__init__.py +0 -0
  42. amqpstorm/tests/functional/ssl/test_reliability.py +349 -0
  43. amqpstorm/tests/functional/test_basic.py +159 -0
  44. amqpstorm/tests/functional/test_exchange.py +40 -0
  45. amqpstorm/tests/functional/test_generic.py +601 -0
  46. amqpstorm/tests/functional/test_legacy.py +119 -0
  47. amqpstorm/tests/functional/test_queue.py +66 -0
  48. amqpstorm/tests/functional/test_reliability.py +336 -0
  49. amqpstorm/tests/functional/test_tx.py +102 -0
  50. amqpstorm/tests/functional/test_web_based.py +63 -0
  51. amqpstorm/tests/functional/utility.py +137 -0
  52. amqpstorm/tests/unit/__init__.py +0 -0
  53. amqpstorm/tests/unit/base/__init__.py +0 -0
  54. amqpstorm/tests/unit/base/test_base_channel.py +70 -0
  55. amqpstorm/tests/unit/base/test_stateful.py +57 -0
  56. amqpstorm/tests/unit/basic/__init__.py +0 -0
  57. amqpstorm/tests/unit/basic/test_basic.py +407 -0
  58. amqpstorm/tests/unit/basic/test_basic_exception.py +293 -0
  59. amqpstorm/tests/unit/channel/__init__.py +0 -0
  60. amqpstorm/tests/unit/channel/test_channel.py +202 -0
  61. amqpstorm/tests/unit/channel/test_channel_exception.py +229 -0
  62. amqpstorm/tests/unit/channel/test_channel_frame.py +171 -0
  63. amqpstorm/tests/unit/channel/test_channel_message_handling.py +663 -0
  64. amqpstorm/tests/unit/channel0/__init__.py +0 -0
  65. amqpstorm/tests/unit/channel0/test_channel0.py +203 -0
  66. amqpstorm/tests/unit/channel0/test_channel0_frame.py +125 -0
  67. amqpstorm/tests/unit/connection/__init__.py +0 -0
  68. amqpstorm/tests/unit/connection/test_connection.py +660 -0
  69. amqpstorm/tests/unit/connection/test_connection_exception.py +137 -0
  70. amqpstorm/tests/unit/exchange/__init__.py +0 -0
  71. amqpstorm/tests/unit/exchange/test_exchange.py +48 -0
  72. amqpstorm/tests/unit/exchange/test_exchange_exception.py +117 -0
  73. amqpstorm/tests/unit/io/__init__.py +0 -0
  74. amqpstorm/tests/unit/io/test_io.py +248 -0
  75. amqpstorm/tests/unit/io/test_io_exception.py +303 -0
  76. amqpstorm/tests/unit/management/__init__.py +0 -0
  77. amqpstorm/tests/unit/management/test_api.py +29 -0
  78. amqpstorm/tests/unit/management/test_basic.py +24 -0
  79. amqpstorm/tests/unit/management/test_exception.py +30 -0
  80. amqpstorm/tests/unit/management/test_http_client.py +67 -0
  81. amqpstorm/tests/unit/queue/__init__.py +0 -0
  82. amqpstorm/tests/unit/queue/test_queue_exception.py +140 -0
  83. amqpstorm/tests/unit/test_compatibility.py +176 -0
  84. amqpstorm/tests/unit/test_exception.py +46 -0
  85. amqpstorm/tests/unit/test_heartbeat.py +265 -0
  86. amqpstorm/tests/unit/test_message.py +492 -0
  87. amqpstorm/tests/unit/test_rpc.py +225 -0
  88. amqpstorm/tests/unit/test_tx.py +134 -0
  89. amqpstorm/tests/unit/uri_connection/__init__.py +0 -0
  90. amqpstorm/tests/unit/uri_connection/test_uri_connection.py +239 -0
  91. amqpstorm/tests/unit/uri_connection/test_uri_connection_exception.py +58 -0
  92. amqpstorm/tests/utility.py +219 -0
  93. amqpstorm/tx.py +94 -0
  94. amqpstorm/uri_connection.py +174 -0
  95. amqpstorm-3.1.1.dist-info/METADATA +57 -0
  96. amqpstorm-3.1.1.dist-info/RECORD +99 -0
  97. amqpstorm-3.1.1.dist-info/WHEEL +5 -0
  98. amqpstorm-3.1.1.dist-info/licenses/LICENSE +21 -0
  99. amqpstorm-3.1.1.dist-info/top_level.txt +1 -0
amqpstorm/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ """AMQPStorm."""
2
+ __version__ = '3.1.1' # noqa
3
+ __author__ = 'eandersson' # noqa
4
+
5
+ import logging
6
+
7
+ logging.getLogger('amqpstorm').addHandler(logging.NullHandler())
8
+
9
+ from amqpstorm.channel import Channel # noqa
10
+ from amqpstorm.connection import Connection # noqa
11
+ from amqpstorm.uri_connection import UriConnection # noqa
12
+ from amqpstorm.message import Message # noqa
13
+ from amqpstorm.exception import AMQPError # noqa
14
+ from amqpstorm.exception import AMQPChannelError # noqa
15
+ from amqpstorm.exception import AMQPMessageError # noqa
16
+ from amqpstorm.exception import AMQPConnectionError # noqa
17
+ from amqpstorm.exception import AMQPInvalidArgument # noqa
amqpstorm/base.py ADDED
@@ -0,0 +1,204 @@
1
+ """AMQPStorm Base."""
2
+ from __future__ import annotations
3
+
4
+ from typing import TYPE_CHECKING
5
+ from typing import Any
6
+ from typing import Iterator
7
+
8
+ from amqpstorm.compatibility import is_string
9
+ from amqpstorm.exception import AMQPChannelError
10
+
11
+ if TYPE_CHECKING:
12
+ from amqpstorm.channel import Channel
13
+
14
+ AUTH_MECHANISM = 'PLAIN'
15
+ IDLE_WAIT = 0.01
16
+ MAX_FRAME_SIZE = 131072
17
+ MAX_CHANNELS = 65535
18
+
19
+
20
+ class Stateful:
21
+ """Stateful implementation."""
22
+ CLOSED = 0
23
+ CLOSING = 1
24
+ OPENING = 2
25
+ OPEN = 3
26
+
27
+ def __init__(self) -> None:
28
+ self._state: int = self.CLOSED
29
+ self._exceptions: list[Exception] = []
30
+
31
+ def set_state(self, state: int) -> None:
32
+ """Set State.
33
+
34
+ :param int state:
35
+ :return:
36
+ """
37
+ self._state = state
38
+
39
+ @property
40
+ def current_state(self) -> int:
41
+ """Get the State.
42
+
43
+ :rtype: int
44
+ """
45
+ return self._state
46
+
47
+ @property
48
+ def is_closed(self) -> bool:
49
+ """Is Closed?
50
+
51
+ :rtype: bool
52
+ """
53
+ return self._state == self.CLOSED
54
+
55
+ @property
56
+ def is_closing(self) -> bool:
57
+ """Is Closing?
58
+
59
+ :rtype: bool
60
+ """
61
+ return self._state == self.CLOSING
62
+
63
+ @property
64
+ def is_opening(self) -> bool:
65
+ """Is Opening?
66
+
67
+ :rtype: bool
68
+ """
69
+ return self._state == self.OPENING
70
+
71
+ @property
72
+ def is_open(self) -> bool:
73
+ """Is Open?
74
+
75
+ :rtype: bool
76
+ """
77
+ return self._state == self.OPEN
78
+
79
+ @property
80
+ def exceptions(self) -> list[Exception]:
81
+ """Stores all exceptions thrown by this instance.
82
+
83
+ This is useful for troubleshooting, and is used internally
84
+ to check the health of the connection.
85
+
86
+ :rtype: list
87
+ """
88
+ return self._exceptions
89
+
90
+
91
+ class BaseChannel(Stateful):
92
+ """Channel base class."""
93
+ __slots__ = [
94
+ '_channel_id', '_consumer_tags'
95
+ ]
96
+
97
+ def __init__(self, channel_id: int) -> None:
98
+ super().__init__()
99
+ self._consumer_tags: list[str] = []
100
+ self._channel_id: int = channel_id
101
+
102
+ @property
103
+ def channel_id(self) -> int:
104
+ """Get Channel id.
105
+
106
+ :rtype: int
107
+ """
108
+ return self._channel_id
109
+
110
+ @property
111
+ def consumer_tags(self) -> list[str]:
112
+ """Get a list of consumer tags.
113
+
114
+ :rtype: list
115
+ """
116
+ return self._consumer_tags
117
+
118
+ def add_consumer_tag(self, tag: str) -> None:
119
+ """Add a Consumer tag.
120
+
121
+ :param str tag: Consumer tag.
122
+ :return:
123
+ """
124
+ if not is_string(tag):
125
+ raise AMQPChannelError('consumer tag needs to be a string')
126
+ if tag not in self._consumer_tags:
127
+ self._consumer_tags.append(tag)
128
+
129
+ def remove_consumer_tag(self, tag: str | None = None) -> None:
130
+ """Remove a Consumer tag.
131
+
132
+ If no tag is specified, all tags will be removed.
133
+
134
+ :param str,None tag: Consumer tag.
135
+ :return:
136
+ """
137
+ if tag is not None:
138
+ if tag in self._consumer_tags:
139
+ self._consumer_tags.remove(tag)
140
+ else:
141
+ self._consumer_tags = []
142
+
143
+
144
+ class BaseMessage:
145
+ """Message base class.
146
+
147
+ :param Channel channel: AMQPStorm Channel
148
+ :param str,unicode body: Message body
149
+ :param dict method: Message method
150
+ :param dict properties: Message properties
151
+ :param bool auto_decode: This is not implemented in the base message class.
152
+ """
153
+ __slots__ = [
154
+ '_auto_decode', '_body', '_channel', '_method', '_properties'
155
+ ]
156
+
157
+ def __init__(
158
+ self,
159
+ channel: Channel | None,
160
+ body: bytes | str | None = None,
161
+ method: dict[str, Any] | None = None,
162
+ properties: dict[str, Any] | None = None,
163
+ auto_decode: bool | None = None,
164
+ ) -> None:
165
+ self._auto_decode = auto_decode
166
+ self._channel = channel
167
+ self._body = body
168
+ self._method = method
169
+ self._properties: dict[str, Any] = properties or {}
170
+
171
+ def __iter__(self) -> Iterator[tuple[str, Any]]:
172
+ for attribute in ['_body', '_channel', '_method', '_properties']:
173
+ yield attribute[1::], getattr(self, attribute)
174
+
175
+ def to_dict(self) -> dict[str, Any]:
176
+ """Message to Dictionary.
177
+
178
+ :rtype: dict
179
+ """
180
+ return {
181
+ 'body': self._body,
182
+ 'method': self._method,
183
+ 'properties': self._properties,
184
+ 'channel': self._channel
185
+ }
186
+
187
+ def to_tuple(
188
+ self,
189
+ ) -> tuple[bytes | str | None, Channel | None, dict[str, Any] | None, dict[str, Any]]:
190
+ """Message to Tuple.
191
+
192
+ :rtype: tuple
193
+ """
194
+ return self._body, self._channel, self._method, self._properties
195
+
196
+
197
+ class Handler:
198
+ """Operations Handler (e.g. Queue, Exchange)"""
199
+ __slots__ = [
200
+ '_channel'
201
+ ]
202
+
203
+ def __init__(self, channel: Channel) -> None:
204
+ self._channel = channel