Skip to content

Commit cf5ba70

Browse files
committed
formatting
1 parent a003364 commit cf5ba70

File tree

5 files changed

+45
-31
lines changed

5 files changed

+45
-31
lines changed

examples/tls/tls_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self):
3636
self._count = 0
3737

3838
def on_message(self, event: Event):
39-
print("received message: " + str(event.message.body))
39+
print("received message: " + Converter.bytes_to_string(event.message.body))
4040

4141
# accepting
4242
self.delivery_context.accept(event)

rabbitmq_amqp_python_client/converter.py

-27
This file was deleted.

rabbitmq_amqp_python_client/qpid/proton/_message.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@
8686
from ._endpoints import Link
8787
from ._exceptions import (
8888
EXCEPTIONS,
89-
ArgumentOutOfRangeException,
9089
MessageException,
9190
)
9291

9392
if TYPE_CHECKING:
94-
from proton._data import Described, PythonAMQPData
93+
from proton._data import PythonAMQPData
9594
from proton._delivery import Delivery
9695
from proton._endpoints import Receiver, Sender
9796

rabbitmq_amqp_python_client/utils.py

+42
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,45 @@ def validate_annotations(annotations: []) -> bool: # type: ignore
77
validated = False
88
return validated
99
return validated
10+
11+
12+
def string_to_bytes(body: str) -> bytes:
13+
"""
14+
Convert a string to the body of a message.
15+
16+
Args:
17+
body: The string to convert
18+
19+
Returns:
20+
bytes: The byte representation of the string
21+
"""
22+
return str.encode(body)
23+
24+
25+
class Converter:
26+
27+
@staticmethod
28+
def bytes_to_string(body: bytes) -> str:
29+
"""
30+
Convert the body of a message to a string.
31+
32+
Args:
33+
body: The body of the message
34+
35+
Returns:
36+
str: The string representation of the body
37+
"""
38+
return "".join(map(chr, body))
39+
40+
@staticmethod
41+
def string_to_bytes(body: str) -> bytes:
42+
"""
43+
Convert a string to the body of a message.
44+
45+
Args:
46+
body: The string to convert
47+
48+
Returns:
49+
bytes: The byte representation of the string
50+
"""
51+
return str.encode(body)

tests/test_publisher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_publish_to_invalid_destination(connection: Connection) -> None:
131131
publisher = None
132132
try:
133133
publisher = connection.publisher("/invalid-destination/" + queue_name)
134-
publisher.publish(Message(body=string_to_bytes("test")))
134+
publisher.publish(Message(body=Converter.string_to_bytes("test")))
135135
except ArgumentOutOfRangeException:
136136
raised = True
137137
except Exception:

0 commit comments

Comments
 (0)