# HG changeset patch # User Goffi # Date 1384447895 -3600 # Node ID 3c304929af74fbc839d47215e2929b591b191b54 # Parent 0c2c1dfb79e4fde01a7553afd48cbc114ba30d85 plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs. diff -r 0c2c1dfb79e4 -r 3c304929af74 src/plugins/plugin_misc_groupblog.py --- a/src/plugins/plugin_misc_groupblog.py Thu Nov 14 16:49:57 2013 +0100 +++ b/src/plugins/plugin_misc_groupblog.py Thu Nov 14 17:51:35 2013 +0100 @@ -85,7 +85,8 @@ self.host = host host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sassa{ss}s', out_sign='', - method=self.sendGroupBlog) + method=self.sendGroupBlog, + async=True) host.bridge.addMethod("sendGroupBlogComment", ".plugin", in_sign='sss', out_sign='', method=self.sendGroupBlogComment, @@ -296,6 +297,7 @@ defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) defer_blog.addErrback(self._mblogPublicationFailed) + return defer_blog def _mblogPublicationFailed(self, failure): #TODO @@ -317,19 +319,19 @@ if access_type == "PUBLIC": if access_list: raise Exception("Publishers list must be empty when getting microblogs for all contacts") - self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra) + return self._publishMblog(client.item_access_pubsub, client, "PUBLIC", [], message, extra) elif access_type == "GROUP": _groups = set(access_list).intersection(client.roster.getGroups()) # We only keep group which actually exist if not _groups: raise BadAccessListError("No valid group") - self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra) + return self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message, extra) elif access_type == "JID": raise NotImplementedError else: error(_("Unknown access type")) raise BadAccessTypeError - self.initialise(profile_key).addCallback(initialised) + return self.initialise(profile_key).addCallback(initialised) def sendGroupBlogComment(self, node_url, message, profile_key='@NONE@'): """Publish a comment in the given node diff -r 0c2c1dfb79e4 -r 3c304929af74 src/plugins/plugin_xep_0060.py --- a/src/plugins/plugin_xep_0060.py Thu Nov 14 16:49:57 2013 +0100 +++ b/src/plugins/plugin_xep_0060.py Thu Nov 14 17:51:35 2013 +0100 @@ -140,7 +140,7 @@ return for node in self.parent_plugin.managedNodes: if event.nodeIdentifier == node[0]: - return node[1](event, self.parent.profile) + node[1](event, self.parent.profile) def deleteReceived(self, event): #TODO: manage delete event diff -r 0c2c1dfb79e4 -r 3c304929af74 src/plugins/plugin_xep_0163.py --- a/src/plugins/plugin_xep_0163.py Thu Nov 14 16:49:57 2013 +0100 +++ b/src/plugins/plugin_xep_0163.py Thu Nov 14 17:51:35 2013 +0100 @@ -26,6 +26,7 @@ from wokkel import disco, pubsub from wokkel.formats import Mood +from sat.core import exceptions NS_USER_MOOD = 'http://jabber.org/protocol/mood' @@ -50,7 +51,7 @@ self.pep_out_cb = {} host.trigger.add("PubSub Disco Info", self.disoInfoTrigger) host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s') # args: from (jid), type(MOOD, TUNE, etc), data, profile - host.bridge.addMethod("sendPersonalEvent", ".plugin", in_sign='sa{ss}s', out_sign='i', method=self.sendPersonalEvent) # args: type(MOOD, TUNE, etc), data, profile_key; return 0 or error_code + host.bridge.addMethod("sendPersonalEvent", ".plugin", in_sign='sa{ss}s', out_sign='', method=self.sendPersonalEvent, async=True) # args: type(MOOD, TUNE, etc), data, profile_key; self.addPEPEvent("MOOD", NS_USER_MOOD, self.userMoodCB, self.sendMood) def disoInfoTrigger(self, disco_info, profile): @@ -66,7 +67,7 @@ @param event_type: type of the event (always uppercase), can be MOOD, TUNE, etc @param name: namespace of the node (e.g. http://jabber.org/protocol/mood for User Mood) @param in_callback: method to call when this event occur - @param out_callback: method to call when we want to publish this event + @param out_callback: method to call when we want to publish this event (must return a deferred) @param notify: add autosubscribe (+notify) if True""" if out_callback: self.pep_out_cb[event_type] = out_callback @@ -82,21 +83,21 @@ @param profile: profile which send the data""" item = pubsub.Item(payload=data) - self.host.plugins["XEP-0060"].publish(None, namespace, [item], profile_key=profile) + return self.host.plugins["XEP-0060"].publish(None, namespace, [item], profile_key=profile) def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'): """Send personal event after checking the data is alright @param event_type: type of event (eg: MOOD, TUNE), must be in self.pep_out_cb.keys() @param data: dict of {string:string} of event_type dependant data @param profile_key: profile who send the event - @return: 0 if success, error code else""" + """ profile = self.host.memory.getProfileName(profile_key) if not profile: error(_('Trying to send personal event with an unknown profile key [%s]') % profile_key) - return 1 + raise exceptions.ProfileUnknownError if not event_type in self.pep_out_cb.keys(): error(_('Trying to send personal event for an unknown type')) - return 2 + raise DataError('Type unknown') return self.pep_out_cb[event_type](data, profile) def userMoodCB(self, itemsEvent, profile): @@ -122,11 +123,9 @@ value = data['mood'].lower() text = data['text'] if 'text' in data else '' except KeyError: - error(_("Mood data must contain at least 'mood' key")) - return 3 + raise exceptions.DataError("Mood data must contain at least 'mood' key") mood = UserMood(value, text) - self.sendPEPEvent(NS_USER_MOOD, mood, profile) - return 0 + return self.sendPEPEvent(NS_USER_MOOD, mood, profile) class UserMood(Mood, domish.Element): diff -r 0c2c1dfb79e4 -r 3c304929af74 src/plugins/plugin_xep_0277.py --- a/src/plugins/plugin_xep_0277.py Thu Nov 14 16:49:57 2013 +0100 +++ b/src/plugins/plugin_xep_0277.py Thu Nov 14 17:51:35 2013 +0100 @@ -160,14 +160,13 @@ @param profile: profile which send the mood""" if 'content' not in data: error(_("Microblog data must contain at least 'content' key")) - return 3 + raise exceptions.DataError('no "content" key found') content = data['content'] if not content: error(_("Microblog data's content value must not be empty")) - return 3 + raise exceptions.DataError('empty content') item = self.data2entry(data, profile) - self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile) - return 0 + return self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile) def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'): """Get the last published microblogs