Skip to content

Commit a00d9c1

Browse files
author
Alan Christie
committed
chore: Switch to bytes()
1 parent 3fb2c82 commit a00d9c1

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

app/app.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,14 @@ async def on_message_for_websocket(
405405
# - timestamp: int (milliseconds since Python time epoch)
406406
# It's essentially time.time() x 1000
407407
r_stream = message_context.consumer.get_stream(message_context.subscriber_name)
408-
_LOGGER.info(
408+
_LOGGER.debug(
409409
"Got msg=%s stream=%s es_id=%s /%s/",
410410
msg,
411411
r_stream,
412412
es_id,
413413
es_websocket_uuid,
414414
)
415-
_LOGGER.info(
415+
_LOGGER.debug(
416416
"With offset=%s timestamp=%s /%s/",
417417
message_context.offset,
418418
message_context.timestamp,
@@ -448,12 +448,10 @@ async def on_message_for_websocket(
448448
shutdown = True
449449
elif msg:
450450
_LOGGER.info("PREPARING %s", message_context.offset)
451-
# The msg (an AMQPMessage) cannot be decoded directly.
452-
# Instead, if we want to manipulate it (as a string)
453-
# we must str() it and eval() it! It's the easiest way because this way
454-
# it becomes a string representation of a bytestring, not a bytestring.
455-
# Once we eval() it it becomes a bytestring and we can decode it.
456-
message_string = eval(str(msg)).decode("utf-8") # pylint: disable=eval-used
451+
# The msg (an AMQPMessage) cannot be decoded directly, but we can
452+
# invoke its built-in __bytes__() representation to get the message as bytes.
453+
# We can then decode it to get a string we can manipulate.
454+
message_string = bytes(msg).decode("utf-8")
457455
_LOGGER.info("TRIMMED %s", message_context.offset)
458456
if message_string[0] == "{":
459457
_LOGGER.info("IS JSON %s", message_context.offset)

0 commit comments

Comments
 (0)