Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0060.py @ 1299:3360074a2f00 frontends_multi_profiles
core: fixed some logging calls without unicode strings, and use of print
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Feb 2015 18:53:07 +0100 |
parents | faa1129559b8 |
children | f71a0fc26886 |
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 | 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 | 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 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 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
|
29 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
|
30 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
33 "name": "Publish-Subscribe", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
34 "import_name": "XEP-0060", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
35 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "protocols": ["XEP-0060"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "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
|
38 "recommendations": ["XEP-0059"], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
39 "main": "XEP_0060", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
41 "description": _("""Implementation of PubSub Protocol""") |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
44 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 OPT_PUBLISH_MODEL = 'pubsub#publish_model' |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 def __init__(self, host): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1261
diff
changeset
|
58 log.info(_(u"PubSub plugin initialization")) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.host = host |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
60 self.managedNodes = [] |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
61 self.clients = {} |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
62 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
|
63 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 def getHandler(self, profile): |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 self.clients[profile] = SatPubSubClient(self.host, self) |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 return self.clients[profile] |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 def addManagedNode(self, node_name, callback): |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 """Add a handler for a namespace |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 @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
|
71 @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
|
72 @param profile: profile which manage this handler""" |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 self.managedNodes.append((node_name, callback)) |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
75 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
|
76 """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
|
77 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
|
78 @param profile_key: as usual :) |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
79 @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
|
80 profile = self.host.memory.getProfileName(profile_key) |
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
81 if not profile: |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
82 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
|
83 'action': action, |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
84 'profile_key': profile_key} |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
85 log.error(err_mess) |
286
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
86 raise Exception(err_mess) |
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
87 try: |
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
88 client = self.clients[profile] |
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
89 except KeyError: |
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
90 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
|
91 log.error(err_mess) |
286
3b382fa0ac28
plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents:
283
diff
changeset
|
92 raise Exception(err_mess) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
93 return profile, client |
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
94 |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
95 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
|
96 """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
|
97 |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
98 @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
|
99 @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
|
100 @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
|
101 @return: Deferred list[str] |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
102 """ |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 # init is still running |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
107 d = defer.Deferred() |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
108 cache['waiting'].append(d) |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
109 return d |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
110 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
|
111 |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
112 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
|
113 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
|
114 |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
115 def cb(nodes): |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
116 cache['nodes'] = nodes |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
117 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
|
118 d.callback(nodes) |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
119 return nodes |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
120 |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
121 return init.addCallback(cb) |
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
122 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
123 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
|
124 """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
|
125 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
126 @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
|
127 @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
|
128 @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
|
129 @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
|
130 """ |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
131 session_id = profile + '@found@' + service.userhost() |
1261
93bce9e4c9c8
plugin XEP-0060: listNodes should not use SatPubSubClient.getDiscoItems but self.host.getDiscoItems, cf. revs 1217 (318eab3f93f8) and 1259 (633fcd13a7dc)
souliane <souliane@mailoo.org>
parents:
1260
diff
changeset
|
132 d = self.host.getDiscoItems(service, nodeIdentifier, profile_key=profile) |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
133 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
|
134 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
|
135 |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
136 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
|
137 """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
|
138 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
139 @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
|
140 @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
|
141 @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
|
142 - 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
|
143 - '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
|
144 - '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
|
145 - '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
|
146 @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
|
147 @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
|
148 """ |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
154 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
|
155 profile, client = self.__getClientNProfile(profile_key, 'publish item') |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
156 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
|
157 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
162 @defer.inlineCallbacks |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
163 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
|
164 """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
|
165 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
166 @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
|
167 @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
|
168 @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
|
169 @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
|
170 @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
|
171 @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
|
172 @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
|
173 """ |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
174 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
|
175 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
|
176 d_dict = {} |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
177 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
|
178 if node not in found_nodes: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1261
diff
changeset
|
179 log.debug(u"Skip the items retrieval for [{node}]: node doesn't exist".format(node=node)) |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
188 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
|
189 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
|
190 return client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
191 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
196 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
|
197 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
|
198 return client.deleteNode(service, nodeIdentifier) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
199 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
204 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
|
205 profile, client = self.__getClientNProfile(profile_key, 'subscribe node') |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
206 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
|
207 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
208 @defer.inlineCallbacks |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
209 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
|
210 """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
|
211 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
212 @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
|
213 @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
|
214 @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
|
215 @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
|
216 @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
|
217 @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
|
218 """ |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 d_list = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
223 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
|
224 if nodeIdentifier not in found_nodes: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1261
diff
changeset
|
225 log.debug(u"Skip the subscription to [{node}]: node doesn't exist".format(node=nodeIdentifier)) |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
234 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 class SatPubSubClient(pubsub.PubSubClient): |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 implements(disco.IDisco) |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 def __init__(self, host, parent_plugin): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
239 self.host = host |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 self.parent_plugin = parent_plugin |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 pubsub.PubSubClient.__init__(self) |
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 connectionInitialized(self): |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 pubsub.PubSubClient.connectionInitialized(self) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
245 |
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
|
246 # 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
|
247 # 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
|
248 # 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
|
249 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
|
250 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
|
251 """ |
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 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
|
253 |
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 @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
|
255 @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
|
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 @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
|
258 @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
|
259 |
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 @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
|
261 @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
|
262 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
263 @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
|
264 @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
|
265 |
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 @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
|
267 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
|
268 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
|
269 @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
|
270 """ |
1219
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
271 # 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 |
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 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
|
282 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
|
283 for element in iq.pubsub.items.elements(): |
1260
c8cf61c6d238
plugin pubsub: fixed redefinition of PubSubRequest
Goffi <goffi@goffi.org>
parents:
1259
diff
changeset
|
284 if element.uri == pubsub.NS_PUBSUB and element.name == 'item': |
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
|
285 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
|
286 # 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
|
287 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
|
288 |
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 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
|
290 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
|
291 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
|
292 |
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 # 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
|
294 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
|
295 """ |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
296 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
|
297 |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
298 @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
|
299 @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
|
300 @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
|
301 @type nodeIdentifier: C{unicode} |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
302 @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
|
303 @type itemIdentifiers: C{set} |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
304 """ |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
305 request = PubSubRequest('retract') |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
306 request.recipient = service |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
307 request.nodeIdentifier = nodeIdentifier |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
308 request.itemIdentifiers = itemIdentifiers |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
309 request.sender = sender |
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
310 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
|
311 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 def itemsReceived(self, event): |
477
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
313 if not self.host.trigger.point("PubSubItemsReceived", event, self.parent.profile): |
031b0e0aaab8
plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
314 return |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 for node in self.parent_plugin.managedNodes: |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 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
|
317 node[1](event, self.parent.profile) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 def deleteReceived(self, event): |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
320 #TODO: manage delete event |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1261
diff
changeset
|
321 log.debug(_(u"Publish node deleted")) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
323 # 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
|
324 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
325 @defer.inlineCallbacks |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
326 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
|
327 """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
|
328 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
329 @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
|
330 @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
|
331 @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
|
332 @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
|
333 """ |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
334 request = PubSubRequest('subscriptions') |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
335 request.recipient = service |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
336 request.nodeIdentifier = nodeIdentifier |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
337 request.sender = sender |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
338 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
|
339 defer.returnValue([sub for sub in iq.pubsub.subscriptions.elements() if |
1260
c8cf61c6d238
plugin pubsub: fixed redefinition of PubSubRequest
Goffi <goffi@goffi.org>
parents:
1259
diff
changeset
|
340 (sub.uri == pubsub.NS_PUBSUB and sub.name == 'subscription')]) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
341 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
342 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
|
343 disco_info = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
344 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
|
345 return disco_info |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
346 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
347 def getDiscoItems(self, requestor, service, nodeIdentifier=''): |
1259
633fcd13a7dc
plugin pubsub: fixed a bug introducted in revision 318eab3f93f8: getDiscoItems handler method which is called on disco items request, was calling getDiscoItems from host, which do a request itself, resulting in an infinite items request loop.
Goffi <goffi@goffi.org>
parents:
1246
diff
changeset
|
348 return [] |
1219
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
349 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
350 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
351 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
|
352 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
353 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
|
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 @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
|
356 @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
|
357 @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
|
358 - 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
|
359 - 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
|
360 - 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
|
361 - 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
|
362 """ |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
367 # 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
|
368 # 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
|
369 # 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
|
370 # 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
|
371 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
|
372 """ |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
373 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
|
374 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
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 @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
|
381 @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
|
382 @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
|
383 """ |
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 try: |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
386 (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
|
387 childURI, |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
392 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
|
393 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
|
394 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
|
395 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 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
|
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 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
|
402 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
|
403 |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
1217
diff
changeset
|
404 # 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
|
405 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
|
406 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
|
407 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
|
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 return iq.send() |