comparison src/plugins/plugin_misc_groupblog.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children beaf6bec2fcd
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
80 info(_("Group blog plugin initialization")) 80 info(_("Group blog plugin initialization"))
81 self.host = host 81 self.host = host
82 82
83 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='', 83 host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='',
84 method=self.sendGroupBlog) 84 method=self.sendGroupBlog)
85 85
86 host.bridge.addMethod("getLastGroupBlogs", ".plugin", 86 host.bridge.addMethod("getLastGroupBlogs", ".plugin",
87 in_sign='sis', out_sign='aa{ss}', 87 in_sign='sis', out_sign='aa{ss}',
88 method=self.getLastGroupBlogs, 88 method=self.getLastGroupBlogs,
89 async = True) 89 async = True)
90 90
91 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin", 91 host.bridge.addMethod("getMassiveLastGroupBlogs", ".plugin",
92 in_sign='sasis', out_sign='a{saa{ss}}', 92 in_sign='sasis', out_sign='a{saa{ss}}',
93 method=self.getMassiveLastGroupBlogs, 93 method=self.getMassiveLastGroupBlogs,
94 async = True) 94 async = True)
95 95
96 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='', 96 host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
97 method=self.subscribeGroupBlog, 97 method=self.subscribeGroupBlog,
98 async = True) 98 async = True)
99 99
100 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='', 100 host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
101 method=self.massiveSubscribeGroupBlogs, 101 method=self.massiveSubscribeGroupBlogs,
102 async = True) 102 async = True)
103 103
104 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger) 104 host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
105 105
106 106
107 def getHandler(self, profile): 107 def getHandler(self, profile):
108 return GroupBlog_handler() 108 return GroupBlog_handler()
109 109
110 @defer.inlineCallbacks 110 @defer.inlineCallbacks
111 def initialise(self, profile_key): 111 def initialise(self, profile_key):
112 """Check that this data for this profile are initialised, and do it else 112 """Check that this data for this profile are initialised, and do it else
113 @param client: client of the profile 113 @param client: client of the profile
114 @profile_key: %(doc_profile)s""" 114 @profile_key: %(doc_profile)s"""
115 profile = self.host.memory.getProfileName(profile_key) 115 profile = self.host.memory.getProfileName(profile_key)
116 if not profile: 116 if not profile:
117 error(_("Unknown profile")) 117 error(_("Unknown profile"))
118 raise Exception("Unknown profile") 118 raise Exception("Unknown profile")
119 119
120 client = self.host.getClient(profile) 120 client = self.host.getClient(profile)
121 if not client: 121 if not client:
122 error(_('No client for this profile key: %s') % profile_key) 122 error(_('No client for this profile key: %s') % profile_key)
123 raise Exception("Unknown profile") 123 raise Exception("Unknown profile")
124 yield client.client_initialized #we want to be sure that the client is initialized 124 yield client.client_initialized #we want to be sure that the client is initialized
125 125
126 #we first check that we have a item-access pubsub server 126 #we first check that we have a item-access pubsub server
127 if not hasattr(client,"item_access_pubsub"): 127 if not hasattr(client,"item_access_pubsub"):
128 debug(_('Looking for item-access power pubsub server')) 128 debug(_('Looking for item-access power pubsub server'))
129 #we don't have any pubsub server featuring item access yet 129 #we don't have any pubsub server featuring item access yet
130 client.item_access_pubsub = None 130 client.item_access_pubsub = None
134 #if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features): 134 #if set([NS_PUBSUB_ITEM_ACCESS, NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features):
135 if set([NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features): 135 if set([NS_PUBSUB_AUTO_CREATE, NS_PUBSUB_CREATOR_JID_CHECK]).issubset(_disco.features):
136 info(_("item-access powered pubsub service found: [%s]") % entity.full()) 136 info(_("item-access powered pubsub service found: [%s]") % entity.full())
137 client.item_access_pubsub = entity 137 client.item_access_pubsub = entity
138 client._item_access_pubsub_pending.callback(None) 138 client._item_access_pubsub_pending.callback(None)
139 139
140 if hasattr(client,"_item_access_pubsub_pending"): 140 if hasattr(client,"_item_access_pubsub_pending"):
141 #XXX: we need to wait for item access pubsub service check 141 #XXX: we need to wait for item access pubsub service check
142 yield client._item_access_pubsub_pending 142 yield client._item_access_pubsub_pending
143 del client._item_access_pubsub_pending 143 del client._item_access_pubsub_pending
144 144
172 172
173 def _parseAccessData(self, microblog_data, item): 173 def _parseAccessData(self, microblog_data, item):
174 form_elts = filter(lambda elt: elt.name == "x", item.children) 174 form_elts = filter(lambda elt: elt.name == "x", item.children)
175 for form_elt in form_elts: 175 for form_elt in form_elts:
176 form = data_form.Form.fromElement(form_elt) 176 form = data_form.Form.fromElement(form_elt)
177 177
178 if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG): 178 if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG):
179 access_model = form.get(OPT_ACCESS_MODEL, 'open') 179 access_model = form.get(OPT_ACCESS_MODEL, 'open')
180 if access_model == "roster": 180 if access_model == "roster":
181 try: 181 try:
182 microblog_data["groups"] = '\n'.join(form.fields[OPT_ROSTER_GROUPS_ALLOWED].values) 182 microblog_data["groups"] = '\n'.join(form.fields[OPT_ROSTER_GROUPS_ALLOWED].values)
183 except KeyError: 183 except KeyError:
184 warning("No group found for roster access-model") 184 warning("No group found for roster access-model")
185 microblog_data["groups"] = '' 185 microblog_data["groups"] = ''
186 186
187 break 187 break
188 188
189 def item2gbdata(self, item): 189 def item2gbdata(self, item):
190 """ Convert item to microblog data dictionary + add access data """ 190 """ Convert item to microblog data dictionary + add access data """
191 microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item) 191 microblog_data = self.host.plugins["XEP-0277"].item2mbdata(item)
256 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message) 256 self._publishMblog(client.item_access_pubsub, client, "GROUP", _groups, message)
257 elif access_type == "JID": 257 elif access_type == "JID":
258 raise NotImplementedError 258 raise NotImplementedError
259 else: 259 else:
260 error(_("Unknown access type")) 260 error(_("Unknown access type"))
261 raise BadAccessTypeError 261 raise BadAccessTypeError
262 262
263 self.initialise(profile_key).addCallback(initialised) 263 self.initialise(profile_key).addCallback(initialised)
264 264
265 265
266 266
267 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'): 267 def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
268 """Get the last published microblogs 268 """Get the last published microblogs
269 @param pub_jid: jid of the publisher 269 @param pub_jid: jid of the publisher
270 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7) 270 @param max_items: how many microblogs we want to get (see XEP-0060 #6.5.7)
271 @param profile_key: profile key 271 @param profile_key: profile key
272 @return: list of microblog data (dict) 272 @return: list of microblog data (dict)
273 """ 273 """
274 274
275 def initialised(result): 275 def initialised(result):
276 profile, client = result 276 profile, client = result
277 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)), 277 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
278 max_items=max_items, profile_key=profile_key) 278 max_items=max_items, profile_key=profile_key)
279 d.addCallback(lambda items: map(self.item2gbdata, items)) 279 d.addCallback(lambda items: map(self.item2gbdata, items))
290 @param max_items: how many microblogs we want to get 290 @param max_items: how many microblogs we want to get
291 @param profile_key: profile key 291 @param profile_key: profile key
292 """ 292 """
293 def sendResult(result): 293 def sendResult(result):
294 """send result of DeferredList (list of microblogs to the calling method""" 294 """send result of DeferredList (list of microblogs to the calling method"""
295 295
296 ret = {} 296 ret = {}
297 297
298 for (success, value) in result: 298 for (success, value) in result:
299 if success: 299 if success:
300 source_jid, data = value 300 source_jid, data = value
301 ret[source_jid] = data 301 ret[source_jid] = data
302 302
303 return ret 303 return ret
304 304
305 def initialised(result): 305 def initialised(result):
306 profile, client = result 306 profile, client = result
307 307
314 jids.extend(client.roster.getJidsFromGroup(_group)) 314 jids.extend(client.roster.getJidsFromGroup(_group))
315 elif publishers_type == 'JID': 315 elif publishers_type == 'JID':
316 jids = publishers 316 jids = publishers
317 else: 317 else:
318 raise UnknownType 318 raise UnknownType
319 319
320 mblogs = [] 320 mblogs = []
321 321
322 for _jid in jids: 322 for _jid in jids:
323 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)), 323 d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
324 max_items=max_items, profile_key=profile_key) 324 max_items=max_items, profile_key=profile_key)
325 d.addCallback(lambda items, source_jid: (source_jid, map(self.item2gbdata, items)), _jid) 325 d.addCallback(lambda items, source_jid: (source_jid, map(self.item2gbdata, items)), _jid)
326 mblogs.append(d) 326 mblogs.append(d)
327 dlist = defer.DeferredList(mblogs) 327 dlist = defer.DeferredList(mblogs)
328 dlist.addCallback(sendResult) 328 dlist.addCallback(sendResult)
329 329
330 return dlist 330 return dlist
331 331
332 332
333 #TODO: custom exception 333 #TODO: custom exception
334 if publishers_type not in ["GROUP", "JID", "ALL"]: 334 if publishers_type not in ["GROUP", "JID", "ALL"]:
389 389
390 390
391 391
392 class GroupBlog_handler(XMPPHandler): 392 class GroupBlog_handler(XMPPHandler):
393 implements(iwokkel.IDisco) 393 implements(iwokkel.IDisco)
394 394
395 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 395 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
396 return [disco.DiscoFeature(NS_GROUPBLOG)] 396 return [disco.DiscoFeature(NS_GROUPBLOG)]
397 397
398 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 398 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
399 return [] 399 return []