From b8bae075a954a05b825c5c6680ba77796ac29027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Test=C3=A9?= Date: Fri, 29 Dec 2017 14:35:58 +0100 Subject: [PATCH] Added parser for InfoReply and ClientListReply --- AUTHORS.rst | 1 + asyncio_redis/replies.py | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 49e1e3c..f6e3c0b 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -13,6 +13,7 @@ Contributors - Aymeric Augustin - Daniel Arbuckle - David Creswick +- David Testé - Denya - Don Brown - Martin Richard diff --git a/asyncio_redis/replies.py b/asyncio_redis/replies.py index 138d88d..72ebcc8 100644 --- a/asyncio_redis/replies.py +++ b/asyncio_redis/replies.py @@ -196,13 +196,44 @@ def __repr__(self): class InfoReply: """ :func:`~asyncio_redis.RedisProtocol.info` reply. """ def __init__(self, data): - self._data = data # TODO: implement parser logic + self._data = self._parse(data) + + @property + def data(self): + """ Received info """ + return self._data + + def _parse(self, data): + info = {} + for line in data.split(): + if not line.startswith(b"#"): + key, _, value = line.partition(b":") + info[key] = value + + return info class ClientListReply: """ :func:`~asyncio_redis.RedisProtocol.client_list` reply. """ def __init__(self, data): - self._data = data # TODO: implement parser logic + self._data = self._parse(data) + + @property + def data(self): + """ Received client list """ + return self._data + + def _parse(self, data): + client_list = [] + for line in data.splitlines(): + pairs = line.split(b" ") + client_info = {} + print(pairs) + for pair in pairs: + client_info = dict(pair.split(b"=") for pair in pairs) + client_list.append(client_info) + + return client_list class PubSubReply: