From 2f7507500a62c9f4159bb75f12f41658bdd4450e Mon Sep 17 00:00:00 2001 From: ZijianGuo Date: Mon, 10 May 2021 15:06:59 +0800 Subject: [PATCH] Decode bytes to strings Change-Id: I6c8a4b2c9b62ca2d1c11aa633ad2389786216162 Signed-off-by: ZijianGuo --- zaqar/storage/redis/models.py | 8 ++++---- zaqar/storage/redis/subscriptions.py | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/zaqar/storage/redis/models.py b/zaqar/storage/redis/models.py index 1deda4dd8..774e88a3a 100644 --- a/zaqar/storage/redis/models.py +++ b/zaqar/storage/redis/models.py @@ -157,8 +157,8 @@ class SubscriptionEnvelope(object): is_confirmed = bool(self.confirmed) basic_msg = { 'id': self.id, - 'source': self.source.decode(), - 'subscriber': self.subscriber.decode(), + 'source': encodeutils.safe_decode(self.source), + 'subscriber': encodeutils.safe_decode(self.subscriber), 'ttl': self.ttl, 'age': now - created, 'options': self.options, @@ -318,8 +318,8 @@ def _hmap_to_subenv_kwargs(hmap): # into binary. Woohoo! return { 'id': encodeutils.safe_decode(hmap[b'id']), - 'source': hmap[b's'], - 'subscriber': hmap[b'u'], + 'source': encodeutils.safe_decode(hmap[b's']), + 'subscriber': encodeutils.safe_decode(hmap[b'u']), 'ttl': int(hmap[b't']), 'expires': int(hmap[b'e']), 'options': _unpack(hmap[b'o']), diff --git a/zaqar/storage/redis/subscriptions.py b/zaqar/storage/redis/subscriptions.py index 4679b4367..7b516e2d6 100644 --- a/zaqar/storage/redis/subscriptions.py +++ b/zaqar/storage/redis/subscriptions.py @@ -15,6 +15,7 @@ import functools import msgpack +from oslo_utils import encodeutils from oslo_utils import timeutils from oslo_utils import uuidutils import redis @@ -78,8 +79,8 @@ class SubscriptionController(base.Subscription): is_confirmed = int(record[5]) ret = { 'id': sid, - 'source': record[0].decode(), - 'subscriber': record[1].decode(), + 'source': encodeutils.safe_decode(record[0]), + 'subscriber': encodeutils.safe_decode(record[1]), 'ttl': ttl, 'age': now - created, 'options': self._unpacker(record[4]), @@ -167,7 +168,7 @@ class SubscriptionController(base.Subscription): # the subscription but the id is still there. So let's # delete the id for clean up. self._client.zrem(subset_key, s_id) - if subscription[1].decode() == subscriber: + if encodeutils.safe_decode(subscription[1]) == subscriber: return True return False except redis.exceptions.ResponseError: @@ -251,7 +252,7 @@ class SubscriptionController(base.Subscription): for s_id in sub_ids: subscription = self._client.hmget(s_id, ['s', 'u', 't', 'o', 'c']) - if subscription[1].decode() == subscriber: + if encodeutils.safe_decode(subscription[1]) == subscriber: subscription = SubscriptionEnvelope.from_redis(s_id, self._client) now = timeutils.utcnow_ts()