annotate src/plugins/plugin_xep_0060.py @ 2338:b1bbd2994ceb

plugin XEP-0060: implemented subscriptions management method for node owner: added getNodeSubscriptions and setNodeSubscriptions and their bridge method (psNodeSubscriptionsGet and psNodeSubscriptionsSet)
author Goffi <goffi@goffi.org>
date Sun, 20 Aug 2017 10:31:53 +0200
parents e715a29c4f9b
children 6c26f435a02d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1904
diff changeset
1 #!/usr/bin/env python2
283
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)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1760
diff changeset
5 # Copyright (C) 2009-2016 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__)
1483
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
24 from sat.core import exceptions
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
25 from sat.tools import sat_defer
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
26
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
27 from twisted.words.protocols.jabber import jid, error
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
28 from twisted.internet import defer
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
29 from wokkel import disco
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
30 from wokkel import data_form
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
31 from zope.interface import implements
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
32 from collections import namedtuple
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
33 import urllib
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
34 import datetime
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
35 from dateutil import tz
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
36 # XXX: tmp.wokkel.pubsub is actually use instead of wokkel version
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
37 # mam and rsm come from tmp.wokkel too
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
38 from wokkel import pubsub
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
39 from wokkel import rsm
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
40 from wokkel import mam
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
41
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 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_NAME: "Publish-Subscribe",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
45 C.PI_IMPORT_NAME: "XEP-0060",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
46 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_PROTOCOLS: ["XEP-0060"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_DEPENDENCIES: [],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 C.PI_RECOMMENDATIONS: ["XEP-0313"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
50 C.PI_MAIN: "XEP_0060",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
51 C.PI_HANDLER: "yes",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
52 C.PI_DESCRIPTION: _("""Implementation of PubSub Protocol""")
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
53 }
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
54
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
55 UNSPECIFIED = "unspecified error"
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
56 MAM_FILTER = "mam_filter_"
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
57
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
59 Extra = namedtuple('Extra', ('rsm_request', 'extra'))
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
60 # rsm_request is the rsm.RSMRequest build with rsm_ prefixed keys, or None
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
61 # extra is a potentially empty dict
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
62
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
63
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
64 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
65 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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73 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
74 OPT_PUBLISH_MODEL = 'pubsub#publish_model'
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
75 ACCESS_OPEN = 'open'
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
76 ACCESS_PRESENCE = 'presence'
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
77 ACCESS_ROSTER = 'roster'
2201
40dd9eb2692c plugin groupblog, XEP-0060: added ACCESS_PUBLISHER_ROSTER and switched to it in groupblog
Goffi <goffi@goffi.org>
parents: 2198
diff changeset
78 ACCESS_PUBLISHER_ROSTER = 'publisher-roster'
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
79 ACCESS_AUTHORIZE = 'authorize'
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
80 ACCESS_WHITELIST = 'whitelist'
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
81
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
82 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
83 log.info(_(u"PubSub plugin initialization"))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.host = host
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
85 self._mam = host.plugins.get('XEP-0313')
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
86 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks)
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
87 self.rt_sessions = sat_defer.RTDeferredSessions()
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
88 host.bridge.addMethod("psNodeCreate", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._createNode, async=True)
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
89 host.bridge.addMethod("psNodeConfigurationGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeConfiguration, async=True)
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
90 host.bridge.addMethod("psNodeConfigurationSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeConfiguration, async=True)
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
91 host.bridge.addMethod("psNodeAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeAffiliations, async=True)
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
92 host.bridge.addMethod("psNodeAffiliationsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeAffiliations, async=True)
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
93 host.bridge.addMethod("psNodeSubscriptionsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeSubscriptions, async=True)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
94 host.bridge.addMethod("psNodeSubscriptionsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeSubscriptions, async=True)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
95 host.bridge.addMethod("psAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getAffiliations, async=True)
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
96 host.bridge.addMethod("psNodeDelete", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
97 host.bridge.addMethod("psItemsGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
98 host.bridge.addMethod("psItemSend", ".plugin", in_sign='ssssa{ss}s', out_sign='s', method=self._sendItem, async=True)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
99 host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
100 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
101 host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
102 host.bridge.addMethod("psGetSubscribeRTResult", ".plugin", in_sign='ss', out_sign='(ua(sss))', method=self._manySubscribeRTResult, async=True)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
103 host.bridge.addMethod("psGetFromMany", ".plugin", in_sign='a(ss)ia{ss}s', out_sign='s', method=self._getFromMany)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
104 host.bridge.addMethod("psGetFromManyRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssasa{ss}))', method=self._getFromManyRTResult, async=True)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
105 host.bridge.addSignal("psEvent", ".plugin", signature='ssssa{ss}s') # args: category, service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), data, profile
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
106
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
107 def getHandler(self, client):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
108 client.pubsub_client = SatPubSubClient(self.host, self)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
109 return client.pubsub_client
1282
74d558e6c9fd plugin XEP-0060: free SatPubSubClient instance on profile disconnection
souliane <souliane@mailoo.org>
parents: 1268
diff changeset
110
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
111 @defer.inlineCallbacks
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
112 def profileConnected(self, client):
2148
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
113 pubsub_services = yield self.host.findServiceEntities(client, "pubsub", "service")
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
114 if pubsub_services:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
115 # we use one of the found services as our default pubsub service
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
116 client.pubsub_service = pubsub_services.pop()
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
117 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
118 client.pubsub_service = None
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
119
1483
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
120 def getFeatures(self, profile):
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
121 try:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
122 client = self.host.getClient(profile)
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
123 except exceptions.ProfileNotSetError:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
124 return {}
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
125 try:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
126 return {'service': client.pubsub_service.full() if client.pubsub_service is not None else ''}
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
127 except AttributeError:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
128 if self.host.isConnected(profile):
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
129 log.debug("Profile is not connected, service is not checked yet")
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
130 else:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
131 log.error("Service should be available !")
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
132 return {}
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
133
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
134 def parseExtra(self, extra):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
135 """Parse extra dictionnary
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
136
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
137 used bridge's extra dictionnaries
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
138 @param extra(dict): extra data used to configure request
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
139 @return(Extra): filled Extra instance
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
140 """
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
141 if extra is not None:
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
142 # rsm
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
143 rsm_args = {}
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
144 for arg in ('max', 'after', 'before', 'index'):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
145 try:
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
146 argname = "max_" if arg == 'max' else arg
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
147 rsm_args[argname] = extra.pop('rsm_{}'.format(arg))
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
148 except KeyError:
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
149 continue
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
150
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
151 if rsm_args:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
152 rsm_request = rsm.RSMRequest(**rsm_args)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
153 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
154 rsm_request = None
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
155
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
156 # mam
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
157 mam_args = {}
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
158 for arg in ('start', 'end'):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
159 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
160 mam_args[arg] = datetime.datetime.fromtimestamp(int(extra.pop('{}{}'.format(MAM_FILTER, arg))), tz.tzutc())
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
161 except (TypeError, ValueError):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
162 log.warning(u"Bad value for {} filter".format(arg))
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
163 except KeyError:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
164 continue
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
165
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
166 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
167 mam_args['with_jid'] = jid.JID(extra.pop('{}jid'.format(MAM_FILTER)))
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
168 except (jid.InvalidFormat):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
169 log.warning(u"Bad value for jid filter")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
170 except KeyError:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
171 pass
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
172
1778
442303b62a16 plugin XEP-0060: fixed extra mam filters parsing
Goffi <goffi@goffi.org>
parents: 1777
diff changeset
173 for name, value in extra.iteritems():
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
174 if name.startswith(MAM_FILTER):
1778
442303b62a16 plugin XEP-0060: fixed extra mam filters parsing
Goffi <goffi@goffi.org>
parents: 1777
diff changeset
175 var = name[len(MAM_FILTER):]
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
176 extra_fields = mam_args.setdefault('extra_fields', [])
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
177 extra_fields.append(data_form.Field(var=var, value=value))
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
178
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
179 if mam_args:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
180 assert 'mam' not in extra
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
181 extra['mam'] = mam.MAMRequest(mam.buildForm(**mam_args))
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
182 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
183 rsm_request = None
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
184 extra = {}
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
185 return Extra(rsm_request, extra)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
186
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
187 def addManagedNode(self, node, **kwargs):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
188 """Add a handler for a node
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
189
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
190 @param node(unicode): node to monitor
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
191 all node *prefixed* with this one will be triggered
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
192 @param **kwargs: method(s) to call when the node is found
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
193 the method must be named after PubSub constants in lower case
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
194 and suffixed with "_cb"
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
195 e.g.: "items_cb" for C.PS_ITEMS, "delete_cb" for C.PS_DELETE
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
196 """
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
197 assert node is not None
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
198 assert kwargs
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
199 callbacks = self._node_cb.setdefault(node, {})
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
200 for event, cb in kwargs.iteritems():
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
201 event_name = event[:-3]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
202 assert event_name in C.PS_EVENTS
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
203 callbacks.setdefault(event_name,[]).append(cb)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
204
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
205 def removeManagedNode(self, node, *args):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
206 """Add a handler for a node
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
207
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
208 @param node(unicode): node to monitor
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
209 @param *args: callback(s) to remove
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
210 """
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
211 assert args
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
212 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
213 registred_cb = self._node_cb[node]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
214 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
215 pass
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
216 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
217 for callback in args:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
218 for event, cb_list in registred_cb.iteritems():
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
219 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
220 cb_list.remove(callback)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
221 except ValueError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
222 pass
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
223 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
224 log.debug(u"removed callback {cb} for event {event} on node {node}".format(
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
225 cb=callback, event=event, node=node))
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
226 if not cb_list:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
227 del registred_cb[event]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
228 if not registred_cb:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
229 del self._node_cb[node]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
230 return
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
231 log.error(u"Trying to remove inexistant callback {cb} for node {node}".format(cb=callback, node=node))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
232
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
233 # def listNodes(self, service, nodeIdentifier='', profile=C.PROF_KEY_NONE):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
234 # """Retrieve the name of the nodes that are accessible on the target service.
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
235
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
236 # @param service (JID): target service
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
237 # @param nodeIdentifier (str): the parent node name (leave empty to retrieve first-level nodes)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
238 # @param profile (str): %(doc_profile)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
239 # @return: deferred which fire a list of nodes
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
240 # """
2148
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
241 # client = self.host.getClient(profile)
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
242 # d = self.host.getDiscoItems(client, service, nodeIdentifier)
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
243 # d.addCallback(lambda result: [item.getAttribute('node') for item in result.toElement().children if item.hasAttribute('node')])
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
244 # return d
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
245
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
246 # def listSubscribedNodes(self, service, nodeIdentifier='', filter_='subscribed', profile=C.PROF_KEY_NONE):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
247 # """Retrieve the name of the nodes to which the profile is subscribed 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
248
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
249 # @param service (JID): target service
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
250 # @param nodeIdentifier (str): the parent node name (leave empty to retrieve all subscriptions)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
251 # @param filter_ (str): filter the result according to the given subscription type:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
252 # - None: do not filter
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
253 # - 'pending': subscription has not been approved yet by the node owner
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
254 # - 'unconfigured': subscription options have not been configured yet
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
255 # - 'subscribed': subscription is complete
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
256 # @param profile (str): %(doc_profile)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
257 # @return: Deferred list[str]
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
258 # """
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
259 # d = self.subscriptions(service, nodeIdentifier, profile_key=profile)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
260 # d.addCallback(lambda subs: [sub.getAttribute('node') for sub in subs if sub.getAttribute('subscription') == filter_])
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
261 # return d
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
262
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
263 def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
264 client = self.host.getClient(profile_key)
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
265 service = None if not service else jid.JID(service)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
266 d = self.sendItem(client, service, nodeIdentifier, payload, item_id or None, extra)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
267 d.addCallback(lambda ret: ret or u'')
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
268 return d
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
269
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
270 def _getPublishedItemId(self, iq_elt, original_id):
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
271 """return item of published id if found in answer
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
273 if not found original_id is returned, or empty string if it is None or empty string
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
274 """
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
275 try:
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
276 item_id = iq_elt.pubsub.publish.item['id']
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
277 except (AttributeError, KeyError):
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
278 item_id = None
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
279 return item_id or original_id
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
280
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
281 def sendItem(self, client, service, nodeIdentifier, payload, item_id=None, extra=None):
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
282 """high level method to send one item
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
283
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
284 @param service(jid.JID, None): service to send the item to
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
285 None to use PEP
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
286 @param NodeIdentifier(unicode): PubSub node to use
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
287 @param item_id(unicode, None): id to use or None to create one
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
288 @param payload(domish.Element, unicode): payload of the item to send
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
289 @param extra(dict, None): extra option, not used yet
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
290 @return (unicode, None): id of the created item
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
291 """
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
292 item_elt = pubsub.Item(id=item_id, payload=payload)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
293 d = self.publish(client, service, nodeIdentifier, [item_elt])
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
294 d.addCallback(self._getPublishedItemId, item_id)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
295 return d
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
296
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
297 def publish(self, client, service, nodeIdentifier, items=None):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
298 return client.pubsub_client.publish(service, nodeIdentifier, items, client.pubsub_client.parent.jid)
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
299
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
300 def _unwrapMAMMessage(self, message_elt):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
301 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
302 item_elt = (message_elt.elements(mam.NS_MAM, 'result').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
303 .elements(C.NS_FORWARD, 'forwarded').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
304 .elements(C.NS_CLIENT, 'message').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
305 .elements('http://jabber.org/protocol/pubsub#event', 'event').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
306 .elements('http://jabber.org/protocol/pubsub#event', 'items').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
307 .elements('http://jabber.org/protocol/pubsub#event', 'item').next())
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
308 except StopIteration:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
309 raise exceptions.DataError(u"Can't find Item in MAM message element")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
310 return item_elt
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
311
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
312 def _getItems(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE):
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
313 """Get items from pubsub node
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
314
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
315 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
316 """
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
317 service = jid.JID(service) if service else None
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
318 max_items = None if max_items == C.NO_LIMIT else max_items
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
319 extra = self.parseExtra(extra_dict)
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
320 d = self.getItems(service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra, profile_key)
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
321 d.addCallback(self.serItemsData)
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
322 return d
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
323
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
324 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
325 """Retrieve pubsub items from a node.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
326
1865
fc6eeacf31bc plugin XEP-0277: service can be None in mbGet, resulting in a request on default pubsub service of profile (i.e. profile's PEP)
Goffi <goffi@goffi.org>
parents: 1854
diff changeset
327 @param service (JID, None): pubsub service.
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
328 @param node (str): node id.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
329 @param max_items (int): optional limit on the number of retrieved items.
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
330 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be used with rsm_request).
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
331 @param sub_id (str): optional subscription identifier.
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
332 @param rsm_request (rsm.RSMRequest): RSM request data
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
333 @param profile_key (unicode): %(doc_profile_key)s
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
334 @return: a deferred couple (list[dict], dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
335 - list of items
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
336 - metadata with the following keys:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
337 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
338 - service, node: service and node used
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
339 """
2319
e715a29c4f9b plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents: 2314
diff changeset
340 if item_ids and max_items is not None:
e715a29c4f9b plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents: 2314
diff changeset
341 max_items = None
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
342 if rsm_request and item_ids:
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
343 raise ValueError(u"items_id can't be used with rsm")
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
344 if extra is None:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
345 extra = {}
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
346 client = self.host.getClient(profile_key)
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
347 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
348 mam_query = extra['mam']
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
349 except KeyError:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
350 d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, None, rsm_request)
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
351 else:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
352 # if mam is requested, we have to do a totally different query
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
353 if self._mam is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
354 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
355 if max_items is not None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
356 raise exceptions.DataError(u"max_items parameter can't be used with MAM")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
357 if item_ids:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
358 raise exceptions.DataError(u"items_ids parameter can't be used with MAM")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
359 if mam_query.node is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
360 mam_query.node = node
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
361 elif mam_query.node != node:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
362 raise exceptions.DataError(u"MAM query node is incoherent with getItems's node")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
363 if mam_query.rsm is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
364 mam_query.rsm = rsm_request
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
365 else:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
366 if mam_query.rsm != rsm_request:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
367 raise exceptions.DataError(u"Conflict between RSM request and MAM's RSM request")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
368 d = self._mam.getArchives(client, mam_query, service, self._unwrapMAMMessage)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
369
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
370 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
371 subscribe = C.bool(extra['subscribe'])
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
372 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
373 subscribe = False
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
374
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
375 def subscribeEb(failure, service, node):
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
376 failure.trap(error.StanzaError)
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
377 log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value)))
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
378
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
379 def doSubscribe(items):
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
380 self.subscribe(service, node, profile_key=profile_key).addErrback(subscribeEb, service, node)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
381 return items
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
382
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
383 if subscribe:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
384 d.addCallback(doSubscribe)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
385
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
386 def addMetadata(result):
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
387 items, rsm_response = result
2314
01f0a954d506 plugin XEP-0060: fixed service in metadata for PEP
Goffi <goffi@goffi.org>
parents: 2305
diff changeset
388 service_jid = service if service else client.jid.userhostJID()
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
389 metadata = {'service': service_jid,
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
390 'node': node,
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
391 'uri': self.getNodeURI(service_jid, node),
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
392 }
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
393 if rsm_request is not None and rsm_response is not None:
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
394 metadata.update({'rsm_{}'.format(key): value for key, value in rsm_response.toDict().iteritems()})
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
395 return (items, metadata)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
396
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
397 d.addCallback(addMetadata)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
398 return d
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
399
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
400 # @defer.inlineCallbacks
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
401 # def getItemsFromMany(self, service, data, max_items=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
402 # """Massively retrieve pubsub items from many nodes.
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
403
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
404 # @param service (JID): target service.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
405 # @param data (dict): dictionnary binding some arbitrary keys to the node identifiers.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
406 # @param max_items (int): optional limit on the number of retrieved items *per node*.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
407 # @param sub_id (str): optional subscription identifier.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
408 # @param rsm (dict): RSM request data
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
409 # @param profile_key (str): %(doc_profile_key)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
410 # @return: a deferred dict with:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
411 # - key: a value in (a subset of) data.keys()
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
412 # - couple (list[dict], dict) containing:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
413 # - list of items
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
414 # - RSM response data
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
415 # """
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
416 # client = self.host.getClient(profile_key)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
417 # found_nodes = yield self.listNodes(service, profile=client.profile)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
418 # d_dict = {}
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
419 # for publisher, node in data.items():
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
420 # if node not in found_nodes:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
421 # log.debug(u"Skip the items retrieval for [{node}]: node doesn't exist".format(node=node))
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
422 # continue # avoid pubsub "item-not-found" error
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
423 # d_dict[publisher] = self.getItems(service, node, max_items, None, sub_id, rsm, client.profile)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
424 # defer.returnValue(d_dict)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
425
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
426 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
427 client = self.host.getClient(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
428 return client.pubsub_client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
429
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
430 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
431 client = self.host.getClient(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
432 return client.pubsub_client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
433
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
434 def _createNode(self, service_s, nodeIdentifier, options, profile_key):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
435 client = self.host.getClient(profile_key)
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
436 return self.createNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier, options)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
437
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
438 def createNode(self, client, service, nodeIdentifier=None, options=None):
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
439 """Create a new node
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
440
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
441 @param service(jid.JID): PubSub service,
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
442 @param NodeIdentifier(unicode, None): node name
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
443 use None to create instant node (identifier will be returned by this method)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
444 @param option(dict[unicode, unicode], None): node configuration options
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
445 @return (unicode): identifier of the created node (may be different from requested name)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
446 """
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
447 return client.pubsub_client.createNode(service, nodeIdentifier, options)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
448
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
449 def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
450 client = self.host.getClient(profile_key)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
451 d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
452 def serialize(form):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
453 # FIXME: better more generic dataform serialisation should be available in SàT
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
454 return {f.var: unicode(f.value) for f in form.fields.values()}
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
455 d.addCallback(serialize)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
456 return d
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
457
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
458 def getConfiguration(self, client, service, nodeIdentifier):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
459 request = pubsub.PubSubRequest('configureGet')
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
460 request.recipient = service
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
461 request.nodeIdentifier = nodeIdentifier
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
462
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
463 def cb(iq):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
464 form = data_form.findForm(iq.pubsub.configure,
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
465 pubsub.NS_PUBSUB_NODE_CONFIG)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
466 form.typeCheck()
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
467 return form
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
468
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
469 d = request.send(client.xmlstream)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
470 d.addCallback(cb)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
471 return d
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
472
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
473 def _setNodeConfiguration(self, service_s, nodeIdentifier, options, profile_key):
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
474 client = self.host.getClient(profile_key)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
475 d = self.setConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier, options)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
476 return d
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
477
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
478 def setConfiguration(self, client, service, nodeIdentifier, options):
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
479 request = pubsub.PubSubRequest('configureSet')
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
480 request.recipient = service
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
481 request.nodeIdentifier = nodeIdentifier
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
482
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
483 form = data_form.Form(formType='submit',
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
484 formNamespace=pubsub.NS_PUBSUB_NODE_CONFIG)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
485 form.makeFields(options)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
486 request.options = form
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
487
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
488 d = request.send(client.xmlstream)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
489 return d
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
490
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
491 def _getAffiliations(self, service_s, nodeIdentifier, profile_key):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
492 client = self.host.getClient(profile_key)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
493 d = self.getAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier or None)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
494 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
495
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
496 def getAffiliations(self, client, service, nodeIdentifier=None):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
497 """Retrieve affiliations of an entity
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
498
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
499 @param nodeIdentifier(unicode, None): node to get affiliation from
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
500 None to get all nodes affiliations for this service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
501 """
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
502 request = pubsub.PubSubRequest('affiliations')
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
503 request.recipient = service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
504 request.nodeIdentifier = nodeIdentifier
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
505
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
506 def cb(iq_elt):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
507 try:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
508 affiliations_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB, 'affiliations')))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
509 except StopIteration:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
510 raise ValueError(_(u"Invalid result: missing <affiliations> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
511 try:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
512 return {e['node']: e['affiliation'] for e in affiliations_elt.elements((pubsub.NS_PUBSUB, 'affiliation'))}
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
513 except KeyError:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
514 raise ValueError(_(u"Invalid result: bad <affiliation> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
515
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
516 d = request.send(client.xmlstream)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
517 d.addCallback(cb)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
518 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
519
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
520 def _getNodeAffiliations(self, service_s, nodeIdentifier, profile_key):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
521 client = self.host.getClient(profile_key)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
522 d = self.getNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
2226
6856b7225c5b plugin XEP-0060: getNodeAffiliations use jid.JID as keys instead of jids as unicode
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
523 d.addCallback(lambda affiliations: {j.full(): a for j, a in affiliations.iteritems()})
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
524 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
525
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
526 def getNodeAffiliations(self, client, service, nodeIdentifier):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
527 """Retrieve affiliations of a node owned by profile"""
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
528 request = pubsub.PubSubRequest('affiliationsGet')
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
529 request.recipient = service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
530 request.nodeIdentifier = nodeIdentifier
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
531
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
532 def cb(iq_elt):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
533 try:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
534 affiliations_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB_OWNER, 'affiliations')))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
535 except StopIteration:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
536 raise ValueError(_(u"Invalid result: missing <affiliations> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
537 try:
2226
6856b7225c5b plugin XEP-0060: getNodeAffiliations use jid.JID as keys instead of jids as unicode
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
538 return {jid.JID(e['jid']): e['affiliation'] for e in affiliations_elt.elements((pubsub.NS_PUBSUB_OWNER, 'affiliation'))}
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
539 except KeyError:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
540 raise ValueError(_(u"Invalid result: bad <affiliation> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
541
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
542 d = request.send(client.xmlstream)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
543 d.addCallback(cb)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
544 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
545
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
546 def _setNodeAffiliations(self, service_s, nodeIdentifier, affiliations, profile_key=C.PROF_KEY_NONE):
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
547 client = self.host.getClient(profile_key)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
548 affiliations = {jid.JID(jid_): affiliation for jid_, affiliation in affiliations.iteritems()}
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
549 d = self.setNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier, affiliations)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
550 return d
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
551
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
552 def setNodeAffiliations(self, client, service, nodeIdentifier, affiliations):
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
553 """Update affiliations of a node owned by profile
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
554
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
555 @param affiliations(dict[jid.JID, unicode]): affiliations to set
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
556 check https://xmpp.org/extensions/xep-0060.html#affiliations for a list of possible affiliations
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
557 """
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
558 request = pubsub.PubSubRequest('affiliationsSet')
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
559 request.recipient = service
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
560 request.nodeIdentifier = nodeIdentifier
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
561 request.affiliations = affiliations
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
562 d = request.send(client.xmlstream)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
563 return d
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
564
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
565 def _deleteNode(self, service_s, nodeIdentifier, profile_key):
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
566 client = self.host.getClient(profile_key)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
567 return self.deleteNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
568
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
569 def deleteNode(self, client, service, nodeIdentifier):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
570 return client.pubsub_client.deleteNode(service, nodeIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
571
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
572 def _retractItem(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
573 return self._retractItems(service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
574
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
575 def _retractItems(self, service_s, nodeIdentifier, itemIdentifiers, notify, profile_key):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
576 return self.retractItems(jid.JID(service_s) if service_s else None, nodeIdentifier, itemIdentifiers, notify, profile_key)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
577
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
578 def retractItems(self, service, nodeIdentifier, itemIdentifiers, notify=True, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
579 client = self.host.getClient(profile_key)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
580 return client.pubsub_client.retractItems(service, nodeIdentifier, itemIdentifiers, notify=True)
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
581
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
582 def subscribe(self, service, nodeIdentifier, sub_jid=None, options=None, profile_key=C.PROF_KEY_NONE):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
583 # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
584 client = self.host.getClient(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
585 return client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.pubsub_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
586
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
587 def subscriptions(self, service, nodeIdentifier='', profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
588 client = self.host.getClient(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
589 return client.pubsub_client.subscriptions(service, nodeIdentifier)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
590
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
591 ## misc tools ##
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
592
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
593 def getNodeURI(self, service, node, item=None):
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
594 """Return XMPP URI of a PubSub node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
595
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
596 @param service(jid.JID): PubSub service,
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
597 @param node(unicode): node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
598 @return (unicode): URI of the node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
599 """
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
600 assert service is not None
1854
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
601 # XXX: urllib.urlencode use "&" to separate value, while XMPP URL (cf. RFC 5122)
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
602 # use ";" as a separator. So if more than one value is used in query_data,
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
603 # urlencode MUST NOT BE USED.
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
604 query_data = [('node', node.encode('utf-8'))]
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
605 if item is not None:
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
606 query_data.append(('item', item.encode('utf-8')))
1854
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
607 return "xmpp:{service}?;{query}".format(
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
608 service=service.userhost(),
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
609 query=urllib.urlencode(query_data)
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
610 ).decode('utf-8')
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
611
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
612 ## methods to manage several stanzas/jids at once ##
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
613
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
614 # generic #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
615
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
616 def getRTResults(self, session_id, on_success=None, on_error=None, profile=C.PROF_KEY_NONE):
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
617 return self.rt_sessions.getResults(session_id, on_success, on_error, profile)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
618
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
619 def serItemsData(self, items_data, item_cb=lambda item: item.toXml()):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
620 """Helper method to serialise result from [getItems]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
621
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
622 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode])
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
623 as returned by [getItems]. metadata values are then casted to unicode and
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
624 each item is passed to items_cb
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
625 @param items_data(tuple): tuple returned by [getItems]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
626 @param item_cb(callable): method to transform each item
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
627 @return (tuple): a serialised form ready to go throught bridge
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
628 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
629 items, metadata = items_data
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
630 return [item_cb(item) for item in items], {key: unicode(value) for key, value in metadata.iteritems()}
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
631
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
632 def serItemsDataD(self, items_data, item_cb):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
633 """Helper method to serialise result from [getItems], deferred version
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
634
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
635 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode])
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
636 as returned by [getItems]. metadata values are then casted to unicode and
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
637 each item is passed to items_cb
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
638 An errback is added to item_cb, and when it is fired the value is filtered from final items
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
639 @param items_data(tuple): tuple returned by [getItems]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
640 @param item_cb(callable): method to transform each item (must return a deferred)
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
641 @return (tuple): a deferred which fire a serialised form ready to go throught bridge
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
642 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
643 items, metadata = items_data
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
644 def eb(failure):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
645 log.warning("Error while serialising/parsing item: {}".format(unicode(failure.value)))
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
646 d = defer.gatherResults([item_cb(item).addErrback(eb) for item in items])
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
647 def finishSerialisation(serialised_items):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
648 return [item for item in serialised_items if item is not None], {key: unicode(value) for key, value in metadata.iteritems()}
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
649 d.addCallback(finishSerialisation)
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
650 return d
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
651
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
652 def serDList(self, results, failure_result=None):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
653 """Serialise a DeferredList result
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
654
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
655 @param results: DeferredList results
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
656 @param failure_result: value to use as value for failed Deferred
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
657 (default: empty tuple)
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
658 @return (list): list with:
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
659 - failure: empty in case of success, else error message
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
660 - result
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
661 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
662 if failure_result is None:
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
663 failure_result = ()
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
664 return [('', result) if success else (unicode(result.result) or UNSPECIFIED, failure_result) for success, result in results]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
665
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
666 # subscribe #
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
667
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
668 def _getNodeSubscriptions(self, service_s, nodeIdentifier, profile_key):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
669 client = self.host.getClient(profile_key)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
670 d = self.getNodeSubscriptions(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
671 d.addCallback(lambda subscriptions: {j.full(): a for j, a in subscriptions.iteritems()})
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
672 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
673
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
674 def getNodeSubscriptions(self, client, service, nodeIdentifier):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
675 """Retrieve subscriptions to a node
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
676
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
677 @param nodeIdentifier(unicode): node to get subscriptions from
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
678 """
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
679 if not nodeIdentifier:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
680 raise exceptions.DataError("node identifier can't be empty")
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
681 request = pubsub.PubSubRequest('subscriptionsGet')
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
682 request.recipient = service
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
683 request.nodeIdentifier = nodeIdentifier
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
684
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
685 def cb(iq_elt):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
686 try:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
687 subscriptions_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB, 'subscriptions')))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
688 except StopIteration:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
689 raise ValueError(_(u"Invalid result: missing <subscriptions> element: {}").format(iq_elt.toXml))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
690 except AttributeError as e:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
691 raise ValueError(_(u"Invalid result: {}").format(e))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
692 try:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
693 return {jid.JID(s['jid']): s['subscription'] for s in subscriptions_elt.elements((pubsub.NS_PUBSUB, 'subscription'))}
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
694 except KeyError:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
695 raise ValueError(_(u"Invalid result: bad <subscription> element: {}").format(iq_elt.toXml))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
696
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
697 d = request.send(client.xmlstream)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
698 d.addCallback(cb)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
699 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
700
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
701 def _setNodeSubscriptions(self, service_s, nodeIdentifier, subscriptions, profile_key=C.PROF_KEY_NONE):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
702 client = self.host.getClient(profile_key)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
703 subscriptions = {jid.JID(jid_): subscription for jid_, subscription in subscriptions.iteritems()}
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
704 d = self.setNodeSubscriptions(client, jid.JID(service_s) if service_s else None, nodeIdentifier, subscriptions)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
705 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
706
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
707 def setNodeSubscriptions(self, client, service, nodeIdentifier, subscriptions):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
708 """Set or update subscriptions of a node owned by profile
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
709
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
710 @param subscriptions(dict[jid.JID, unicode]): subscriptions to set
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
711 check https://xmpp.org/extensions/xep-0060.html#substates for a list of possible subscriptions
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
712 """
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
713 request = pubsub.PubSubRequest('subscriptionsSet')
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
714 request.recipient = service
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
715 request.nodeIdentifier = nodeIdentifier
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
716 request.subscriptions = {pubsub.Subscription(nodeIdentifier, jid_, state) for jid_, state in subscriptions.iteritems()}
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
717 d = request.send(client.xmlstream)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
718 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
719
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
720 def _manySubscribeRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
721 """Get real-time results for subcribeToManu session
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
722
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
723 @param session_id: id of the real-time deferred session
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
724 @param return (tuple): (remaining, results) where:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
725 - remaining is the number of still expected results
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
726 - results is a list of tuple(unicode, unicode, bool, unicode) with:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
727 - service: pubsub service
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
728 - and node: pubsub node
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
729 - failure(unicode): empty string in case of success, error message else
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
730 @param profile_key: %(doc_profile_key)s
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
731 """
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
732 profile = self.host.getClient(profile_key).profile
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
733 d = self.rt_sessions.getResults(session_id, on_success=lambda result:'', on_error=lambda failure:unicode(failure.value), profile=profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
734 # we need to convert jid.JID to unicode with full() to serialise it for the bridge
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
735 d.addCallback(lambda ret: (ret[0], [(service.full(), node, '' if success else failure or UNSPECIFIED)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
736 for (service, node), (success, failure) in ret[1].iteritems()]))
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
737 return d
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
738
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
739 def _subscribeToMany(self, node_data, subscriber=None, options=None, profile_key=C.PROF_KEY_NONE):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
740 return self.subscribeToMany([(jid.JID(service), unicode(node)) for service, node in node_data], jid.JID(subscriber), options, profile_key)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
741
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
742 def subscribeToMany(self, node_data, subscriber, options=None, profile_key=C.PROF_KEY_NONE):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
743 """Subscribe to several nodes at once.
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
744
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
745 @param node_data (iterable[tuple]): iterable of tuple (service, node) where:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
746 - service (jid.JID) is the pubsub service
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
747 - node (unicode) is the node to subscribe to
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
748 @param subscriber (jid.JID): optional subscription identifier.
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
749 @param options (dict): subscription options
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
750 @param profile_key (str): %(doc_profile_key)s
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
751 @return (str): RT Deferred session id
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
752 """
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
753 client = self.host.getClient(profile_key)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
754 deferreds = {}
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
755 for service, node in node_data:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
756 deferreds[(service, node)] = client.pubsub_client.subscribe(service, node, subscriber, options=options)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
757 return self.rt_sessions.newSession(deferreds, client.profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
758 # found_nodes = yield self.listNodes(service, profile=client.profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
759 # subscribed_nodes = yield self.listSubscribedNodes(service, profile=client.profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
760 # d_list = []
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
761 # for nodeIdentifier in (set(nodeIdentifiers) - set(subscribed_nodes)):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
762 # if nodeIdentifier not in found_nodes:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
763 # log.debug(u"Skip the subscription to [{node}]: node doesn't exist".format(node=nodeIdentifier))
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
764 # continue # avoid sat-pubsub "SubscriptionExists" error
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
765 # d_list.append(client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.pubsub_client.parent.jid.userhostJID(), options=options))
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
766 # defer.returnValue(d_list)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
767
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
768 # get #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
769
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
770 def _getFromManyRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT):
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
771 """Get real-time results for getFromMany session
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
772
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
773 @param session_id: id of the real-time deferred session
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
774 @param profile_key: %(doc_profile_key)s
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
775 @param return (tuple): (remaining, results) where:
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
776 - remaining is the number of still expected results
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
777 - results is a list of tuple with
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
778 - service (unicode): pubsub service
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
779 - node (unicode): pubsub node
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
780 - failure (unicode): empty string in case of success, error message else
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
781 - items (list[s]): raw XML of items
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
782 - metadata(dict): serialised metadata
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
783 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
784 profile = self.host.getClient(profile_key).profile
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
785 d = self.rt_sessions.getResults(session_id,
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
786 on_success=lambda result: ('', self.serItemsData(result)),
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
787 on_error=lambda failure: (unicode(failure.value) or UNSPECIFIED, ([],{})),
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
788 profile=profile)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
789 d.addCallback(lambda ret: (ret[0],
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
790 [(service.full(), node, failure, items, metadata)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
791 for (service, node), (success, (failure, (items, metadata))) in ret[1].iteritems()]))
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
792 return d
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
793
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
794 def _getFromMany(self, node_data, max_item=10, extra_dict=None, profile_key=C.PROF_KEY_NONE):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
795 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
796 @param max_item(int): maximum number of item to get, C.NO_LIMIT for no limit
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
797 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
798 max_item = None if max_item == C.NO_LIMIT else max_item
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
799 extra = self.parseExtra(extra_dict)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
800 return self.getFromMany([(jid.JID(service), unicode(node)) for service, node in node_data], max_item, extra.rsm_request, extra.extra, profile_key)
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
801
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
802 def getFromMany(self, node_data, max_item=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
803 """Get items from many nodes at once
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
804
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
805 @param node_data (iterable[tuple]): iterable of tuple (service, node) where:
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
806 - service (jid.JID) is the pubsub service
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
807 - node (unicode) is the node to get items from
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
808 @param max_items (int): optional limit on the number of retrieved items.
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
809 @param rsm_request (RSMRequest): RSM request data
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
810 @param profile_key (unicode): %(doc_profile_key)s
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
811 @return (str): RT Deferred session id
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
812 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
813 client = self.host.getClient(profile_key)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
814 deferreds = {}
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
815 for service, node in node_data:
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
816 deferreds[(service, node)] = self.getItems(service, node, max_item, rsm_request=rsm_request, extra=extra, profile_key=profile_key)
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
817 return self.rt_sessions.newSession(deferreds, client.profile)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
818
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
819
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
820 class SatPubSubClient(rsm.PubSubClient):
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
821 implements(disco.IDisco)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
822
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
823 def __init__(self, host, parent_plugin):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
824 self.host = host
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
825 self.parent_plugin = parent_plugin
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
826 rsm.PubSubClient.__init__(self)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
827
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
828 def connectionInitialized(self):
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
829 rsm.PubSubClient.connectionInitialized(self)
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
830
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
831 def _getNodeCallbacks(self, node, event):
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
832 """Generate callbacks from given node and event
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
833
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
834 @param node(unicode): node used for the item
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
835 any registered node which prefix the node will match
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
836 @param event(unicode): one of C.PS_ITEMS, C.PS_RETRACT, C.PS_DELETE
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
837 @return (iterator[callable]): callbacks for this node/event
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
838 """
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
839 for registered_node, callbacks_dict in self.parent_plugin._node_cb.iteritems():
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
840 if not node.startswith(registered_node):
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
841 continue
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
842 try:
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
843 for callback in callbacks_dict[event]:
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
844 yield callback
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
845 except KeyError:
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
846 continue
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
847
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
848 def itemsReceived(self, event):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
849 log.debug(u"Pubsub items received")
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
850 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS):
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
851 callback(self.parent, event)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
852
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
853 def deleteReceived(self, event):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
854 log.debug((u"Publish node deleted"))
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
855 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE):
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
856 callback(self.parent, event)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
857
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
858 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
859 """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
860
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
861 @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
862 @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
863 @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
864 @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
865 """
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
866 request = pubsub.PubSubRequest('subscriptions')
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
867 request.recipient = service
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
868 request.nodeIdentifier = nodeIdentifier
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
869 request.sender = sender
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
870 d = request.send(self.xmlstream)
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
871
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
872 def cb(iq):
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
873 # FIXME: to be checked
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
874 return [sub for sub in iq.pubsub.subscriptions.elements() if
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
875 (sub.uri == pubsub.NS_PUBSUB and sub.name == 'subscription')]
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
876
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
877 return d.addCallback(cb)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
878
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
879 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
880 disco_info = []
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
881 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
882 return disco_info
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
883
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
884 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
885 return []