Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
2256:61e836cc9512 | 2257:0ffa8ba0857c |
---|---|
160 def __reversed__(self): | 160 def __reversed__(self): |
161 return self.items.__reversed__() | 161 return self.items.__reversed__() |
162 | 162 |
163 def __contains__(self, item): | 163 def __contains__(self, item): |
164 return self.items.__contains__(item) | 164 return self.items.__contains__(item) |
165 | |
166 | |
167 class Identity(object): | |
168 | |
169 def __init__(self, jid_str, data=None): | |
170 self.jid_str = jid_str | |
171 self.data = data if data is not None else {} | |
172 | |
173 @property | |
174 def nick(self): | |
175 return self.data.get(u'nick') | |
176 | |
177 | |
178 class Identities(object): | |
179 | |
180 def __init__(self): | |
181 self.identities = {} | |
182 | |
183 def __getitem__(self, jid_str): | |
184 try: | |
185 return self.identities[jid_str] | |
186 except KeyError: | |
187 return None | |
188 | |
189 def __setitem__(self, jid_str, data): | |
190 self.identities[jid_str] = Identity(jid_str, data) | |
191 | |
192 def __contains__(self, jid_str): | |
193 return jid_str in self.identities |