Mercurial > libervia-backend
diff src/plugins/plugin_xep_0060.py @ 303:2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
plugin XEP_0060: added some method to manage pubsub nodes
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 24 Mar 2011 21:15:26 +0100 |
parents | e33b3a777f10 |
children | 53adec87d1d7 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py Mon Feb 21 01:38:16 2011 +0100 +++ b/src/plugins/plugin_xep_0060.py Thu Mar 24 21:15:26 2011 +0100 @@ -70,10 +70,16 @@ @param profile: profile which manage this handler""" self.managedNodes.append((node_name, callback)) - def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'): + def __getClientNProfile(self, profile_key, action='do pusbsub'): + """Return a tuple of (client, profile) + raise error when the profile doesn't exists + @param profile_key: as usual :) + @param action: text of action to show in case of error""" profile = self.host.memory.getProfileName(profile_key) if not profile: - err_mess = _('Trying to publish items with an unknown profile key [%s]') % profile_key + err_mess = _('Trying to %(action)s with an unknown profile key [%(profile_key)s]') % { + 'action':action, + 'profile_key':profile_key} error(err_mess) raise Exception(err_mess) try: @@ -82,21 +88,32 @@ err_mess = _('INTERNAL ERROR: no handler for required profile') error(err_mess) raise Exception(err_mess) - client.publish(service, nodeIdentifier, items, client.parent.jid) + return profile, client + + def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'): + profile,client = self.__getClientNProfile(profile_key, 'publish item') + return client.publish(service, nodeIdentifier, items, client.parent.jid) def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'): - profile = self.host.memory.getProfileName(profile_key) - if not profile: - err_mess = _('Trying to get items with an unknown profile key [%s]') % profile_key - error(err_mess) - raise Exception(err_mess) - try: - client = self.clients[profile] - except KeyError: - err_mess = _('INTERNAL ERROR: no handler for required profile') - error(err_mess) - raise Exception(err_mess) + profile,client = self.__getClientNProfile(profile_key, 'get items') return client.items(service, node, max_items, sub_id, client.parent.jid) + + def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key='@DEFAULT@'): + profile,client = self.__getClientNProfile(profile_key, 'get options') + return client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier) + + def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key='@DEFAULT@'): + profile,client = self.__getClientNProfile(profile_key, 'set options') + return client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier) + + def createNode(self, service, nodeIdentifier, options, profile_key='@DEFAULT@'): + profile,client = self.__getClientNProfile(profile_key, 'create node') + return client.createNode(service, nodeIdentifier, options) + + def deleteNode(self, service, nodeIdentifier, profile_key='@DEFAULT@'): + profile,client = self.__getClientNProfile(profile_key, 'delete node') + return client.deleteNode(service, nodeIdentifier) + class SatPubSubClient(pubsub.PubSubClient): implements(disco.IDisco) @@ -115,8 +132,8 @@ return node[1](event, self.parent.profile) def deleteReceived(self, event): - import pdb - pdb.set_trace() + #TODO: manage delete event + debug(_("Publish node deleted")) def purgeReceived(self, event): import pdb