Mercurial > libervia-web
comparison src/browser/sat_browser/contact_list.py @ 601:49ccfc22116c frontends_multi_profiles
browser_side: fixes class JIDList, remove JIDSet and JIDDict which are actually not needed
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 07 Feb 2015 19:22:45 +0100 |
parents | 32dbbc941123 |
children | ea27925ef2a8 |
comparison
equal
deleted
inserted
replaced
600:32dbbc941123 | 601:49ccfc22116c |
---|---|
586 # def refresh(self): | 586 # def refresh(self): |
587 # """Show or hide disconnected contacts and empty groups""" | 587 # """Show or hide disconnected contacts and empty groups""" |
588 # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys()) | 588 # self.updateVisibility(self._contacts_panel.contacts, self.groups.keys()) |
589 | 589 |
590 | 590 |
591 def mayContainJID(iterable, item): | 591 class JIDList(list): |
592 """Tells if the given item is in the iterable, works with JID. | 592 """JID-friendly list implementation for Pyjamas""" |
593 | |
594 @param iterable(object): list, set or another iterable object | |
595 @param item (object): element | |
596 @return: bool | |
597 """ | |
598 # Pyjamas JID-friendly implementation of the "in" operator. Since our JID | |
599 # doesn't inherit from str, without this method the test would return True | |
600 # only when the objects references are the same. | |
601 if isinstance(item, jid.JID): | |
602 return hash(item) in [hash(other) for other in iterable if isinstance(other, jid.JID)] | |
603 return super(type(iterable), iterable).__contains__(self, item) | |
604 | |
605 | |
606 class JIDSet(set): | |
607 """JID set implementation for Pyjamas""" | |
608 | 593 |
609 def __contains__(self, item): | 594 def __contains__(self, item): |
610 return mayContainJID(self, item) | 595 """Tells if the list contains the given item. |
611 | 596 |
612 | 597 @param item (object): element to check |
613 class JIDList(list): | 598 @return: bool |
614 """JID list implementation for Pyjamas""" | 599 """ |
615 | 600 # Since our JID doesn't inherit from str/unicode, without this method |
616 def __contains__(self, item): | 601 # the test would return True only when the objects references are the |
617 return mayContainJID(self, item) | 602 # same. Tests have shown that the other iterable "set" and "dict" don't |
618 | 603 # need this hack to reproduce the Twisted's behavior. |
619 | 604 for other in self: |
620 class JIDDict(dict): | 605 if other == item: |
621 """JID dict implementation for Pyjamas (a dict with JID keys)""" | 606 return True |
622 | 607 return False |
623 def __contains__(self, item): | |
624 return mayContainJID(self, item) | |
625 | |
626 def keys(self): | |
627 return JIDSet(dict.keys(self)) |