Skip to content

Commit

Permalink
Change and add extra decoding
Browse files Browse the repository at this point in the history
- Add decoding when sending messages to fix Python 3 issues.
- Set both to ascii only as this maintains the behaviour with Python 2
  for now while in transition period.
  • Loading branch information
tofu-rocketry committed Feb 16, 2024
1 parent 4dbf4fd commit 627c9d9
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ssm/ssm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,8 @@ def _handle_msg(self, text):

def _save_msg_to_queue(self, body, empaid):
"""Extract message contents and add to the accept or reject queue."""
try:
# if not bytes will fail with "'str' obj has no attribute decode"
body = body.decode('utf-8')
except (AttributeError):
# Message type is something string related
pass
if isinstance(body, bytes):
body = body.decode('ascii')

extracted_msg, signer, err_msg = self._handle_msg(body)
try:
Expand Down Expand Up @@ -485,6 +481,8 @@ def send_all(self):
continue

text = self._outq.get(msgid)
if isinstance(text, bytes):
text = text.decode('ascii')

Check warning on line 485 in ssm/ssm2.py

View check run for this annotation

Codecov / codecov/patch

ssm/ssm2.py#L485

Added line #L485 was not covered by tests

if self._protocol == Ssm2.STOMP_MESSAGING:
# Then we are sending to a STOMP message broker.
Expand Down

0 comments on commit 627c9d9

Please sign in to comment.