Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
302:9f3a6cf91668 | 303:2b52a5da0978 |
---|---|
68 @param namespace: NS of the handler (will appear in disco info) | 68 @param namespace: NS of the handler (will appear in disco info) |
69 @param callback: method to call when the handler is found | 69 @param callback: method to call when the handler is found |
70 @param profile: profile which manage this handler""" | 70 @param profile: profile which manage this handler""" |
71 self.managedNodes.append((node_name, callback)) | 71 self.managedNodes.append((node_name, callback)) |
72 | 72 |
73 def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'): | 73 def __getClientNProfile(self, profile_key, action='do pusbsub'): |
74 """Return a tuple of (client, profile) | |
75 raise error when the profile doesn't exists | |
76 @param profile_key: as usual :) | |
77 @param action: text of action to show in case of error""" | |
74 profile = self.host.memory.getProfileName(profile_key) | 78 profile = self.host.memory.getProfileName(profile_key) |
75 if not profile: | 79 if not profile: |
76 err_mess = _('Trying to publish items with an unknown profile key [%s]') % profile_key | 80 err_mess = _('Trying to %(action)s with an unknown profile key [%(profile_key)s]') % { |
81 'action':action, | |
82 'profile_key':profile_key} | |
77 error(err_mess) | 83 error(err_mess) |
78 raise Exception(err_mess) | 84 raise Exception(err_mess) |
79 try: | 85 try: |
80 client = self.clients[profile] | 86 client = self.clients[profile] |
81 except KeyError: | 87 except KeyError: |
82 err_mess = _('INTERNAL ERROR: no handler for required profile') | 88 err_mess = _('INTERNAL ERROR: no handler for required profile') |
83 error(err_mess) | 89 error(err_mess) |
84 raise Exception(err_mess) | 90 raise Exception(err_mess) |
85 client.publish(service, nodeIdentifier, items, client.parent.jid) | 91 return profile, client |
92 | |
93 def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'): | |
94 profile,client = self.__getClientNProfile(profile_key, 'publish item') | |
95 return client.publish(service, nodeIdentifier, items, client.parent.jid) | |
86 | 96 |
87 def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'): | 97 def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'): |
88 profile = self.host.memory.getProfileName(profile_key) | 98 profile,client = self.__getClientNProfile(profile_key, 'get items') |
89 if not profile: | |
90 err_mess = _('Trying to get items with an unknown profile key [%s]') % profile_key | |
91 error(err_mess) | |
92 raise Exception(err_mess) | |
93 try: | |
94 client = self.clients[profile] | |
95 except KeyError: | |
96 err_mess = _('INTERNAL ERROR: no handler for required profile') | |
97 error(err_mess) | |
98 raise Exception(err_mess) | |
99 return client.items(service, node, max_items, sub_id, client.parent.jid) | 99 return client.items(service, node, max_items, sub_id, client.parent.jid) |
100 | |
101 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key='@DEFAULT@'): | |
102 profile,client = self.__getClientNProfile(profile_key, 'get options') | |
103 return client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier) | |
104 | |
105 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key='@DEFAULT@'): | |
106 profile,client = self.__getClientNProfile(profile_key, 'set options') | |
107 return client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier) | |
108 | |
109 def createNode(self, service, nodeIdentifier, options, profile_key='@DEFAULT@'): | |
110 profile,client = self.__getClientNProfile(profile_key, 'create node') | |
111 return client.createNode(service, nodeIdentifier, options) | |
112 | |
113 def deleteNode(self, service, nodeIdentifier, profile_key='@DEFAULT@'): | |
114 profile,client = self.__getClientNProfile(profile_key, 'delete node') | |
115 return client.deleteNode(service, nodeIdentifier) | |
116 | |
100 | 117 |
101 class SatPubSubClient(pubsub.PubSubClient): | 118 class SatPubSubClient(pubsub.PubSubClient): |
102 implements(disco.IDisco) | 119 implements(disco.IDisco) |
103 | 120 |
104 def __init__(self, host, parent_plugin): | 121 def __init__(self, host, parent_plugin): |
113 for node in self.parent_plugin.managedNodes: | 130 for node in self.parent_plugin.managedNodes: |
114 if event.nodeIdentifier == node[0]: | 131 if event.nodeIdentifier == node[0]: |
115 return node[1](event, self.parent.profile) | 132 return node[1](event, self.parent.profile) |
116 | 133 |
117 def deleteReceived(self, event): | 134 def deleteReceived(self, event): |
118 import pdb | 135 #TODO: manage delete event |
119 pdb.set_trace() | 136 debug(_("Publish node deleted")) |
120 | 137 |
121 def purgeReceived(self, event): | 138 def purgeReceived(self, event): |
122 import pdb | 139 import pdb |
123 pdb.set_trace() | 140 pdb.set_trace() |
124 | 141 |