comparison frontends/src/quick_frontend/quick_contact_list.py @ 1391:1276e6a0716b

quick_frontend: better PEP-8 compliance
author souliane <souliane@mailoo.org>
date Wed, 25 Mar 2015 15:21:17 +0100
parents 017270e6eea4
children 50d5d6325f62
comparison
equal deleted inserted replaced
1390:337be5318177 1391:1276e6a0716b
25 from sat_frontends.tools import jid 25 from sat_frontends.tools import jid
26 26
27 27
28 try: 28 try:
29 # FIXME: to be removed when an acceptable solution is here 29 # FIXME: to be removed when an acceptable solution is here
30 unicode('') # XXX: unicode doesn't exist in pyjamas 30 unicode('') # XXX: unicode doesn't exist in pyjamas
31 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options 31 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
32 # XXX: pyjamas' max doesn't support key argument, so we implement it ourself 32 # XXX: pyjamas' max doesn't support key argument, so we implement it ourself
33 pyjamas_max = max 33 pyjamas_max = max
34
34 def max(iterable, key): 35 def max(iterable, key):
35 iter_cpy = list(iterable) 36 iter_cpy = list(iterable)
36 iter_cpy.sort(key=key) 37 iter_cpy.sort(key=key)
37 return pyjamas_max(iter_cpy) 38 return pyjamas_max(iter_cpy)
38 39
50 self._specials = set() 51 self._specials = set()
51 # extras are specials with full jids (e.g.: private MUC conversation) 52 # extras are specials with full jids (e.g.: private MUC conversation)
52 self._special_extras = set() 53 self._special_extras = set()
53 54
54 # group data contain jids in groups and misc frontend data 55 # group data contain jids in groups and misc frontend data
55 self._groups = {} # groups to group data map 56 self._groups = {} # groups to group data map
56 57
57 # contacts in roster (bare jids) 58 # contacts in roster (bare jids)
58 self._roster = set() 59 self._roster = set()
59 60
60 # entities with an alert (usually a waiting message), full jid 61 # entities with an alert (usually a waiting message), full jid
170 main_resource = cache[C.CONTACT_MAIN_RESOURCE] 171 main_resource = cache[C.CONTACT_MAIN_RESOURCE]
171 cache = cache[C.CONTACT_RESOURCES][main_resource] 172 cache = cache[C.CONTACT_RESOURCES][main_resource]
172 else: 173 else:
173 cache = cache[C.CONTACT_RESOURCES][entity.resource] 174 cache = cache[C.CONTACT_RESOURCES][entity.resource]
174 175
175 if name == 'status': #XXX: we get the first status for 'status' key 176 if name == 'status': # XXX: we get the first status for 'status' key
176 # TODO: manage main language for statuses 177 # TODO: manage main language for statuses
177 return cache[C.PRESENCE_STATUSES].get('default','') 178 return cache[C.PRESENCE_STATUSES].get('default', '')
178 179
179 return cache[name] 180 return cache[name]
180 except KeyError: 181 except KeyError:
181 return None 182 return None
182 183
197 """ 198 """
198 if entity.resource: 199 if entity.resource:
199 raise ValueError("getFullJid must be used with a bare jid") 200 raise ValueError("getFullJid must be used with a bare jid")
200 main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE) 201 main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE)
201 return jid.JID(u"{}/{}".format(entity, main_resource)) 202 return jid.JID(u"{}/{}".format(entity, main_resource))
202
203 203
204 def setGroupData(self, group, name, value): 204 def setGroupData(self, group, name, value):
205 """Register a data for a group 205 """Register a data for a group
206 206
207 @param group: a valid (existing) group name 207 @param group: a valid (existing) group name
383 """ 383 """
384 cache = self.getCache(entity) 384 cache = self.getCache(entity)
385 if show == C.PRESENCE_UNAVAILABLE: 385 if show == C.PRESENCE_UNAVAILABLE:
386 if not entity.resource: 386 if not entity.resource:
387 cache[C.CONTACT_RESOURCES].clear() 387 cache[C.CONTACT_RESOURCES].clear()
388 cache[C.CONTACT_MAIN_RESOURCE]= None 388 cache[C.CONTACT_MAIN_RESOURCE] = None
389 else: 389 else:
390 try: 390 try:
391 del cache[C.CONTACT_RESOURCES][entity.resource] 391 del cache[C.CONTACT_RESOURCES][entity.resource]
392 except KeyError: 392 except KeyError:
393 log.error("Presence unavailable received for an unknown resource [{}]".format(entity)) 393 log.error("Presence unavailable received for an unknown resource [{}]".format(entity))
410 410
411 @param entity(jid.JID): entity updated 411 @param entity(jid.JID): entity updated
412 @param new_nick(unicode): new nick of the entity 412 @param new_nick(unicode): new nick of the entity
413 @param profile: %(doc_profile)s 413 @param profile: %(doc_profile)s
414 """ 414 """
415 raise NotImplementedError # Must be implemented by frontends 415 raise NotImplementedError # Must be implemented by frontends
416 416
417 def unselectAll(self): 417 def unselectAll(self):
418 """Unselect all contacts""" 418 """Unselect all contacts"""
419 self._selected.clear() 419 self._selected.clear()
420 self.update() 420 self.update()