Show
Ignore:
Timestamp:
07/06/08 23:35:19 (5 months ago)
Author:
steve-e
Message:

Don't crash when we receive contacts that have a group tag assigned multiple times.

Remove some usage of has_key() in the contacts module. It is a bit slower (method overhead) and will be deprecated soon.
In roster_window. make a small if-clause more pythonic.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/contacts.py

    r9891 r9892  
    172172                self._contacts[account] = {} 
    173173                self._gc_contacts[account] = {} 
    174                 if not self._metacontacts_tags.has_key(account): 
     174                if account not in self._metacontacts_tags: 
    175175                        self._metacontacts_tags[account] = {} 
    176176 
     
    188188                chatstate=None, last_status_time=None, composing_xep=None, 
    189189                mood={}, tune={}, activity={}): 
    190                 return Contact(jid=jid, name=name, groups=groups, show=show, 
     190         
     191                # We don't want duplicated group values 
     192                groups_unique = [] 
     193                for group in groups: 
     194                        if group not in groups_unique: 
     195                                groups_unique.append(group) 
     196 
     197                return Contact(jid=jid, name=name, groups=groups_unique, show=show, 
    191198                        status=status, sub=sub, ask=ask, resource=resource, priority=priority, 
    192199                        keyID=keyID, caps_node=caps_node, caps_hash_method=caps_hash_method, 
     
    206213        def add_contact(self, account, contact): 
    207214                # No such account before ? 
    208                 if not self._contacts.has_key(account): 
     215                if account not in self._contacts: 
    209216                        self._contacts[account] = {contact.jid : [contact]} 
    210217                        return 
    211218                # No such jid before ? 
    212                 if not self._contacts[account].has_key(contact.jid): 
     219                if contact.jid not in self._contacts[account]: 
    213220                        self._contacts[account][contact.jid] = [contact] 
    214221                        return 
     
    227234 
    228235        def remove_contact(self, account, contact): 
    229                 if not self._contacts.has_key(account): 
    230                         return 
    231                 if not self._contacts[account].has_key(contact.jid): 
     236                if account not in self._contacts: 
     237                        return 
     238                if contact.jid not in self._contacts[account]: 
    232239                        return 
    233240                if contact in self._contacts[account][contact.jid]: 
     
    241248        def remove_jid(self, account, jid, remove_meta=True): 
    242249                '''Removes all contacts for a given jid''' 
    243                 if not self._contacts.has_key(account): 
    244                         return 
    245                 if not self._contacts[account].has_key(jid): 
     250                if account not in self._contacts: 
     251                        return 
     252                if jid not in self._contacts[account]: 
    246253                        return 
    247254                del self._contacts[account][jid] 
     
    387394                        self.remove_metacontact(account, jid) 
    388395                        old_tag = self.get_metacontacts_tag(account, jid) 
    389                 if not self._metacontacts_tags[account].has_key(tag): 
     396                if tag not in self._metacontacts_tags[account]: 
    390397                        self._metacontacts_tags[account][tag] = [{'jid': jid, 'tag': tag}] 
    391398                else: 
     
    558565        def add_gc_contact(self, account, gc_contact): 
    559566                # No such account before ? 
    560                 if not self._gc_contacts.has_key(account): 
     567                if account not in self._gc_contacts: 
    561568                        self._contacts[account] = {gc_contact.room_jid : {gc_contact.name: \ 
    562569                                gc_contact}} 
    563570                        return 
    564571                # No such room_jid before ? 
    565                 if not self._gc_contacts[account].has_key(gc_contact.room_jid): 
     572                if gc_contact.room_jid not in self._gc_contacts[account]: 
    566573                        self._gc_contacts[account][gc_contact.room_jid] = {gc_contact.name: \ 
    567574                                gc_contact} 
     
    571578 
    572579        def remove_gc_contact(self, account, gc_contact): 
    573                 if not self._gc_contacts.has_key(account): 
    574                         return 
    575                 if not self._gc_contacts[account].has_key(gc_contact.room_jid): 
    576                         return 
    577                 if not self._gc_contacts[account][gc_contact.room_jid].has_key( 
    578                         gc_contact.name): 
     580                if account not in self._gc_contacts: 
     581                        return 
     582                if gc_contact.room_jid not in self._gc_contacts[account]: 
     583                        return 
     584                if gc_contact.name not in self._gc_contacts[account][ 
     585                gc_contact.room_jid]: 
    579586                        return 
    580587                del self._gc_contacts[account][gc_contact.room_jid][gc_contact.name] 
     
    584591 
    585592        def remove_room(self, account, room_jid): 
    586                 if not self._gc_contacts.has_key(account): 
    587                         return 
    588                 if not self._gc_contacts[account].has_key(room_jid): 
     593                if account not in self._gc_contacts: 
     594                        return 
     595                if room_jid not in self._gc_contacts[account]: 
    589596                        return 
    590597                del self._gc_contacts[account][room_jid] 
    591598 
    592599        def get_gc_list(self, account): 
    593                 if not self._gc_contacts.has_key(account): 
     600                if account not in self._gc_contacts: 
    594601                        return [] 
    595602                return self._gc_contacts[account].keys()