annotate src/plugins/plugin_xep_0060.py @ 1243:b4a264915ea9

plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
author souliane <souliane@mailoo.org>
date Sun, 19 Oct 2014 02:48:11 +0200
parents f584fbda4773
children 8b891f9be183
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for Publish-Subscribe (xep-0060)
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 745
diff changeset
20 from sat.core.i18n import _
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
21 from sat.core.constants import Const as C
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
22 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
23 log = getLogger(__name__)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
24 from sat.memory.memory import Sessions
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
25
1219
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
26 from wokkel.compat import IQ
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
27 from wokkel import disco, pubsub
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
28 from wokkel.pubsub import PubSubRequest, NS_PUBSUB
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from zope.interface import implements
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
30 from twisted.internet import defer
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
31
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
32
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
33 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
34 "name": "Publish-Subscribe",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
35 "import_name": "XEP-0060",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
36 "type": "XEP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
37 "protocols": ["XEP-0060"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 "dependencies": [],
1219
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
39 "recommendations": ["XEP-0059"],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
40 "main": "XEP_0060",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
41 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
42 "description": _("""Implementation of PubSub Protocol""")
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
44
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
45
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
46 class XEP_0060(object):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
47 OPT_ACCESS_MODEL = 'pubsub#access_model'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
48 OPT_PERSIST_ITEMS = 'pubsub#persist_items'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
49 OPT_MAX_ITEMS = 'pubsub#max_items'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
50 OPT_DELIVER_PAYLOADS = 'pubsub#deliver_payloads'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
51 OPT_SEND_ITEM_SUBSCRIBE = 'pubsub#send_item_subscribe'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
52 OPT_NODE_TYPE = 'pubsub#node_type'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
53 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
54 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
55 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
56 OPT_PUBLISH_MODEL = 'pubsub#publish_model'
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
57
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
59 log.info(_("PubSub plugin initialization"))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.host = host
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
61 self.managedNodes = []
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
62 self.clients = {}
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
63 self.node_cache = Sessions(timeout=60, resettable_timeout=False)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
64
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def getHandler(self, profile):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.clients[profile] = SatPubSubClient(self.host, self)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
67 return self.clients[profile]
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
68
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def addManagedNode(self, node_name, callback):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
70 """Add a handler for a namespace
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
71 @param namespace: NS of the handler (will appear in disco info)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
72 @param callback: method to call when the handler is found
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
73 @param profile: profile which manage this handler"""
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.managedNodes.append((node_name, callback))
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
75
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
76 def __getClientNProfile(self, profile_key, action='do pusbsub'):
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
77 """Return a tuple of (client, profile)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
78 raise error when the profile doesn't exists
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
79 @param profile_key: as usual :)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
80 @param action: text of action to show in case of error"""
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
81 profile = self.host.memory.getProfileName(profile_key)
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
82 if not profile:
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
83 err_mess = _('Trying to %(action)s with an unknown profile key [%(profile_key)s]') % {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
84 'action': action,
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
85 'profile_key': profile_key}
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
86 log.error(err_mess)
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
87 raise Exception(err_mess)
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
88 try:
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
89 client = self.clients[profile]
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
90 except KeyError:
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
91 err_mess = _('INTERNAL ERROR: no handler for required profile')
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
92 log.error(err_mess)
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
93 raise Exception(err_mess)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
94 return profile, client
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
95
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
96 def _getDeferredNodeCache(self, session_id, init, profile):
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
97 """Manage a node cache with deferred initialisation and concurrent access.
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
98
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
99 @param session_id (string): node cache session ID
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
100 @param init (Deferred): deferred list of strings to initialise the cache.
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
101 @param profile (str): %(doc_profile)s
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
102 @return: Deferred list[str]
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
103 """
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
104 if session_id in self.node_cache:
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
105 cache = self.node_cache.profileGet(session_id, profile)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
106 if cache['nodes'] is None:
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
107 # init is still running
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
108 d = defer.Deferred()
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
109 cache['waiting'].append(d)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
110 return d
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
111 return defer.succeed(cache['nodes'])
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
112
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
113 cache = {'init': init, 'waiting': [], 'nodes': None}
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
114 self.node_cache.newSession(cache, session_id=session_id, profile=profile)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
115
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
116 def cb(nodes):
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
117 cache['nodes'] = nodes
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
118 for d in cache['waiting']:
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
119 d.callback(nodes)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
120 return nodes
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
121
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
122 return init.addCallback(cb)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
123
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
124 def listNodes(self, service, nodeIdentifier='', profile=C.PROF_KEY_NONE):
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
125 """Retrieve the name of the nodes that are accessible on the target service.
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
126
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
127 @param service (JID): target service
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
128 @param nodeIdentifier (str): the parent node name (leave empty to retrieve first-level nodes)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
129 @param profile (str): %(doc_profile)s
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
130 @return: Deferred list[str]
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
131 """
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
132 session_id = profile + '@found@' + service.userhost()
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
133 d = self.getDiscoItems(service, nodeIdentifier, profile_key=profile)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
134 d.addCallback(lambda result: [item.getAttribute('node') for item in result.toElement().children if item.hasAttribute('node')])
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
135 return self._getDeferredNodeCache(session_id, d, profile)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
136
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
137 def listSubscribedNodes(self, service, nodeIdentifier='', filter_='subscribed', profile=C.PROF_KEY_NONE):
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
138 """Retrieve the name of the nodes to which the profile is subscribed on the target service.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
139
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
140 @param service (JID): target service
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
141 @param nodeIdentifier (str): the parent node name (leave empty to retrieve all subscriptions)
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
142 @param filter_ (str): filter the result according to the given subscription type:
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
143 - None: do not filter
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
144 - 'pending': subscription has been approved yet by the node owner
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
145 - 'unconfigured': subscription options have not been configured yet
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
146 - 'subscribed': subscription is complete
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
147 @param profile (str): %(doc_profile)s
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
148 @return: Deferred list[str]
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
149 """
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
150 session_id = profile + '@subscriptions@' + service.userhost()
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
151 d = self.subscriptions(service, nodeIdentifier, profile_key=profile)
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
152 d.addCallback(lambda subs: [sub.getAttribute('node') for sub in subs if sub.getAttribute('subscription') == filter_])
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
153 return self._getDeferredNodeCache(session_id, d, profile)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
154
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
155 def publish(self, service, nodeIdentifier, items=None, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
156 profile, client = self.__getClientNProfile(profile_key, 'publish item')
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
157 return client.publish(service, nodeIdentifier, items, client.parent.jid)
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
158
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
159 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
160 profile, client = self.__getClientNProfile(profile_key, 'get items')
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
161 return client.items(service, node, max_items, item_ids, sub_id, client.parent.jid)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
162
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
163 @defer.inlineCallbacks
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
164 def getItemsFromMany(self, service, data, max_items=None, item_ids=None, sub_id=None, profile_key=C.PROF_KEY_NONE):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
165 """Massively retrieve pubsub items from many nodes.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
166
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
167 @param service (JID): target service.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
168 @param data (dict): dictionnary binding some arbitrary keys to the node identifiers.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
169 @param max_items (int): optional limit on the number of retrieved items *per node*.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
170 @param item_ids (list[str]): identifiers of the items to be retrieved (should not be used).
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
171 @param sub_id (str): optional subscription identifier.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
172 @param profile_key (str): %(doc_profile_key)s
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
173 @return: dict binding a subset of the keys of data to Deferred instances.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
174 """
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
175 profile, client = self.__getClientNProfile(profile_key, 'get items')
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
176 found_nodes = yield self.listNodes(service, profile=profile)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
177 d_dict = {}
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
178 for publisher, node in data.items():
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
179 if node not in found_nodes:
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
180 log.info("Skip the items retrieval for [{node}]: node doesn't exist".format(node=node))
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
181 continue # avoid pubsub "item-not-found" error
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
182 d_dict[publisher] = client.items(service, node, max_items, item_ids, sub_id, client.parent.jid)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
183 defer.returnValue(d_dict)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
184
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
185 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
186 profile, client = self.__getClientNProfile(profile_key, 'get options')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
187 return client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
188
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
189 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
190 profile, client = self.__getClientNProfile(profile_key, 'set options')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
191 return client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
192
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
193 def createNode(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
194 profile, client = self.__getClientNProfile(profile_key, 'create node')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
195 return client.createNode(service, nodeIdentifier, options)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
196
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
197 def deleteNode(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
198 profile, client = self.__getClientNProfile(profile_key, 'delete node')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
199 return client.deleteNode(service, nodeIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
200
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
201 def retractItems(self, service, nodeIdentifier, itemIdentifiers, profile_key=C.PROF_KEY_NONE):
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
202 profile, client = self.__getClientNProfile(profile_key, 'retract items')
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
203 return client.retractItems(service, nodeIdentifier, itemIdentifiers)
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
204
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
205 def subscribe(self, service, nodeIdentifier, sub_jid=None, options=None, profile_key=C.PROF_KEY_NONE):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
206 profile, client = self.__getClientNProfile(profile_key, 'subscribe node')
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
207 return client.subscribe(service, nodeIdentifier, sub_jid or client.parent.jid.userhostJID(), options=options)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
208
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
209 @defer.inlineCallbacks
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
210 def subscribeToMany(self, service, nodeIdentifiers, sub_jid=None, options=None, profile_key=C.PROF_KEY_NONE):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
211 """Massively subscribe to many nodes.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
212
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
213 @param service (JID): target service.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
214 @param nodeIdentifiers (list): the list of node identifiers to subscribe to.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
215 @param sub_id (str): optional subscription identifier.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
216 @param options (list): optional list of subscription options
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
217 @param profile_key (str): %(doc_profile_key)s
1243
b4a264915ea9 plugins groupblogs: fixes the massive retrieval callback (loop variable was misused in a lambda callback)
souliane <souliane@mailoo.org>
parents: 1242
diff changeset
218 @return: list of Deferred instances.
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
219 """
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
220 profile, client = self.__getClientNProfile(profile_key, 'subscribe nodes')
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
221 found_nodes = yield self.listNodes(service, profile=profile)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
222 subscribed_nodes = yield self.listSubscribedNodes(service, profile=profile)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
223 d_list = []
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
224 for nodeIdentifier in (set(nodeIdentifiers) - set(subscribed_nodes)):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
225 if nodeIdentifier not in found_nodes:
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
226 log.info("Skip the subscription to [{node}]: node doesn't exist".format(node=nodeIdentifier))
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
227 continue # avoid sat-pubsub "SubscriptionExists" error
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
228 d_list.append(client.subscribe(service, nodeIdentifier, sub_jid or client.parent.jid.userhostJID(), options=options))
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
229 defer.returnValue(d_list)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
230
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
231 def subscriptions(self, service, nodeIdentifier='', profile_key=C.PROF_KEY_NONE):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
232 profile, client = self.__getClientNProfile(profile_key, 'retrieve subscriptions')
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
233 return client.subscriptions(service, nodeIdentifier)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
234
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
235 def getDiscoItems(self, service, nodeIdentifier='', profile_key=C.PROF_KEY_NONE):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
236 profile, client = self.__getClientNProfile(profile_key, 'disco items')
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
237 return client.getDiscoItems(None, service, nodeIdentifier)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
238
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
239
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
240 class SatPubSubClient(pubsub.PubSubClient):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
241 implements(disco.IDisco)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
242
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
243 def __init__(self, host, parent_plugin):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
244 self.host = host
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
245 self.parent_plugin = parent_plugin
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
246 pubsub.PubSubClient.__init__(self)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
247
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
248 def connectionInitialized(self):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
249 pubsub.PubSubClient.connectionInitialized(self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
250
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
251 # FIXME: we have to temporary override this method here just
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
252 # to set the attributes itemIdentifiers which is not used
1219
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
253 # in pubsub.PubSubClient.items + use the XEP-0059
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
254 def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None,
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
255 subscriptionIdentifier=None, sender=None):
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
256 """
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
257 Retrieve previously published items from a publish subscribe node.
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
258
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
259 @param service: The publish subscribe service that keeps the node.
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
260 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
261
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
262 @param nodeIdentifier: The identifier of the node.
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
263 @type nodeIdentifier: C{unicode}
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
264
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
265 @param maxItems: Optional limit on the number of retrieved items.
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
266 @type maxItems: C{int}
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
267
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
268 @param itemIdentifiers: Identifiers of the items to be retrieved.
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
269 @type itemIdentifiers: C{set}
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
270
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
271 @param subscriptionIdentifier: Optional subscription identifier. In
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
272 case the node has been subscribed to multiple times, this narrows
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
273 the results to the specific subscription.
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
274 @type subscriptionIdentifier: C{unicode}
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
275 """
1219
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
276 # TODO: add method attributes for RSM: before, after, index
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
277 request = PubSubRequest('items', self.host, {'limit': maxItems} if maxItems else {})
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
278 request.recipient = service
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
279 request.nodeIdentifier = nodeIdentifier
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
280 if maxItems:
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
281 request.maxItems = str(int(maxItems))
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
282 request.subscriptionIdentifier = subscriptionIdentifier
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
283 request.sender = sender
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
284 request.itemIdentifiers = itemIdentifiers # XXX: this line has been added
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
285
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
286 def cb(iq):
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
287 items = []
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
288 for element in iq.pubsub.items.elements():
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
289 if element.uri == NS_PUBSUB and element.name == 'item':
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
290 items.append(element)
1219
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
291 # TODO: return (items, self.host.plugins['XEP-0059'].extractMetadata(iq)) ??
891
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
292 return items
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
293
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
294 d = request.send(self.xmlstream)
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
295 d.addCallback(cb)
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
296 return d
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
297
a7b2aacf22ac plugin XEP-0060, groupblog: added nodeIdentifiers attribute to getItems in order to retrieve items by ids
souliane <souliane@mailoo.org>
parents: 811
diff changeset
298 # FIXME: this should be done in wokkel
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
299 def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None):
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
300 """
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
301 Retract items from a publish subscribe node.
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
302
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
303 @param service: The publish subscribe service to delete the node from.
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
304 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
305 @param nodeIdentifier: The identifier of the node.
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
306 @type nodeIdentifier: C{unicode}
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
307 @param itemIdentifiers: Identifiers of the items to be retracted.
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
308 @type itemIdentifiers: C{set}
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
309 """
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
310 request = PubSubRequest('retract')
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
311 request.recipient = service
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
312 request.nodeIdentifier = nodeIdentifier
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
313 request.itemIdentifiers = itemIdentifiers
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
314 request.sender = sender
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
315 return request.send(self.xmlstream)
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
316
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
317 def itemsReceived(self, event):
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 459
diff changeset
318 if not self.host.trigger.point("PubSubItemsReceived", event, self.parent.profile):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 459
diff changeset
319 return
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
320 for node in self.parent_plugin.managedNodes:
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
321 if event.nodeIdentifier == node[0]:
704
3c304929af74 plugin XEP-0277, group blogs: proper asynchronous methods for sending blogs.
Goffi <goffi@goffi.org>
parents: 615
diff changeset
322 node[1](event, self.parent.profile)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
323
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
324 def deleteReceived(self, event):
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
325 #TODO: manage delete event
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
326 log.debug(_("Publish node deleted"))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
327
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
328 # def purgeReceived(self, event):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
329
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
330 @defer.inlineCallbacks
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
331 def subscriptions(self, service, nodeIdentifier, sender=None):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
332 """Return the list of subscriptions to the given service and node.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
333
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
334 @param service: The publish subscribe service to retrieve the subscriptions from.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
335 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
336 @param nodeIdentifier: The identifier of the node (leave empty to retrieve all subscriptions).
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
337 @type nodeIdentifier: C{unicode}
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
338 """
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
339 request = PubSubRequest('subscriptions')
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
340 request.recipient = service
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
341 request.nodeIdentifier = nodeIdentifier
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
342 request.sender = sender
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
343 iq = yield request.send(self.xmlstream)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
344 defer.returnValue([sub for sub in iq.pubsub.subscriptions.elements() if
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
345 (sub.uri == NS_PUBSUB and sub.name == 'subscription')])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
346
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
347 def getDiscoInfo(self, requestor, service, nodeIdentifier=''):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
348 disco_info = []
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
349 self.host.trigger.point("PubSub Disco Info", disco_info, self.parent.profile)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
350 return disco_info
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
351
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
352 def getDiscoItems(self, requestor, service, nodeIdentifier=''):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
353 return self.host.getDiscoItems(service, nodeIdentifier, self.parent.profile)
1219
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
354
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
355
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
356 class PubSubRequest(pubsub.PubSubRequest):
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
357
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
358 def __init__(self, verb=None, host=None, page_attrs=None):
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
359 """
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
360 @param verb (str): the type of pubsub request
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
361 @param host (SAT): the SAT instance
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
362 @param page_attrs (dict): options for RSM paging:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
363 - limit (int): the maximum number of items in the page
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
364 - index (int): the starting index of the requested page
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
365 - after (str, int): the element immediately preceding the page
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
366 - before (str, int): the element immediately following the page
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
367 """
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
368 self.verb = verb
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
369 self.host = host
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
370 self.page_attrs = page_attrs
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
371
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
372 # FIXME: the redefinition of this wokkel method is the easiest way I found
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
373 # to handle RSM. We should find a proper solution, maybe just add in wokkel an
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
374 # empty method postProcessMessage, call it before sending and overwrite it here
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
375 # instead of overwriting the whole send method.
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
376 def send(self, xs):
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
377 """
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
378 Send this request to its recipient.
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
379
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
380 This renders all of the relevant parameters for this specific
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
381 requests into an L{IQ}, and invoke its C{send} method.
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
382 This returns a deferred that fires upon reception of a response. See
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
383 L{IQ} for details.
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
384
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
385 @param xs: The XML stream to send the request on.
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
386 @type xs: L{twisted.words.protocols.jabber.xmlstream.XmlStream}
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
387 @rtype: L{defer.Deferred}.
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
388 """
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
389
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
390 try:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
391 (self.stanzaType,
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
392 childURI,
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
393 childName) = self._verbRequestMap[self.verb]
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
394 except KeyError:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
395 raise NotImplementedError()
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
396
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
397 iq = IQ(xs, self.stanzaType)
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
398 iq.addElement((childURI, 'pubsub'))
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
399 verbElement = iq.pubsub.addElement(childName)
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
400
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
401 if self.sender:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
402 iq['from'] = self.sender.full()
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
403 if self.recipient:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
404 iq['to'] = self.recipient.full()
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
405
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
406 for parameter in self._parameters[self.verb]:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
407 getattr(self, '_render_%s' % parameter)(verbElement)
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
408
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
409 # This lines have been added for RSM
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
410 if self.host and 'XEP-0059' in self.host.plugins and self.page_attrs:
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
411 self.page_attrs['stanza'] = iq
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
412 self.host.plugins['XEP-0059'].requestPage(**self.page_attrs)
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
413
16484ebb695b plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents: 1217
diff changeset
414 return iq.send()