Mercurial > libervia-web
comparison src/browser/sat_browser/contact_list.py @ 608:ea27925ef2a8 frontends_multi_profiles
merges souliane changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 09 Feb 2015 21:58:49 +0100 |
parents | 537649f6a2d0 49ccfc22116c |
children | 14bdf5394ae9 |
comparison
equal
deleted
inserted
replaced
607:537649f6a2d0 | 608:ea27925ef2a8 |
---|---|
600 # def refresh(self): | 600 # def refresh(self): |
601 # """Show or hide disconnected contacts and empty groups""" | 601 # """Show or hide disconnected contacts and empty groups""" |
602 # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys()) | 602 # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys()) |
603 | 603 |
604 | 604 |
605 def mayContainJID(iterable, item): | 605 class JIDList(list): |
606 """Tells if the given item is in the iterable, works with JID. | 606 """JID-friendly list implementation for Pyjamas""" |
607 | |
608 @param iterable(object): list, set or another iterable object | |
609 @param item (object): element | |
610 @return: bool | |
611 """ | |
612 # Pyjamas JID-friendly implementation of the "in" operator. Since our JID | |
613 # doesn't inherit from str, without this method the test would return True | |
614 # only when the objects references are the same. | |
615 if isinstance(item, jid.JID): | |
616 return hash(item) in [hash(other) for other in iterable if isinstance(other, jid.JID)] | |
617 return super(type(iterable), iterable).__contains__(self, item) | |
618 | |
619 | |
620 class JIDSet(set): | |
621 """JID set implementation for Pyjamas""" | |
622 | 607 |
623 def __contains__(self, item): | 608 def __contains__(self, item): |
624 return mayContainJID(self, item) | 609 """Tells if the list contains the given item. |
625 | 610 |
626 | 611 @param item (object): element to check |
627 class JIDList(list): | 612 @return: bool |
628 """JID list implementation for Pyjamas""" | 613 """ |
629 | 614 # Since our JID doesn't inherit from str/unicode, without this method |
630 def __contains__(self, item): | 615 # the test would return True only when the objects references are the |
631 return mayContainJID(self, item) | 616 # same. Tests have shown that the other iterable "set" and "dict" don't |
632 | 617 # need this hack to reproduce the Twisted's behavior. |
633 | 618 for other in self: |
634 class JIDDict(dict): | 619 if other == item: |
635 """JID dict implementation for Pyjamas (a dict with JID keys)""" | 620 return True |
636 | 621 return False |
637 def __contains__(self, item): | |
638 return mayContainJID(self, item) | |
639 | |
640 def keys(self): | |
641 return JIDSet(dict.keys(self)) |