comparison src/memory/memory.py @ 747:5aff0beddb28

core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
author souliane <souliane@mailoo.org>
date Mon, 16 Dec 2013 14:35:26 +0100
parents 03744d9ebc13
children 1def5b7edf9f
comparison
equal deleted inserted replaced
746:539f278bc265 747:5aff0beddb28
758 758
759 def addServerFeature(self, feature, jid_, profile): 759 def addServerFeature(self, feature, jid_, profile):
760 """Add a feature discovered from server 760 """Add a feature discovered from server
761 @param feature: string of the feature 761 @param feature: string of the feature
762 @param jid_: the jid of the target server 762 @param jid_: the jid of the target server
763 @param profile: which profile is asking this server ?""" 763 @param profile: which profile asked this server?"""
764 if profile not in self.server_features: 764 if profile not in self.server_features:
765 self.server_features[profile] = {} 765 self.server_features[profile] = {}
766 features = self.server_features[profile].setdefault(jid_, []) 766 features = self.server_features[profile].setdefault(jid_, [])
767 features.append(feature) 767 features.append(feature)
768 768
769 def addServerIdentity(self, category, type_, entity, jid_, profile): 769 def addServerIdentity(self, category, type_, entity, jid_, profile):
770 """Add an identity discovered from server 770 """Add an identity discovered from server
771 @param feature: string of the feature 771 @param feature: string of the feature
772 @param jid_: the jid of the target server 772 @param jid_: the jid of the target server
773 @param profile: which profile is asking this server ?""" 773 @param profile: which profile asked this server?"""
774 if not profile in self.server_identities: 774 if not profile in self.server_identities:
775 self.server_identities[profile] = {} 775 self.server_identities[profile] = {}
776 identities = self.server_identities[profile].setdefault(jid_, {}) 776 identities = self.server_identities[profile].setdefault(jid_, {})
777 if (category, type_) not in identities: 777 if (category, type_) not in identities:
778 identities[(category, type_)] = set() 778 identities[(category, type_)] = set()
779 identities[(category, type_)].add(entity) 779 identities[(category, type_)].add(entity)
780 780
781 def getServerServiceEntities(self, category, type_, jid_=None, profile=None): 781 def getServerServiceEntities(self, category, type_, jid_=None, profile=None):
782 """Return all available entities for a service""" 782 """Return all available entities of a server for the service (category, type_)
783 @param category: identity's category
784 @param type_: identitiy's type
785 @param jid_: the jid of the target server (None for profile's server)
786 @param profile: which profile is asking this server?
787 @return: a set of entities or None if no cached data were found
788 """
783 if jid_ is None: 789 if jid_ is None:
784 jid_ = self.host.getClientHostJid(profile) 790 jid_ = self.host.getClientHostJid(profile)
785 if profile in self.server_identities and jid_ in self.server_identities[profile]: 791 if profile in self.server_identities and jid_ in self.server_identities[profile]:
786 return self.server_identities[profile][jid_].get((category, type_), set()) 792 return self.server_identities[profile][jid_].get((category, type_), set())
787 else: 793 else:
788 return None 794 return None
789 795
790 def getServerServiceEntity(self, category, type_, jid_=None, profile=None): 796 def getServerServiceEntity(self, category, type_, jid_=None, profile=None):
791 """Helper method to get first available entity for a service""" 797 """Helper method to get first available entity of a server for the service (category, type_)
792 if jid_ is None: 798 @param category: identity's category
793 jid_ = self.host.getClientHostJid(profile) 799 @param type_: identitiy's type
800 @param jid_: the jid of the target server (None for profile's server)
801 @param profile: which profile is asking this server?
802 @return: the first found entity or None if no cached data were found
803 """
794 entities = self.getServerServiceEntities(category, type_, jid_, profile) 804 entities = self.getServerServiceEntities(category, type_, jid_, profile)
795 if entities is None: 805 if entities is None:
796 warning(_("Entities (%(category)s/%(type)s) of %(server)s not available, maybe they haven't been asked yet?") 806 warning(_("Entities (%(category)s/%(type)s) of %(server)s not available, maybe they haven't been asked yet?")
797 % {"category": category, "type": type_, "server": jid_}) 807 % {"category": category, "type": type_, "server": jid_})
798 return None 808 return None
799 else: 809 else:
800 return list(entities)[0] if entities else None 810 return list(entities)[0] if entities else None
801 811
812 def getAllServerIdentities(self, jid_, profile):
813 """Helper method to get all identities of a server
814 @param jid_: the jid of the target server (None for profile's server)
815 @param profile: which profile is asking this server?
816 @return: a set of entities or None if no cached data were found
817 """
818 if jid_ is None:
819 jid_ = self.host.getClientHostJid(profile)
820 if jid_ not in self.server_identities[profile]:
821 return None
822 entities = set()
823 for set_ in self.server_identities[profile][jid_].values():
824 entities.update(set_)
825 return entities
826
802 def hasServerFeature(self, feature, jid_=None, profile_key="@NONE@"): 827 def hasServerFeature(self, feature, jid_=None, profile_key="@NONE@"):
803 """Tell if the server of the profile has the required feature""" 828 """Tell if the specified server has the required feature
829 @param feature: requested feature
830 @param jid_: the jid of the target server (None for profile's server)
831 @param profile: which profile is asking this server?
832 """
804 profile = self.getProfileName(profile_key) 833 profile = self.getProfileName(profile_key)
805 if not profile: 834 if not profile:
806 error(_('Trying find server feature for a non-existant profile')) 835 error(_('Trying find server feature for a non-existant profile'))
807 return None 836 return None
808 assert profile in self.server_features 837 assert profile in self.server_features