# HG changeset patch # User Goffi # Date 1495490306 -7200 # Node ID 0ffa8ba0857cd2b7ac866f0c73035785b7ee492f # Parent 61e836cc95120cf0bed889317a73795c63c034f2 core (tools/common/data_objects): added classes to handle Identities diff -r 61e836cc9512 -r 0ffa8ba0857c src/tools/common/data_objects.py --- 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