diff options
author | mathieui <mathieui@mathieui.net> | 2017-10-13 23:15:03 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2017-10-13 23:15:03 +0200 |
commit | cee802b6efa027702d1e9fbaa6f440b22cc2996b (patch) | |
tree | 3073612e9c989b3445c4e431c8bd34278d8f99d5 | |
parent | 858e3332791d74c25f0abd7659276ce15db6e1cf (diff) | |
download | poezio-cee802b6efa027702d1e9fbaa6f440b22cc2996b.tar.gz poezio-cee802b6efa027702d1e9fbaa6f440b22cc2996b.tar.bz2 poezio-cee802b6efa027702d1e9fbaa6f440b22cc2996b.tar.xz poezio-cee802b6efa027702d1e9fbaa6f440b22cc2996b.zip |
Fix the last pylint error (do not set the roster contact filter to None)
-rw-r--r-- | poezio/roster.py | 20 | ||||
-rw-r--r-- | poezio/tabs/rostertab.py | 2 | ||||
-rw-r--r-- | poezio/windows/roster_win.py | 8 |
3 files changed, 18 insertions, 12 deletions
diff --git a/poezio/roster.py b/poezio/roster.py index b36442d6..96dfd396 100644 --- a/poezio/roster.py +++ b/poezio/roster.py @@ -21,21 +21,22 @@ from datetime import datetime from poezio.common import safeJID from slixmpp.exceptions import IqError, IqTimeout - class Roster(object): """ The proxy class to get the roster from slixmpp. Caches Contact and RosterGroup objects. """ + DEFAULT_FILTER = (lambda x, y: None, None) def __init__(self): """ node: the RosterSingle from slixmpp """ self.__node = None - self.contact_filter = None # A tuple(function, *args) - # function to filter contacts, - # on search, for example + + # A tuple(function, *args) function to filter contacts + # on search, for example + self.contact_filter = self.DEFAULT_FILTER self.folded_groups = set(config.get('folded_roster_groups', section='var').split(':')) self.groups = {} @@ -170,7 +171,7 @@ class Roster(object): contact_list = [] for contact in self.get_contacts(): if contact.bare_jid != self.jid: - if self.contact_filter: + if self.contact_filter is not self.DEFAULT_FILTER: if self.contact_filter[0](contact, self.contact_filter[1]): contact_list.append(contact) else: @@ -297,8 +298,13 @@ class RosterGroup(object): def get_contacts(self, contact_filter=None, sort=''): """Return the group contacts, filtered and sorted""" - contact_list = self.contacts.copy() if not contact_filter\ - else [contact for contact in self.contacts.copy() if contact_filter[0](contact, contact_filter[1])] + if contact_filter is Roster.DEFAULT_FILTER or contact_filter is None: + contact_list = self.contacts.copy() + else: + contact_list = [contact + for contact in self.contacts.copy() + if contact_filter[0](contact, contact_filter[1]) + ] contact_list = sorted(contact_list, key=SORTING_METHODS['name']) for sorting in sort.split(':'): diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index 6f8988a7..e1a8f532 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -1239,7 +1239,7 @@ class RosterInfoTab(Tab): @refresh_wrapper.always def on_search_terminate(self, txt): curses.curs_set(0) - roster.contact_filter = None + roster.contact_filter = roster.DEFAULT_FILTER self.reset_help_message() roster.modified() return True diff --git a/poezio/windows/roster_win.py b/poezio/windows/roster_win.py index eda1cf10..73191e84 100644 --- a/poezio/windows/roster_win.py +++ b/poezio/windows/roster_win.py @@ -93,25 +93,25 @@ class RosterWin(Win): return log.debug('The roster has changed, rebuilding the cacheā¦') # This is a search - if roster.contact_filter: + if roster.contact_filter is not roster.DEFAULT_FILTER: self.roster_cache = [] sort = config.get('roster_sort', 'jid:show') or 'jid:show' for contact in roster.get_contacts_sorted_filtered(sort): self.roster_cache.append(contact) else: - show_offline = config.get('roster_show_offline') or roster.contact_filter + show_offline = config.get('roster_show_offline') sort = config.get('roster_sort') or 'jid:show' group_sort = config.get('roster_group_sort') or 'name' self.roster_cache = [] # build the cache for group in roster.get_groups(group_sort): - contacts_filtered = group.get_contacts(roster.contact_filter) + contacts_filtered = group.get_contacts() if (not show_offline and group.get_nb_connected_contacts() == 0) or not contacts_filtered: continue # Ignore empty groups self.roster_cache.append(group) if group.folded: continue # ignore folded groups - for contact in group.get_contacts(roster.contact_filter, sort): + for contact in group.get_contacts(sort=sort): if not show_offline and len(contact) == 0: continue # ignore offline contacts self.roster_cache.append(contact) |