Mercurial > libervia-backend
comparison src/tools/memory.py @ 346:ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 May 2011 20:28:21 +0200 |
parents | 7c9784658163 |
children | 312ca6f9d84a |
comparison
equal
deleted
inserted
replaced
345:e6047415868d | 346:ca3a041fed30 |
---|---|
289 param_node.setAttribute('value', profile_value) | 289 param_node.setAttribute('value', profile_value) |
290 prof_xml.documentElement.appendChild(cat_copy) | 290 prof_xml.documentElement.appendChild(cat_copy) |
291 return prof_xml | 291 return prof_xml |
292 | 292 |
293 | 293 |
294 def getParamsUI(self, profile_key='@DEFAULT@'): | 294 def getParamsUI(self, profile_key): |
295 """Return a SàT XMLUI for parameters, with given profile""" | 295 """Return a SàT XMLUI for parameters, with given profile""" |
296 profile = self.getProfileName(profile_key) | 296 profile = self.getProfileName(profile_key) |
297 if not profile: | 297 if not profile: |
298 error(_("Asking params for inexistant profile")) | 298 error(_("Asking params for inexistant profile")) |
299 return "" | 299 return "" |
300 param_xml = self.getParams(profile) | 300 param_xml = self.getParams(profile) |
301 return paramsXml2xmlUI(param_xml) | 301 return paramsXml2xmlUI(param_xml) |
302 | 302 |
303 def getParams(self, profile_key='@DEFAULT@'): | 303 def getParams(self, profile_key): |
304 """Construct xml for asked profile | 304 """Construct xml for asked profile |
305 Take params xml as skeleton""" | 305 Take params xml as skeleton""" |
306 profile = self.getProfileName(profile_key) | 306 profile = self.getProfileName(profile_key) |
307 if not profile: | 307 if not profile: |
308 error(_("Asking params for inexistant profile")) | 308 error(_("Asking params for inexistant profile")) |
311 return_xml = prof_xml.toxml() | 311 return_xml = prof_xml.toxml() |
312 prof_xml.unlink() | 312 prof_xml.unlink() |
313 | 313 |
314 return return_xml | 314 return return_xml |
315 | 315 |
316 def getParamsForCategory(self, category, profile_key='@DEFAULT@'): | 316 def getParamsForCategory(self, category, profile_key): |
317 """Return node's xml for selected category""" | 317 """Return node's xml for selected category""" |
318 #TODO: manage category of general type (without existant profile) | 318 #TODO: manage category of general type (without existant profile) |
319 profile = self.getProfileName(profile_key) | 319 profile = self.getProfileName(profile_key) |
320 if not profile: | 320 if not profile: |
321 error(_("Asking params for inexistant profile")) | 321 error(_("Asking params for inexistant profile")) |
357 categories=[] | 357 categories=[] |
358 for cat in self.dom.getElementsByTagName("category"): | 358 for cat in self.dom.getElementsByTagName("category"): |
359 categories.append(cat.getAttribute("name")) | 359 categories.append(cat.getAttribute("name")) |
360 return categories | 360 return categories |
361 | 361 |
362 def setParam(self, name, value, category, profile_key='@DEFAULT@'): | 362 def setParam(self, name, value, category, profile_key): |
363 """Set a parameter, return None if the parameter is not in param xml""" | 363 """Set a parameter, return None if the parameter is not in param xml""" |
364 profile = self.getProfileName(profile_key) | 364 profile = self.getProfileName(profile_key) |
365 if not profile: | 365 if not profile: |
366 error(_('Trying to set parameter for an unknown profile')) | 366 error(_('Trying to set parameter for an unknown profile')) |
367 return #TODO: throw an error | 367 return #TODO: throw an error |
571 warning(_("Entities not available, maybe they haven't been asked to server yet ?")) | 571 warning(_("Entities not available, maybe they haven't been asked to server yet ?")) |
572 return None | 572 return None |
573 else: | 573 else: |
574 return list(entities)[0] if entities else None | 574 return list(entities)[0] if entities else None |
575 | 575 |
576 def hasServerFeature(self, feature, profile_key='@DEFAULT@'): | 576 def hasServerFeature(self, feature, profile_key): |
577 """Tell if the server of the profile has the required feature""" | 577 """Tell if the server of the profile has the required feature""" |
578 profile = self.getProfileName(profile_key) | 578 profile = self.getProfileName(profile_key) |
579 if not profile: | 579 if not profile: |
580 error (_('Trying find server feature for a non-existant profile')) | 580 error (_('Trying find server feature for a non-existant profile')) |
581 return | 581 return |
582 assert(self.server_features.has_key(profile)) | 582 assert(self.server_features.has_key(profile)) |
583 return feature in self.server_features[profile] | 583 return feature in self.server_features[profile] |
584 | 584 |
585 | 585 |
586 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): | 586 def addContact(self, contact_jid, attributes, groups, profile_key): |
587 debug("Memory addContact: %s",contact_jid.userhost()) | 587 debug("Memory addContact: %s",contact_jid.userhost()) |
588 profile = self.getProfileName(profile_key) | 588 profile = self.getProfileName(profile_key) |
589 if not profile: | 589 if not profile: |
590 error (_('Trying to add a contact to a non-existant profile')) | 590 error (_('Trying to add a contact to a non-existant profile')) |
591 return | 591 return |
593 assert(isinstance(groups,set)) | 593 assert(isinstance(groups,set)) |
594 if not self.contacts.has_key(profile): | 594 if not self.contacts.has_key(profile): |
595 self.contacts[profile] = {} | 595 self.contacts[profile] = {} |
596 self.contacts[profile][contact_jid.userhost()]=[attributes, groups] | 596 self.contacts[profile][contact_jid.userhost()]=[attributes, groups] |
597 | 597 |
598 def delContact(self, contact_jid, profile_key='@DEFAULT@'): | 598 def delContact(self, contact_jid, profile_key): |
599 debug("Memory delContact: %s",contact_jid.userhost()) | 599 debug("Memory delContact: %s",contact_jid.userhost()) |
600 profile = self.getProfileName(profile_key) | 600 profile = self.getProfileName(profile_key) |
601 if not profile: | 601 if not profile: |
602 error (_('Trying to delete a contact for a non-existant profile')) | 602 error (_('Trying to delete a contact for a non-existant profile')) |
603 return | 603 return |
604 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): | 604 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): |
605 del self.contacts[profile][contact_jid.userhost()] | 605 del self.contacts[profile][contact_jid.userhost()] |
606 | 606 |
607 def getContact(self, contact_jid, profile_key='@DEFAULT@'): | 607 def getContact(self, contact_jid, profile_key): |
608 profile = self.getProfileName(profile_key) | 608 profile = self.getProfileName(profile_key) |
609 if not profile: | 609 if not profile: |
610 error(_('Asking a contact for a non-existant profile')) | 610 error(_('Asking a contact for a non-existant profile')) |
611 return None | 611 return None |
612 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): | 612 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): |
613 self.contacts[profile][contact_jid.userhost()] | 613 return self.contacts[profile][contact_jid.userhost()] |
614 else: | 614 |
615 return None | 615 def getContacts(self, profile_key): |
616 | |
617 def getContacts(self, profile_key='@DEFAULT@'): | |
618 """Return list of contacts for given profile | 616 """Return list of contacts for given profile |
619 @param profile_key: profile key | 617 @param profile_key: profile key |
620 @return list of [contact, attr, groups]""" | 618 @return list of [contact, attr, groups]""" |
621 debug ("Memory getContact OK (%s)", self.contacts) | 619 debug ("Memory getContact OK (%s)", self.contacts) |
622 profile = self.getProfileName(profile_key) | 620 profile = self.getProfileName(profile_key) |
628 for contact in self.contacts[profile]: | 626 for contact in self.contacts[profile]: |
629 attr, groups = self.contacts[profile][contact] | 627 attr, groups = self.contacts[profile][contact] |
630 ret.append([contact, attr, groups ]) | 628 ret.append([contact, attr, groups ]) |
631 return ret | 629 return ret |
632 | 630 |
633 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): | 631 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key): |
634 profile = self.getProfileName(profile_key) | 632 profile = self.getProfileName(profile_key) |
635 if not profile: | 633 if not profile: |
636 error(_('Trying to add presence status to a non-existant profile')) | 634 error(_('Trying to add presence status to a non-existant profile')) |
637 return | 635 return |
638 if not self.presenceStatus.has_key(profile): | 636 if not self.presenceStatus.has_key(profile): |
655 profile = self.getProfileName(profile_key) | 653 profile = self.getProfileName(profile_key) |
656 assert(profile) | 654 assert(profile) |
657 if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid): | 655 if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid): |
658 del self.subscriptions[profile][contact_jid] | 656 del self.subscriptions[profile][contact_jid] |
659 | 657 |
660 def getWaitingSub(self, profile_key='@DEFAULT@'): | 658 def getWaitingSub(self, profile_key): |
661 """Called to get a list of currently waiting subscription requests""" | 659 """Called to get a list of currently waiting subscription requests""" |
662 profile = self.getProfileName(profile_key) | 660 profile = self.getProfileName(profile_key) |
663 if not profile: | 661 if not profile: |
664 error(_('Asking waiting subscriptions for a non-existant profile')) | 662 error(_('Asking waiting subscriptions for a non-existant profile')) |
665 return {} | 663 return {} |
666 if not self.subscriptions.has_key(profile): | 664 if not self.subscriptions.has_key(profile): |
667 return {} | 665 return {} |
668 | 666 |
669 return self.subscriptions[profile] | 667 return self.subscriptions[profile] |
670 | 668 |
671 def getPresenceStatus(self, profile_key='@DEFAULT@'): | 669 def getPresenceStatus(self, profile_key): |
672 profile = self.getProfileName(profile_key) | 670 profile = self.getProfileName(profile_key) |
673 if not profile: | 671 if not profile: |
674 error(_('Asking contacts for a non-existant profile')) | 672 error(_('Asking contacts for a non-existant profile')) |
675 return {} | 673 return {} |
676 if not self.presenceStatus.has_key(profile): | 674 if not self.presenceStatus.has_key(profile): |
677 self.presenceStatus[profile] = {} | 675 self.presenceStatus[profile] = {} |
678 debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile]) | 676 debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile]) |
679 return self.presenceStatus[profile] | 677 return self.presenceStatus[profile] |
680 | 678 |
681 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): | 679 def getParamA(self, name, category, attr="value", profile_key='@DEFAULT@'): |
682 return self.params.getParamA(name, category, attr, profile_key) | 680 return self.params.getParamA(name, category, attr, profile_key) |
683 | 681 |
684 def getParamsUI(self, profile_key='@DEFAULT@'): | 682 def getParamsUI(self, profile_key): |
685 return self.params.getParamsUI(profile_key) | 683 return self.params.getParamsUI(profile_key) |
686 | 684 |
687 def getParams(self, profile_key='@DEFAULT@'): | 685 def getParams(self, profile_key): |
688 return self.params.getParams(profile_key) | 686 return self.params.getParams(profile_key) |
689 | 687 |
690 def getParamsForCategory(self, category, profile_key='@DEFAULT@'): | 688 def getParamsForCategory(self, category, profile_key): |
691 return self.params.getParamsForCategory(category, profile_key) | 689 return self.params.getParamsForCategory(category, profile_key) |
692 | 690 |
693 def getParamsCategories(self): | 691 def getParamsCategories(self): |
694 return self.params.getParamsCategories() | 692 return self.params.getParamsCategories() |
695 | 693 |
696 def setParam(self, name, value, category, profile_key='@DEFAULT@'): | 694 def setParam(self, name, value, category, profile_key): |
697 return self.params.setParam(name, value, category, profile_key) | 695 return self.params.setParam(name, value, category, profile_key) |
698 | 696 |
699 def importParams(self, xml): | 697 def importParams(self, xml): |
700 return self.params.importParams(xml) | 698 return self.params.importParams(xml) |
701 | 699 |