core (tools/common/data_objects): added classes to handle Identities
This commit is contained in:
parent
0b154647e4
commit
4dee63d105
1 changed files with 29 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue