plugin XEP_0277: microblog access model can now be changed

plugin XEP_0060: added some method to manage pubsub nodes
This commit is contained in:
Goffi 2011-03-24 21:15:26 +01:00
commit 7f918c4c52

View file

@ -70,10 +70,16 @@ class XEP_0060():
@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 @@ class XEP_0060():
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 @@ class SatPubSubClient(pubsub.PubSubClient):
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