core (tools/common/data_objects): added classes to handle Identities

This commit is contained in:
Goffi 2017-05-22 23:58:26 +02:00
commit 4dee63d105

View file

@ -162,3 +162,32 @@ class BlogItems(object):
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