Mercurial > libervia-backend
diff src/tools/common/data_objects.py @ 2257:0ffa8ba0857c
core (tools/common/data_objects): added classes to handle Identities
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 22 May 2017 23:58:26 +0200 |
parents | cf6c539672c7 |
children | a8eaaac4d80f |
line wrap: on
line diff
--- a/src/tools/common/data_objects.py Sun May 21 20:08:42 2017 +0200 +++ b/src/tools/common/data_objects.py Mon May 22 23:58:26 2017 +0200 @@ -162,3 +162,32 @@ def __contains__(self, item): return self.items.__contains__(item) + + +class Identity(object): + + def __init__(self, jid_str, data=None): + self.jid_str = jid_str + self.data = data if data is not None else {} + + @property + def nick(self): + return self.data.get(u'nick') + + +class Identities(object): + + def __init__(self): + self.identities = {} + + def __getitem__(self, jid_str): + try: + return self.identities[jid_str] + except KeyError: + return None + + def __setitem__(self, jid_str, data): + self.identities[jid_str] = Identity(jid_str, data) + + def __contains__(self, jid_str): + return jid_str in self.identities