Mercurial > libervia-backend
comparison src/memory/memory.py @ 466:448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 26 Mar 2012 00:22:49 +0200 |
parents | fb1abc0f8c6a |
children | 2a072735e459 |
comparison
equal
deleted
inserted
replaced
465:78e67a59d51d | 466:448ce3c9e2ac |
---|---|
489 | 489 |
490 def __init__(self, host): | 490 def __init__(self, host): |
491 info (_("Memory manager init")) | 491 info (_("Memory manager init")) |
492 self.initialized = defer.Deferred() | 492 self.initialized = defer.Deferred() |
493 self.host = host | 493 self.host = host |
494 self.contacts={} | |
495 self.presenceStatus={} | 494 self.presenceStatus={} |
496 self.lastResource={} #tmp, will be refactored with bdd integration | 495 self.lastResource={} #tmp, will be refactored with bdd integration |
497 self.subscriptions={} | 496 self.subscriptions={} |
498 self.server_features={} #used to store discovery's informations | 497 self.server_features={} #used to store discovery's informations |
499 self.server_identities={} | 498 self.server_identities={} |
653 error (_('Trying find server feature for a non-existant profile')) | 652 error (_('Trying find server feature for a non-existant profile')) |
654 return | 653 return |
655 assert(self.server_features.has_key(profile)) | 654 assert(self.server_features.has_key(profile)) |
656 return feature in self.server_features[profile] | 655 return feature in self.server_features[profile] |
657 | 656 |
658 | |
659 def addContact(self, contact_jid, attributes, groups, profile_key): | |
660 debug("Memory addContact: %s",contact_jid.userhost()) | |
661 profile = self.getProfileName(profile_key) | |
662 if not profile: | |
663 error (_('Trying to add a contact to a non-existant profile')) | |
664 return | |
665 assert(isinstance(attributes,dict)) | |
666 assert(isinstance(groups,set)) | |
667 if not self.contacts.has_key(profile): | |
668 self.contacts[profile] = {} | |
669 self.contacts[profile][contact_jid.userhost()]=[attributes, groups] | |
670 | |
671 def delContact(self, contact_jid, profile_key): | |
672 debug("Memory delContact: %s",contact_jid.userhost()) | |
673 profile = self.getProfileName(profile_key) | |
674 if not profile: | |
675 error (_('Trying to delete a contact for a non-existant profile')) | |
676 return | |
677 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): | |
678 del self.contacts[profile][contact_jid.userhost()] | |
679 | |
680 def getContact(self, contact_jid, profile_key): | |
681 profile = self.getProfileName(profile_key) | |
682 if not profile: | |
683 error(_('Asking a contact for a non-existant profile')) | |
684 return None | |
685 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): | |
686 return self.contacts[profile][contact_jid.userhost()] | |
687 | |
688 def getContacts(self, profile_key): | |
689 """Return list of contacts for given profile | |
690 @param profile_key: profile key | |
691 @return list of [contact, attr, groups]""" | |
692 profile = self.getProfileName(profile_key) | |
693 if not profile: | |
694 error(_('Asking contacts for a non-existant profile')) | |
695 return [] | |
696 ret=[] | |
697 if self.contacts.has_key(profile): | |
698 for contact in self.contacts[profile]: | |
699 attr, groups = self.contacts[profile][contact] | |
700 ret.append([contact, attr, groups ]) | |
701 return ret | |
702 | |
703 def getLastResource(self, contact, profile_key): | 657 def getLastResource(self, contact, profile_key): |
704 """Return the last resource used by a contact | 658 """Return the last resource used by a contact |
705 @param contact: contact jid (unicode) | 659 @param contact: contact jid (unicode) |
706 @param profile_key: %(doc_profile_key)s""" | 660 @param profile_key: %(doc_profile_key)s""" |
707 profile = self.getProfileName(profile_key) | 661 profile = self.getProfileName(profile_key) |