AMQPStorm 3.0__tar.gz → 3.1__tar.gz
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.
- {amqpstorm-3.0 → amqpstorm-3.1}/AMQPStorm.egg-info/PKG-INFO +12 -14
- {amqpstorm-3.0 → amqpstorm-3.1}/AMQPStorm.egg-info/SOURCES.txt +2 -2
- amqpstorm-3.1/AMQPStorm.egg-info/requires.txt +11 -0
- amqpstorm-3.1/CHANGELOG.rst +36 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/PKG-INFO +12 -14
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/__init__.py +1 -1
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/base.py +45 -29
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/basic.py +107 -51
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/channel.py +117 -54
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/channel0.py +39 -29
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/compatibility.py +25 -31
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/connection.py +69 -42
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/exception.py +16 -12
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/exchange.py +26 -7
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/heartbeat.py +36 -29
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/io.py +118 -93
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/api.py +33 -22
- amqpstorm-3.1/amqpstorm/management/base.py +13 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/basic.py +24 -5
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/channel.py +13 -3
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/connection.py +18 -4
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/exception.py +16 -4
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/exchange.py +46 -13
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/healthchecks.py +5 -1
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/http_client.py +59 -13
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/queue.py +45 -13
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/user.py +26 -10
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/virtual_host.py +10 -5
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/message.py +68 -47
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/queue.py +29 -6
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/rpc.py +38 -31
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_basic.py +4 -4
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_queue.py +22 -22
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/ssl/test_reliability.py +8 -8
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_basic.py +11 -11
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_generic.py +27 -27
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_legacy.py +4 -4
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_queue.py +2 -2
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_reliability.py +61 -36
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_tx.py +4 -4
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_web_based.py +3 -3
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/utility.py +8 -2
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/channel/test_channel.py +27 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/channel/test_channel_message_handling.py +150 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/connection/test_connection.py +21 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/io/test_io.py +41 -1
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/io/test_io_exception.py +36 -8
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/test_rpc.py +5 -4
- amqpstorm-3.1/amqpstorm/tests/unit/uri_connection/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/uri_connection/test_uri_connection.py +29 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/uri_connection/test_uri_connection_exception.py +3 -3
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/utility.py +1 -2
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tx.py +19 -7
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/uri_connection.py +40 -17
- amqpstorm-3.1/pyproject.toml +58 -0
- amqpstorm-3.1/setup.cfg +4 -0
- amqpstorm-3.0/AMQPStorm.egg-info/requires.txt +0 -4
- amqpstorm-3.0/CHANGELOG.rst +0 -8
- amqpstorm-3.0/amqpstorm/management/base.py +0 -5
- amqpstorm-3.0/setup.cfg +0 -13
- amqpstorm-3.0/setup.py +0 -59
- {amqpstorm-3.0 → amqpstorm-3.1}/AMQPStorm.egg-info/dependency_links.txt +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/AMQPStorm.egg-info/top_level.txt +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/LICENSE +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/MANIFEST.in +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/README.rst +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/management/__init__.py +0 -0
- /amqpstorm-3.0/amqpstorm/tests/functional/__init__.py → /amqpstorm-3.1/amqpstorm/py.typed +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/__init__.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/functional/management → amqpstorm-3.1/amqpstorm/tests/functional}/__init__.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/functional/ssl → amqpstorm-3.1/amqpstorm/tests/functional/management}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_api.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_channel.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_connection.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_exchange.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_healthcheck.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_user.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/management/test_virtual_host.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit → amqpstorm-3.1/amqpstorm/tests/functional/ssl}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/functional/test_exchange.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/base → amqpstorm-3.1/amqpstorm/tests/unit}/__init__.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/basic → amqpstorm-3.1/amqpstorm/tests/unit/base}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/base/test_base_channel.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/base/test_stateful.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/channel → amqpstorm-3.1/amqpstorm/tests/unit/basic}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/basic/test_basic.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/basic/test_basic_exception.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/channel0 → amqpstorm-3.1/amqpstorm/tests/unit/channel}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/channel/test_channel_exception.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/channel/test_channel_frame.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/connection → amqpstorm-3.1/amqpstorm/tests/unit/channel0}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/channel0/test_channel0.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/channel0/test_channel0_frame.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/exchange → amqpstorm-3.1/amqpstorm/tests/unit/connection}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/connection/test_connection_exception.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/io → amqpstorm-3.1/amqpstorm/tests/unit/exchange}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/exchange/test_exchange.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/exchange/test_exchange_exception.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/management → amqpstorm-3.1/amqpstorm/tests/unit/io}/__init__.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/queue → amqpstorm-3.1/amqpstorm/tests/unit/management}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/management/test_api.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/management/test_basic.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/management/test_exception.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/management/test_http_client.py +0 -0
- {amqpstorm-3.0/amqpstorm/tests/unit/uri_connection → amqpstorm-3.1/amqpstorm/tests/unit/queue}/__init__.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/queue/test_queue_exception.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/test_compatibility.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/test_exception.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/test_heartbeat.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/test_message.py +0 -0
- {amqpstorm-3.0 → amqpstorm-3.1}/amqpstorm/tests/unit/test_tx.py +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AMQPStorm
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1
|
|
4
4
|
Summary: Thread-safe Python3 RabbitMQ Client & Management library.
|
|
5
|
-
|
|
6
|
-
Author: Erik Olof Gunnar Andersson
|
|
7
|
-
Author-email: amqpstorm@eandersson.net
|
|
5
|
+
Author-email: Erik Olof Gunnar Andersson <amqpstorm@eandersson.net>
|
|
8
6
|
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://amqpstorm.readthedocs.io/
|
|
8
|
+
Project-URL: Documentation, https://amqpstorm.readthedocs.io/
|
|
9
|
+
Project-URL: Repository, https://github.com/eandersson/amqpstorm
|
|
10
|
+
Project-URL: Changelog, https://github.com/eandersson/amqpstorm/blob/main/CHANGELOG.rst
|
|
9
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
10
12
|
Classifier: Intended Audience :: Developers
|
|
11
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -24,21 +26,17 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
24
26
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
27
|
Classifier: Topic :: System :: Networking
|
|
26
28
|
Requires-Python: >=3.11
|
|
29
|
+
Description-Content-Type: text/x-rst
|
|
27
30
|
License-File: LICENSE
|
|
28
31
|
Requires-Dist: pamqp<5.0,>=4.0.0
|
|
29
32
|
Provides-Extra: management
|
|
30
33
|
Requires-Dist: requests>2; extra == "management"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Dynamic: license
|
|
34
|
+
Provides-Extra: docs
|
|
35
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
36
|
+
Requires-Dist: sphinx_rtd_theme; extra == "docs"
|
|
37
|
+
Provides-Extra: typing
|
|
38
|
+
Requires-Dist: mypy; extra == "typing"
|
|
37
39
|
Dynamic: license-file
|
|
38
|
-
Dynamic: provides-extra
|
|
39
|
-
Dynamic: requires-dist
|
|
40
|
-
Dynamic: requires-python
|
|
41
|
-
Dynamic: summary
|
|
42
40
|
|
|
43
41
|
AMQPStorm
|
|
44
42
|
=========
|
|
@@ -2,8 +2,7 @@ CHANGELOG.rst
|
|
|
2
2
|
LICENSE
|
|
3
3
|
MANIFEST.in
|
|
4
4
|
README.rst
|
|
5
|
-
|
|
6
|
-
setup.py
|
|
5
|
+
pyproject.toml
|
|
7
6
|
AMQPStorm.egg-info/PKG-INFO
|
|
8
7
|
AMQPStorm.egg-info/SOURCES.txt
|
|
9
8
|
AMQPStorm.egg-info/dependency_links.txt
|
|
@@ -21,6 +20,7 @@ amqpstorm/exchange.py
|
|
|
21
20
|
amqpstorm/heartbeat.py
|
|
22
21
|
amqpstorm/io.py
|
|
23
22
|
amqpstorm/message.py
|
|
23
|
+
amqpstorm/py.typed
|
|
24
24
|
amqpstorm/queue.py
|
|
25
25
|
amqpstorm/rpc.py
|
|
26
26
|
amqpstorm/tx.py
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Changelog
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
Version 3.1
|
|
5
|
+
-----------
|
|
6
|
+
- Added inline type hints across the public API and shipped ``py.typed``
|
|
7
|
+
so downstream type checkers pick them up (PEP 561).
|
|
8
|
+
- ``Channel.build_inbound_messages`` now ends cleanly when the channel
|
|
9
|
+
or connection is closed via user code (``.close()``); server- and
|
|
10
|
+
network-driven closes still raise as before. ``check_for_errors``
|
|
11
|
+
itself is unchanged.
|
|
12
|
+
- Performance: byte-string accumulation in receive / publish paths
|
|
13
|
+
replaced with ``b''.join`` (no more O(n²) under non-CPython refcount
|
|
14
|
+
semantics); writes use ``memoryview`` slicing; RPC response storage
|
|
15
|
+
switched to ``collections.deque`` so popping multi-frame ``Basic.Get``
|
|
16
|
+
results is O(n) instead of O(n²).
|
|
17
|
+
- Modernized to Python 3.11+ syntax: dropped ``(object)`` bases, switched
|
|
18
|
+
to argument-less ``super()``, f-strings, modern ``with`` blocks for
|
|
19
|
+
locks.
|
|
20
|
+
- Packaging migrated from ``setup.py`` / ``setup.cfg`` to PEP 621
|
|
21
|
+
``pyproject.toml``; version is now read dynamically from
|
|
22
|
+
``amqpstorm.__version__``.
|
|
23
|
+
- Documentation: fixed several typos, completed missing ``:members:``
|
|
24
|
+
entries on the management API autodoc, added intersphinx mapping and
|
|
25
|
+
short type-hint rendering in the Sphinx config.
|
|
26
|
+
- SSL: hostname verification now on by default; unknown ``cert_reqs``
|
|
27
|
+
URI values fall back to ``CERT_REQUIRED`` instead of ``CERT_NONE``.
|
|
28
|
+
- Switched all elapsed-duration checks (RPC and connection-state
|
|
29
|
+
timeouts) from ``time.time()`` to ``time.monotonic()`` so system
|
|
30
|
+
clock changes can no longer cause spurious timeouts or hangs.
|
|
31
|
+
|
|
32
|
+
Version 3.0
|
|
33
|
+
-----------
|
|
34
|
+
- Python 3 only release.
|
|
35
|
+
- Added support for pamqp 4.x.
|
|
36
|
+
- Improved SSL handling.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AMQPStorm
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1
|
|
4
4
|
Summary: Thread-safe Python3 RabbitMQ Client & Management library.
|
|
5
|
-
|
|
6
|
-
Author: Erik Olof Gunnar Andersson
|
|
7
|
-
Author-email: amqpstorm@eandersson.net
|
|
5
|
+
Author-email: Erik Olof Gunnar Andersson <amqpstorm@eandersson.net>
|
|
8
6
|
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://amqpstorm.readthedocs.io/
|
|
8
|
+
Project-URL: Documentation, https://amqpstorm.readthedocs.io/
|
|
9
|
+
Project-URL: Repository, https://github.com/eandersson/amqpstorm
|
|
10
|
+
Project-URL: Changelog, https://github.com/eandersson/amqpstorm/blob/main/CHANGELOG.rst
|
|
9
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
10
12
|
Classifier: Intended Audience :: Developers
|
|
11
13
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -24,21 +26,17 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
24
26
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
27
|
Classifier: Topic :: System :: Networking
|
|
26
28
|
Requires-Python: >=3.11
|
|
29
|
+
Description-Content-Type: text/x-rst
|
|
27
30
|
License-File: LICENSE
|
|
28
31
|
Requires-Dist: pamqp<5.0,>=4.0.0
|
|
29
32
|
Provides-Extra: management
|
|
30
33
|
Requires-Dist: requests>2; extra == "management"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Dynamic: license
|
|
34
|
+
Provides-Extra: docs
|
|
35
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
36
|
+
Requires-Dist: sphinx_rtd_theme; extra == "docs"
|
|
37
|
+
Provides-Extra: typing
|
|
38
|
+
Requires-Dist: mypy; extra == "typing"
|
|
37
39
|
Dynamic: license-file
|
|
38
|
-
Dynamic: provides-extra
|
|
39
|
-
Dynamic: requires-dist
|
|
40
|
-
Dynamic: requires-python
|
|
41
|
-
Dynamic: summary
|
|
42
40
|
|
|
43
41
|
AMQPStorm
|
|
44
42
|
=========
|
|
@@ -1,26 +1,34 @@
|
|
|
1
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
|
|
2
7
|
|
|
3
8
|
from amqpstorm.compatibility import is_string
|
|
4
9
|
from amqpstorm.exception import AMQPChannelError
|
|
5
10
|
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from amqpstorm.channel import Channel
|
|
13
|
+
|
|
6
14
|
AUTH_MECHANISM = 'PLAIN'
|
|
7
15
|
IDLE_WAIT = 0.01
|
|
8
16
|
MAX_FRAME_SIZE = 131072
|
|
9
17
|
MAX_CHANNELS = 65535
|
|
10
18
|
|
|
11
19
|
|
|
12
|
-
class Stateful
|
|
20
|
+
class Stateful:
|
|
13
21
|
"""Stateful implementation."""
|
|
14
22
|
CLOSED = 0
|
|
15
23
|
CLOSING = 1
|
|
16
24
|
OPENING = 2
|
|
17
25
|
OPEN = 3
|
|
18
26
|
|
|
19
|
-
def __init__(self):
|
|
20
|
-
self._state = self.CLOSED
|
|
21
|
-
self._exceptions = []
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
self._state: int = self.CLOSED
|
|
29
|
+
self._exceptions: list[Exception] = []
|
|
22
30
|
|
|
23
|
-
def set_state(self, state):
|
|
31
|
+
def set_state(self, state: int) -> None:
|
|
24
32
|
"""Set State.
|
|
25
33
|
|
|
26
34
|
:param int state:
|
|
@@ -29,7 +37,7 @@ class Stateful(object):
|
|
|
29
37
|
self._state = state
|
|
30
38
|
|
|
31
39
|
@property
|
|
32
|
-
def current_state(self):
|
|
40
|
+
def current_state(self) -> int:
|
|
33
41
|
"""Get the State.
|
|
34
42
|
|
|
35
43
|
:rtype: int
|
|
@@ -37,7 +45,7 @@ class Stateful(object):
|
|
|
37
45
|
return self._state
|
|
38
46
|
|
|
39
47
|
@property
|
|
40
|
-
def is_closed(self):
|
|
48
|
+
def is_closed(self) -> bool:
|
|
41
49
|
"""Is Closed?
|
|
42
50
|
|
|
43
51
|
:rtype: bool
|
|
@@ -45,7 +53,7 @@ class Stateful(object):
|
|
|
45
53
|
return self._state == self.CLOSED
|
|
46
54
|
|
|
47
55
|
@property
|
|
48
|
-
def is_closing(self):
|
|
56
|
+
def is_closing(self) -> bool:
|
|
49
57
|
"""Is Closing?
|
|
50
58
|
|
|
51
59
|
:rtype: bool
|
|
@@ -53,7 +61,7 @@ class Stateful(object):
|
|
|
53
61
|
return self._state == self.CLOSING
|
|
54
62
|
|
|
55
63
|
@property
|
|
56
|
-
def is_opening(self):
|
|
64
|
+
def is_opening(self) -> bool:
|
|
57
65
|
"""Is Opening?
|
|
58
66
|
|
|
59
67
|
:rtype: bool
|
|
@@ -61,7 +69,7 @@ class Stateful(object):
|
|
|
61
69
|
return self._state == self.OPENING
|
|
62
70
|
|
|
63
71
|
@property
|
|
64
|
-
def is_open(self):
|
|
72
|
+
def is_open(self) -> bool:
|
|
65
73
|
"""Is Open?
|
|
66
74
|
|
|
67
75
|
:rtype: bool
|
|
@@ -69,7 +77,7 @@ class Stateful(object):
|
|
|
69
77
|
return self._state == self.OPEN
|
|
70
78
|
|
|
71
79
|
@property
|
|
72
|
-
def exceptions(self):
|
|
80
|
+
def exceptions(self) -> list[Exception]:
|
|
73
81
|
"""Stores all exceptions thrown by this instance.
|
|
74
82
|
|
|
75
83
|
This is useful for troubleshooting, and is used internally
|
|
@@ -86,13 +94,13 @@ class BaseChannel(Stateful):
|
|
|
86
94
|
'_channel_id', '_consumer_tags'
|
|
87
95
|
]
|
|
88
96
|
|
|
89
|
-
def __init__(self, channel_id):
|
|
90
|
-
super(
|
|
91
|
-
self._consumer_tags = []
|
|
92
|
-
self._channel_id = channel_id
|
|
97
|
+
def __init__(self, channel_id: int) -> None:
|
|
98
|
+
super().__init__()
|
|
99
|
+
self._consumer_tags: list[str] = []
|
|
100
|
+
self._channel_id: int = channel_id
|
|
93
101
|
|
|
94
102
|
@property
|
|
95
|
-
def channel_id(self):
|
|
103
|
+
def channel_id(self) -> int:
|
|
96
104
|
"""Get Channel id.
|
|
97
105
|
|
|
98
106
|
:rtype: int
|
|
@@ -100,14 +108,14 @@ class BaseChannel(Stateful):
|
|
|
100
108
|
return self._channel_id
|
|
101
109
|
|
|
102
110
|
@property
|
|
103
|
-
def consumer_tags(self):
|
|
111
|
+
def consumer_tags(self) -> list[str]:
|
|
104
112
|
"""Get a list of consumer tags.
|
|
105
113
|
|
|
106
114
|
:rtype: list
|
|
107
115
|
"""
|
|
108
116
|
return self._consumer_tags
|
|
109
117
|
|
|
110
|
-
def add_consumer_tag(self, tag):
|
|
118
|
+
def add_consumer_tag(self, tag: str) -> None:
|
|
111
119
|
"""Add a Consumer tag.
|
|
112
120
|
|
|
113
121
|
:param str tag: Consumer tag.
|
|
@@ -118,10 +126,10 @@ class BaseChannel(Stateful):
|
|
|
118
126
|
if tag not in self._consumer_tags:
|
|
119
127
|
self._consumer_tags.append(tag)
|
|
120
128
|
|
|
121
|
-
def remove_consumer_tag(self, tag=None):
|
|
129
|
+
def remove_consumer_tag(self, tag: str | None = None) -> None:
|
|
122
130
|
"""Remove a Consumer tag.
|
|
123
131
|
|
|
124
|
-
If no tag is specified, all
|
|
132
|
+
If no tag is specified, all tags will be removed.
|
|
125
133
|
|
|
126
134
|
:param str,None tag: Consumer tag.
|
|
127
135
|
:return:
|
|
@@ -133,7 +141,7 @@ class BaseChannel(Stateful):
|
|
|
133
141
|
self._consumer_tags = []
|
|
134
142
|
|
|
135
143
|
|
|
136
|
-
class BaseMessage
|
|
144
|
+
class BaseMessage:
|
|
137
145
|
"""Message base class.
|
|
138
146
|
|
|
139
147
|
:param Channel channel: AMQPStorm Channel
|
|
@@ -146,19 +154,25 @@ class BaseMessage(object):
|
|
|
146
154
|
'_auto_decode', '_body', '_channel', '_method', '_properties'
|
|
147
155
|
]
|
|
148
156
|
|
|
149
|
-
def __init__(
|
|
150
|
-
|
|
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:
|
|
151
165
|
self._auto_decode = auto_decode
|
|
152
166
|
self._channel = channel
|
|
153
167
|
self._body = body
|
|
154
168
|
self._method = method
|
|
155
|
-
self._properties = properties or {}
|
|
169
|
+
self._properties: dict[str, Any] = properties or {}
|
|
156
170
|
|
|
157
|
-
def __iter__(self):
|
|
171
|
+
def __iter__(self) -> Iterator[tuple[str, Any]]:
|
|
158
172
|
for attribute in ['_body', '_channel', '_method', '_properties']:
|
|
159
173
|
yield attribute[1::], getattr(self, attribute)
|
|
160
174
|
|
|
161
|
-
def to_dict(self):
|
|
175
|
+
def to_dict(self) -> dict[str, Any]:
|
|
162
176
|
"""Message to Dictionary.
|
|
163
177
|
|
|
164
178
|
:rtype: dict
|
|
@@ -170,7 +184,9 @@ class BaseMessage(object):
|
|
|
170
184
|
'channel': self._channel
|
|
171
185
|
}
|
|
172
186
|
|
|
173
|
-
def to_tuple(
|
|
187
|
+
def to_tuple(
|
|
188
|
+
self,
|
|
189
|
+
) -> tuple[bytes | str | None, Channel | None, dict[str, Any] | None, dict[str, Any]]:
|
|
174
190
|
"""Message to Tuple.
|
|
175
191
|
|
|
176
192
|
:rtype: tuple
|
|
@@ -178,11 +194,11 @@ class BaseMessage(object):
|
|
|
178
194
|
return self._body, self._channel, self._method, self._properties
|
|
179
195
|
|
|
180
196
|
|
|
181
|
-
class Handler
|
|
197
|
+
class Handler:
|
|
182
198
|
"""Operations Handler (e.g. Queue, Exchange)"""
|
|
183
199
|
__slots__ = [
|
|
184
200
|
'_channel'
|
|
185
201
|
]
|
|
186
202
|
|
|
187
|
-
def __init__(self, channel):
|
|
203
|
+
def __init__(self, channel: Channel) -> None:
|
|
188
204
|
self._channel = channel
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"""AMQPStorm Channel.Basic."""
|
|
2
|
+
from __future__ import annotations
|
|
2
3
|
|
|
3
4
|
import logging
|
|
4
|
-
import
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
from typing import Any
|
|
7
|
+
from typing import Callable
|
|
8
|
+
from typing import Iterable
|
|
5
9
|
|
|
6
10
|
from pamqp import body as pamqp_body
|
|
7
11
|
from pamqp import header as pamqp_header
|
|
@@ -15,6 +19,9 @@ from amqpstorm.exception import AMQPChannelError
|
|
|
15
19
|
from amqpstorm.exception import AMQPInvalidArgument
|
|
16
20
|
from amqpstorm.message import Message
|
|
17
21
|
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from amqpstorm.channel import Channel
|
|
24
|
+
|
|
18
25
|
LOGGER = logging.getLogger(__name__)
|
|
19
26
|
|
|
20
27
|
|
|
@@ -22,11 +29,16 @@ class Basic(Handler):
|
|
|
22
29
|
"""RabbitMQ Basic Operations."""
|
|
23
30
|
__slots__ = ['_max_frame_size']
|
|
24
31
|
|
|
25
|
-
def __init__(self, channel, max_frame_size=None):
|
|
26
|
-
super(
|
|
32
|
+
def __init__(self, channel: Channel, max_frame_size: int | None = None) -> None:
|
|
33
|
+
super().__init__(channel)
|
|
27
34
|
self._max_frame_size = max_frame_size or MAX_FRAME_SIZE
|
|
28
35
|
|
|
29
|
-
def qos(
|
|
36
|
+
def qos(
|
|
37
|
+
self,
|
|
38
|
+
prefetch_count: int = 0,
|
|
39
|
+
prefetch_size: int = 0,
|
|
40
|
+
global_: bool = False,
|
|
41
|
+
) -> dict[str, Any]:
|
|
30
42
|
"""Specify quality of service.
|
|
31
43
|
|
|
32
44
|
:param int prefetch_count: Prefetch window in messages
|
|
@@ -51,8 +63,14 @@ class Basic(Handler):
|
|
|
51
63
|
global_=global_)
|
|
52
64
|
return self._channel.rpc_request(qos_frame)
|
|
53
65
|
|
|
54
|
-
def get(
|
|
55
|
-
|
|
66
|
+
def get(
|
|
67
|
+
self,
|
|
68
|
+
queue: str = '',
|
|
69
|
+
no_ack: bool = False,
|
|
70
|
+
to_dict: bool = False,
|
|
71
|
+
auto_decode: bool = True,
|
|
72
|
+
message_impl: type[BaseMessage] | None = None,
|
|
73
|
+
) -> Message | BaseMessage | dict[str, Any] | None:
|
|
56
74
|
"""Fetch a single message.
|
|
57
75
|
|
|
58
76
|
:param str queue: Queue name
|
|
@@ -97,7 +115,7 @@ class Basic(Handler):
|
|
|
97
115
|
return message.to_dict()
|
|
98
116
|
return message
|
|
99
117
|
|
|
100
|
-
def recover(self, requeue=False):
|
|
118
|
+
def recover(self, requeue: bool = False) -> dict[str, Any]:
|
|
101
119
|
"""Redeliver unacknowledged messages.
|
|
102
120
|
|
|
103
121
|
:param bool requeue: Re-queue the messages
|
|
@@ -114,8 +132,16 @@ class Basic(Handler):
|
|
|
114
132
|
recover_frame = commands.Basic.Recover(requeue=requeue)
|
|
115
133
|
return self._channel.rpc_request(recover_frame)
|
|
116
134
|
|
|
117
|
-
def consume(
|
|
118
|
-
|
|
135
|
+
def consume(
|
|
136
|
+
self,
|
|
137
|
+
callback: Callable[..., Any] | None = None,
|
|
138
|
+
queue: str = '',
|
|
139
|
+
consumer_tag: str = '',
|
|
140
|
+
exclusive: bool = False,
|
|
141
|
+
no_ack: bool = False,
|
|
142
|
+
no_local: bool = False,
|
|
143
|
+
arguments: dict[str, Any] | None = None,
|
|
144
|
+
) -> str:
|
|
119
145
|
"""Start a queue consumer.
|
|
120
146
|
|
|
121
147
|
:param typing.Callable callback: Message callback
|
|
@@ -154,7 +180,7 @@ class Basic(Handler):
|
|
|
154
180
|
self._channel._consumer_callbacks[tag] = callback
|
|
155
181
|
return tag
|
|
156
182
|
|
|
157
|
-
def cancel(self, consumer_tag=''):
|
|
183
|
+
def cancel(self, consumer_tag: str = '') -> dict[str, Any]:
|
|
158
184
|
"""Cancel a queue consumer.
|
|
159
185
|
|
|
160
186
|
:param str consumer_tag: Consumer tag
|
|
@@ -174,8 +200,15 @@ class Basic(Handler):
|
|
|
174
200
|
self._channel.remove_consumer_tag(consumer_tag)
|
|
175
201
|
return result
|
|
176
202
|
|
|
177
|
-
def publish(
|
|
178
|
-
|
|
203
|
+
def publish(
|
|
204
|
+
self,
|
|
205
|
+
body: bytes | str,
|
|
206
|
+
routing_key: str,
|
|
207
|
+
exchange: str = '',
|
|
208
|
+
properties: dict[str, Any] | None = None,
|
|
209
|
+
mandatory: bool = False,
|
|
210
|
+
immediate: bool = False,
|
|
211
|
+
) -> bool | None:
|
|
179
212
|
"""Publish a Message.
|
|
180
213
|
|
|
181
214
|
:param bytes,str,unicode body: Message payload
|
|
@@ -195,25 +228,25 @@ class Basic(Handler):
|
|
|
195
228
|
self._validate_publish_parameters(body, exchange, immediate, mandatory,
|
|
196
229
|
properties, routing_key)
|
|
197
230
|
properties = properties or {}
|
|
198
|
-
|
|
199
|
-
|
|
231
|
+
encoded_body = self._handle_utf8_payload(body, properties)
|
|
232
|
+
properties_frame = commands.Basic.Properties(**properties)
|
|
200
233
|
method_frame = commands.Basic.Publish(exchange=exchange,
|
|
201
234
|
routing_key=routing_key,
|
|
202
235
|
mandatory=mandatory,
|
|
203
236
|
immediate=immediate)
|
|
204
|
-
header_frame = pamqp_header.ContentHeader(body_size=len(
|
|
205
|
-
properties=
|
|
237
|
+
header_frame = pamqp_header.ContentHeader(body_size=len(encoded_body),
|
|
238
|
+
properties=properties_frame)
|
|
206
239
|
|
|
207
|
-
frames_out = [method_frame, header_frame]
|
|
208
|
-
|
|
209
|
-
frames_out.append(body_frame)
|
|
240
|
+
frames_out: list[Any] = [method_frame, header_frame]
|
|
241
|
+
frames_out.extend(self._create_content_body(encoded_body))
|
|
210
242
|
|
|
211
243
|
if self._channel.confirming_deliveries:
|
|
212
244
|
with self._channel.rpc.lock:
|
|
213
245
|
return self._publish_confirm(frames_out, mandatory)
|
|
214
246
|
self._channel.write_frames(frames_out)
|
|
247
|
+
return None
|
|
215
248
|
|
|
216
|
-
def ack(self, delivery_tag=0, multiple=False):
|
|
249
|
+
def ack(self, delivery_tag: int = 0, multiple: bool = False) -> None:
|
|
217
250
|
"""Acknowledge Message.
|
|
218
251
|
|
|
219
252
|
:param int/long delivery_tag: Server-assigned delivery tag
|
|
@@ -234,7 +267,12 @@ class Basic(Handler):
|
|
|
234
267
|
multiple=multiple)
|
|
235
268
|
self._channel.write_frame(ack_frame)
|
|
236
269
|
|
|
237
|
-
def nack(
|
|
270
|
+
def nack(
|
|
271
|
+
self,
|
|
272
|
+
delivery_tag: int = 0,
|
|
273
|
+
multiple: bool = False,
|
|
274
|
+
requeue: bool = True,
|
|
275
|
+
) -> None:
|
|
238
276
|
"""Negative Acknowledgement.
|
|
239
277
|
|
|
240
278
|
:param int/long delivery_tag: Server-assigned delivery tag
|
|
@@ -259,7 +297,7 @@ class Basic(Handler):
|
|
|
259
297
|
requeue=requeue)
|
|
260
298
|
self._channel.write_frame(nack_frame)
|
|
261
299
|
|
|
262
|
-
def reject(self, delivery_tag=0, requeue=True):
|
|
300
|
+
def reject(self, delivery_tag: int = 0, requeue: bool = True) -> None:
|
|
263
301
|
"""Reject Message.
|
|
264
302
|
|
|
265
303
|
:param int/long delivery_tag: Server-assigned delivery tag
|
|
@@ -280,7 +318,7 @@ class Basic(Handler):
|
|
|
280
318
|
requeue=requeue)
|
|
281
319
|
self._channel.write_frame(reject_frame)
|
|
282
320
|
|
|
283
|
-
def _consume_add_and_get_tag(self, consume_rpc_result):
|
|
321
|
+
def _consume_add_and_get_tag(self, consume_rpc_result: dict[str, Any]) -> str:
|
|
284
322
|
"""Add the tag to the channel and return it.
|
|
285
323
|
|
|
286
324
|
:param dict consume_rpc_result:
|
|
@@ -291,8 +329,15 @@ class Basic(Handler):
|
|
|
291
329
|
self._channel.add_consumer_tag(consumer_tag)
|
|
292
330
|
return consumer_tag
|
|
293
331
|
|
|
294
|
-
def _consume_rpc_request(
|
|
295
|
-
|
|
332
|
+
def _consume_rpc_request(
|
|
333
|
+
self,
|
|
334
|
+
arguments: dict[str, Any] | None,
|
|
335
|
+
consumer_tag: str,
|
|
336
|
+
exclusive: bool,
|
|
337
|
+
no_ack: bool,
|
|
338
|
+
no_local: bool,
|
|
339
|
+
queue: str,
|
|
340
|
+
) -> dict[str, Any]:
|
|
296
341
|
"""Create a Consume Frame and execute a RPC request.
|
|
297
342
|
|
|
298
343
|
:param str queue: Queue name
|
|
@@ -313,8 +358,14 @@ class Basic(Handler):
|
|
|
313
358
|
return self._channel.rpc_request(consume_frame)
|
|
314
359
|
|
|
315
360
|
@staticmethod
|
|
316
|
-
def _validate_publish_parameters(
|
|
317
|
-
|
|
361
|
+
def _validate_publish_parameters(
|
|
362
|
+
body: Any,
|
|
363
|
+
exchange: Any,
|
|
364
|
+
immediate: Any,
|
|
365
|
+
mandatory: Any,
|
|
366
|
+
properties: Any,
|
|
367
|
+
routing_key: Any,
|
|
368
|
+
) -> None:
|
|
318
369
|
"""Validate Publish Parameters.
|
|
319
370
|
|
|
320
371
|
:param bytes,str,unicode body: Message payload
|
|
@@ -342,7 +393,7 @@ class Basic(Handler):
|
|
|
342
393
|
raise AMQPInvalidArgument('immediate should be a boolean')
|
|
343
394
|
|
|
344
395
|
@staticmethod
|
|
345
|
-
def _handle_utf8_payload(body, properties):
|
|
396
|
+
def _handle_utf8_payload(body: bytes | str, properties: dict[str, Any]) -> bytes:
|
|
346
397
|
"""Update the Body and Properties to the appropriate encoding.
|
|
347
398
|
|
|
348
399
|
:param bytes,str,unicode body: Message payload
|
|
@@ -357,7 +408,12 @@ class Basic(Handler):
|
|
|
357
408
|
body = bytes(body, encoding=encoding)
|
|
358
409
|
return body
|
|
359
410
|
|
|
360
|
-
def _get_message(
|
|
411
|
+
def _get_message(
|
|
412
|
+
self,
|
|
413
|
+
get_frame: Any,
|
|
414
|
+
auto_decode: bool,
|
|
415
|
+
message_impl: type[BaseMessage],
|
|
416
|
+
) -> BaseMessage | None:
|
|
361
417
|
"""Get and return a message using a Basic.Get frame.
|
|
362
418
|
|
|
363
419
|
:param Basic.Get get_frame:
|
|
@@ -372,14 +428,14 @@ class Basic(Handler):
|
|
|
372
428
|
)
|
|
373
429
|
try:
|
|
374
430
|
self._channel.write_frame(get_frame)
|
|
375
|
-
get_ok_frame = self._channel.rpc.get_request(
|
|
376
|
-
|
|
377
|
-
|
|
431
|
+
get_ok_frame: Any = self._channel.rpc.get_request(
|
|
432
|
+
message_uuid, raw=True, multiple=True,
|
|
433
|
+
)
|
|
378
434
|
if isinstance(get_ok_frame, commands.Basic.GetEmpty):
|
|
379
435
|
return None
|
|
380
|
-
content_header = self._channel.rpc.get_request(
|
|
381
|
-
|
|
382
|
-
|
|
436
|
+
content_header: Any = self._channel.rpc.get_request(
|
|
437
|
+
message_uuid, raw=True, multiple=True,
|
|
438
|
+
)
|
|
383
439
|
body = self._get_content_body(message_uuid,
|
|
384
440
|
content_header.body_size)
|
|
385
441
|
finally:
|
|
@@ -391,7 +447,7 @@ class Basic(Handler):
|
|
|
391
447
|
properties=dict(content_header.properties),
|
|
392
448
|
auto_decode=auto_decode)
|
|
393
449
|
|
|
394
|
-
def _publish_confirm(self, frames_out, mandatory):
|
|
450
|
+
def _publish_confirm(self, frames_out: list[Any], mandatory: bool) -> bool:
|
|
395
451
|
"""Confirm that message was published successfully.
|
|
396
452
|
|
|
397
453
|
:param list frames_out:
|
|
@@ -408,7 +464,7 @@ class Basic(Handler):
|
|
|
408
464
|
return True
|
|
409
465
|
return False
|
|
410
466
|
|
|
411
|
-
def _create_content_body(self, body):
|
|
467
|
+
def _create_content_body(self, body: bytes) -> Iterable[pamqp_body.ContentBody]:
|
|
412
468
|
"""Split body based on the maximum frame size.
|
|
413
469
|
|
|
414
470
|
This function is based on code from Rabbitpy.
|
|
@@ -418,16 +474,13 @@ class Basic(Handler):
|
|
|
418
474
|
|
|
419
475
|
:rtype: collections.Iterable
|
|
420
476
|
"""
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
end_frame = start_frame +
|
|
425
|
-
body_len = len(body)
|
|
426
|
-
if end_frame > body_len:
|
|
427
|
-
end_frame = body_len
|
|
477
|
+
body_len = len(body)
|
|
478
|
+
max_frame_size = self._max_frame_size
|
|
479
|
+
for start_frame in range(0, body_len, max_frame_size):
|
|
480
|
+
end_frame = min(start_frame + max_frame_size, body_len)
|
|
428
481
|
yield pamqp_body.ContentBody(body[start_frame:end_frame])
|
|
429
482
|
|
|
430
|
-
def _get_content_body(self, message_uuid, body_size):
|
|
483
|
+
def _get_content_body(self, message_uuid: str, body_size: int) -> bytes:
|
|
431
484
|
"""Get Content Body using RPC requests.
|
|
432
485
|
|
|
433
486
|
:param str uuid_body: Rpc Identifier.
|
|
@@ -435,11 +488,14 @@ class Basic(Handler):
|
|
|
435
488
|
|
|
436
489
|
:rtype: str
|
|
437
490
|
"""
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
491
|
+
body_parts: list[bytes] = []
|
|
492
|
+
body_len = 0
|
|
493
|
+
while body_len < body_size:
|
|
494
|
+
body_piece: Any = self._channel.rpc.get_request(
|
|
495
|
+
message_uuid, raw=True, multiple=True,
|
|
496
|
+
)
|
|
442
497
|
if not body_piece.value:
|
|
443
498
|
break
|
|
444
|
-
|
|
445
|
-
|
|
499
|
+
body_parts.append(body_piece.value)
|
|
500
|
+
body_len += len(body_piece.value)
|
|
501
|
+
return b''.join(body_parts)
|