Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding parser for InfoReply and ClientListReply #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Contributors
- Aymeric Augustin <aymeric.augustin AT m4x.org>
- Daniel Arbuckle <djarb AT highenergymagic.org>
- David Creswick <dcrewi AT gyrae.net>
- David Testé <soonum AT gnu.org>
- Denya <denya.msk AT gmail.com>
- Don Brown <mrdon AT twdata.org>
- Martin Richard <martius AT martiusweb.net>
Expand Down
35 changes: 33 additions & 2 deletions asyncio_redis/replies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this print statement?

for pair in pairs:
client_info = dict(pair.split(b"=") for pair in pairs)
client_list.append(client_info)

return client_list


class PubSubReply:
Expand Down