comparison sat_frontends/quick_frontend/quick_contact_management.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from sat.core.log import getLogger 21 from sat.core.log import getLogger
22
22 log = getLogger(__name__) 23 log = getLogger(__name__)
23 from sat_frontends.tools.jid import JID 24 from sat_frontends.tools.jid import JID
24 25
25 26
26 class QuickContactManagement(object): 27 class QuickContactManagement(object):
27 """This helper class manage the contacts and ease the use of nicknames and shortcuts""" 28 """This helper class manage the contacts and ease the use of nicknames and shortcuts"""
29
28 ### FIXME: is SàT a better place for all this stuff ??? ### 30 ### FIXME: is SàT a better place for all this stuff ??? ###
29 31
30 def __init__(self): 32 def __init__(self):
31 self.__contactlist = {} 33 self.__contactlist = {}
32 34
38 self.__contactlist.clear() 40 self.__contactlist.clear()
39 41
40 def add(self, entity): 42 def add(self, entity):
41 """Add contact to the list, update resources""" 43 """Add contact to the list, update resources"""
42 if not self.__contactlist.has_key(entity.bare): 44 if not self.__contactlist.has_key(entity.bare):
43 self.__contactlist[entity.bare] = {'resources':[]} 45 self.__contactlist[entity.bare] = {"resources": []}
44 if not entity.resource: 46 if not entity.resource:
45 return 47 return
46 if entity.resource in self.__contactlist[entity.bare]['resources']: 48 if entity.resource in self.__contactlist[entity.bare]["resources"]:
47 self.__contactlist[entity.bare]['resources'].remove(entity.resource) 49 self.__contactlist[entity.bare]["resources"].remove(entity.resource)
48 self.__contactlist[entity.bare]['resources'].append(entity.resource) 50 self.__contactlist[entity.bare]["resources"].append(entity.resource)
49 51
50 def getContFromGroup(self, group): 52 def getContFromGroup(self, group):
51 """Return all contacts which are in given group""" 53 """Return all contacts which are in given group"""
52 result = [] 54 result = []
53 for contact in self.__contactlist: 55 for contact in self.__contactlist:
54 if self.__contactlist[contact].has_key('groups'): 56 if self.__contactlist[contact].has_key("groups"):
55 if group in self.__contactlist[contact]['groups']: 57 if group in self.__contactlist[contact]["groups"]:
56 result.append(JID(contact)) 58 result.append(JID(contact))
57 return result 59 return result
58 60
59 def getAttr(self, entity, name): 61 def getAttr(self, entity, name):
60 """Return a specific attribute of contact, or all attributes 62 """Return a specific attribute of contact, or all attributes
61 @param entity: jid of the contact 63 @param entity: jid of the contact
62 @param name: name of the attribute 64 @param name: name of the attribute
63 @return: asked attribute""" 65 @return: asked attribute"""
64 if self.__contactlist.has_key(entity.bare): 66 if self.__contactlist.has_key(entity.bare):
65 if name == 'status': #FIXME: for the moment, we only use the first status 67 if name == "status": # FIXME: for the moment, we only use the first status
66 if self.__contactlist[entity.bare]['statuses']: 68 if self.__contactlist[entity.bare]["statuses"]:
67 return self.__contactlist[entity.bare]['statuses'].values()[0] 69 return self.__contactlist[entity.bare]["statuses"].values()[0]
68 if self.__contactlist[entity.bare].has_key(name): 70 if self.__contactlist[entity.bare].has_key(name):
69 return self.__contactlist[entity.bare][name] 71 return self.__contactlist[entity.bare][name]
70 else: 72 else:
71 log.debug(_('Trying to get attribute for an unknown contact')) 73 log.debug(_("Trying to get attribute for an unknown contact"))
72 return None 74 return None
73 75
74 def isConnected(self, entity): 76 def isConnected(self, entity):
75 """Tell if the contact is online""" 77 """Tell if the contact is online"""
76 return self.__contactlist.has_key(entity.bare) 78 return self.__contactlist.has_key(entity.bare)
77 79
78 def remove(self, entity): 80 def remove(self, entity):
79 """remove resource. If no more resource is online or is no resource is specified, contact is deleted""" 81 """remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
80 try: 82 try:
81 if entity.resource: 83 if entity.resource:
82 self.__contactlist[entity.bare]['resources'].remove(entity.resource) 84 self.__contactlist[entity.bare]["resources"].remove(entity.resource)
83 if not entity.resource or not self.__contactlist[entity.bare]['resources']: 85 if not entity.resource or not self.__contactlist[entity.bare]["resources"]:
84 #no more resource available: the contact seems really disconnected 86 # no more resource available: the contact seems really disconnected
85 del self.__contactlist[entity.bare] 87 del self.__contactlist[entity.bare]
86 except KeyError: 88 except KeyError:
87 log.error(_('INTERNAL ERROR: Key log.error')) 89 log.error(_("INTERNAL ERROR: Key log.error"))
88 raise 90 raise
89 91
90 def update(self, entity, key, value): 92 def update(self, entity, key, value):
91 """Update attribute of contact 93 """Update attribute of contact
92 @param entity: jid of the contact 94 @param entity: jid of the contact
94 @param value: value of the attribute 96 @param value: value of the attribute
95 """ 97 """
96 if self.__contactlist.has_key(entity.bare): 98 if self.__contactlist.has_key(entity.bare):
97 self.__contactlist[entity.bare][key] = value 99 self.__contactlist[entity.bare][key] = value
98 else: 100 else:
99 log.debug (_('Trying to update an unknown contact: %s') % entity.bare) 101 log.debug(_("Trying to update an unknown contact: %s") % entity.bare)
100 102
101 def get_full(self, entity): 103 def get_full(self, entity):
102 return entity.bare+'/'+self.__contactlist[entity.bare]['resources'][-1] 104 return entity.bare + "/" + self.__contactlist[entity.bare]["resources"][-1]
103