annotate sat/plugins/plugin_xep_0060.py @ 2801:ae127e14b040

plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
author Goffi <goffi@goffi.org>
date Fri, 15 Feb 2019 22:13:43 +0100
parents 3b68293a60d4
children 0b7ce5daee9b
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)
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2769
diff changeset
5 # Copyright (C) 2009-2019 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
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
24 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
25 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
26 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
27
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
28 from twisted.words.protocols.jabber import jid, error
2769
9282b289b964 plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents: 2760
diff changeset
29 from twisted.internet import reactor, 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
30 from wokkel import disco
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
31 from wokkel import data_form
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
32 from wokkel import generic
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
33 from zope.interface import implements
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
34 from collections import namedtuple
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
35 import urllib
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36
2413
70399d1acb47 tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
37 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version
70399d1acb47 tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
38 # mam and rsm come from sat_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
39 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
40 from wokkel import rsm
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
41 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
42
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
43
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
44 PLUGIN_INFO = {
2702
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
45 C.PI_NAME: u"Publish-Subscribe",
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
46 C.PI_IMPORT_NAME: u"XEP-0060",
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
47 C.PI_TYPE: u"XEP",
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
48 C.PI_PROTOCOLS: [u"XEP-0060"],
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 C.PI_DEPENDENCIES: [],
2702
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
50 C.PI_RECOMMENDATIONS: [u"XEP-0059", u"XEP-0313"],
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
51 C.PI_MAIN: u"XEP_0060",
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
52 C.PI_HANDLER: u"yes",
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
53 C.PI_DESCRIPTION: _(u"""Implementation of PubSub Protocol"""),
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
54 }
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
55
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
56 UNSPECIFIED = "unspecified error"
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
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 Extra = namedtuple("Extra", ("rsm_request", "extra"))
1459
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
2769
9282b289b964 plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents: 2760
diff changeset
62 TIMEOUT = 30
1459
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):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 OPT_ACCESS_MODEL = "pubsub#access_model"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 OPT_PERSIST_ITEMS = "pubsub#persist_items"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 OPT_MAX_ITEMS = "pubsub#max_items"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 OPT_DELIVER_PAYLOADS = "pubsub#deliver_payloads"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 OPT_SEND_ITEM_SUBSCRIBE = "pubsub#send_item_subscribe"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 OPT_NODE_TYPE = "pubsub#node_type"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 OPT_SUBSCRIPTION_TYPE = "pubsub#subscription_type"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 OPT_SUBSCRIPTION_DEPTH = "pubsub#subscription_depth"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 OPT_ROSTER_GROUPS_ALLOWED = "pubsub#roster_groups_allowed"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 OPT_PUBLISH_MODEL = "pubsub#publish_model"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 ACCESS_OPEN = "open"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 ACCESS_PRESENCE = "presence"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 ACCESS_ROSTER = "roster"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 ACCESS_PUBLISHER_ROSTER = "publisher-roster"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 ACCESS_AUTHORIZE = "authorize"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 ACCESS_WHITELIST = "whitelist"
2647
1bf7e89fded0 plugin XEP-0060: added singleton ID ("current")
Goffi <goffi@goffi.org>
parents: 2643
diff changeset
81 ID_SINGLETON = "current"
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
82
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
83 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
84 log.info(_(u"PubSub plugin initialization"))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.host = host
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
86 self._rsm = host.plugins.get(u"XEP-0059")
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
87 self._mam = host.plugins.get(u"XEP-0313")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 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
89 self.rt_sessions = sat_defer.RTDeferredSessions()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 "psNodeCreate",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 method=self._createNode,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 "psNodeConfigurationGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 out_sign="a{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 method=self._getNodeConfiguration,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 "psNodeConfigurationSet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 method=self._setNodeConfiguration,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 "psNodeAffiliationsGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 out_sign="a{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 method=self._getNodeAffiliations,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 "psNodeAffiliationsSet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 method=self._setNodeAffiliations,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 "psNodeSubscriptionsGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 out_sign="a{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 method=self._getNodeSubscriptions,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 "psNodeSubscriptionsSet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 method=self._setNodeSubscriptions,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 host.bridge.addMethod(
2801
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
147 "psNodePurge",
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
148 ".plugin",
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
149 in_sign="sss",
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
150 out_sign="",
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
151 method=self._purgeNode,
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
152 async=True,
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
153 )
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
154 host.bridge.addMethod(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 "psNodeDelete",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 method=self._deleteNode,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 "psNodeWatchAdd",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 method=self._addWatch,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 async=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 "psNodeWatchRemove",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 method=self._removeWatch,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 async=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 "psAffiliationsGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 out_sign="a{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 method=self._getAffiliations,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 "psItemsGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 in_sign="ssiassa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 out_sign="(asa{ss})",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 method=self._getItems,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 "psItemSend",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 in_sign="ssssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 method=self._sendItem,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 host.bridge.addMethod(
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
203 "psItemsSend",
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
204 ".plugin",
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
205 in_sign="ssasa{ss}s",
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
206 out_sign="as",
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
207 method=self._sendItems,
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
208 async=True,
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
209 )
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
210 host.bridge.addMethod(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 "psRetractItem",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 in_sign="sssbs",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215 method=self._retractItem,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
217 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 "psRetractItems",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 in_sign="ssasbs",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 method=self._retractItems,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 "psSubscribe",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
229 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 method=self._subscribe,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
235 "psUnsubscribe",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
237 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
238 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239 method=self._unsubscribe,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
243 "psSubscriptionsGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
245 in_sign="sss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
246 out_sign="aa{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
247 method=self._subscriptions,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
248 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
249 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
250 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 "psSubscribeToMany",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
252 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253 in_sign="a(ss)sa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 method=self._subscribeToMany,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
257 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
258 "psGetSubscribeRTResult",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
259 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
260 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
261 out_sign="(ua(sss))",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
262 method=self._manySubscribeRTResult,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
263 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
264 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
265 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
266 "psGetFromMany",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
267 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
268 in_sign="a(ss)ia{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
270 method=self._getFromMany,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
273 "psGetFromManyRTResult",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
274 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 out_sign="(ua(sssasa{ss}))",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 method=self._getFromManyRTResult,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
278 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
279 )
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
280
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
281 #  high level observer method
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
282 host.bridge.addSignal(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
283 "psEvent", ".plugin", signature="ssssa{ss}s"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
284 ) # 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
285
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
286 # low level observer method, used if service/node is in watching list (see psNodeWatch* methods)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 host.bridge.addSignal(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 "psEventRaw", ".plugin", signature="sssass"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
289 ) # args: service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), list of item_xml, profile
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
290
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
291 def getHandler(self, client):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
292 client.pubsub_client = SatPubSubClient(self.host, self)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
293 return client.pubsub_client
1282
74d558e6c9fd plugin XEP-0060: free SatPubSubClient instance on profile disconnection
souliane <souliane@mailoo.org>
parents: 1268
diff changeset
294
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
295 @defer.inlineCallbacks
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
296 def profileConnected(self, client):
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
297 client.pubsub_watching = set()
2459
a9c092bf4ee9 plugin XEP-0060: added an config option to set pubsub service
Goffi <goffi@goffi.org>
parents: 2444
diff changeset
298 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 client.pubsub_service = jid.JID(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 self.host.memory.getConfig("", "pubsub_service")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 )
2459
a9c092bf4ee9 plugin XEP-0060: added an config option to set pubsub service
Goffi <goffi@goffi.org>
parents: 2444
diff changeset
302 except RuntimeError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 log.info(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 u"Can't retrieve pubsub_service from conf, we'll use first one that we find"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
306 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 client.pubsub_service = yield self.host.findServiceEntity(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
309 client, "pubsub", "service"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
310 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
311
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
312 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
313 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
314 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
315 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
316 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
317 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
319 "service": client.pubsub_service.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
320 if client.pubsub_service is not None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 else ""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 }
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
323 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
324 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
325 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
326 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
327 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
328 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
329
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
330 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
331 """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
332
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
333 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
334 @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
335 @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
336 """
2484
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
337 if extra is None:
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
338 rsm_request = None
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
339 extra = {}
785b6a1cef0a plugin forums: first draft:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
340 else:
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
341 # order-by
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
342 if C.KEY_ORDER_BY in extra:
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
343 # FIXME: we temporarily manage only one level of ordering
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
344 # we need to switch to a fully serialised extra data
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
345 # to be able to encode a whole ordered list
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
346 extra[C.KEY_ORDER_BY] = [extra.pop(C.KEY_ORDER_BY)]
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
347
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
348 # rsm
2702
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
349 if self._rsm is None:
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
350 rsm_request = None
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
351 else:
2702
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
352 rsm_request = self._rsm.parseExtra(extra)
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
353
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
354 # mam
2702
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
355 if self._mam is None:
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
356 mam_request = None
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
357 else:
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
358 mam_request = self._mam.parseExtra(extra, with_rsm=False)
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
359
2702
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
360 if mam_request is not None:
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
361 assert u"mam" not in extra
6555e9835ff8 plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents: 2647
diff changeset
362 extra[u"mam"] = mam_request
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
363
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
364 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
365
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
366 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
367 """Add a handler for a node
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
368
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
369 @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
370 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
371 @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
372 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
373 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
374 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
375 """
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
376 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
377 assert kwargs
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
378 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
379 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
380 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
381 assert event_name in C.PS_EVENTS
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
382 callbacks.setdefault(event_name, []).append(cb)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
383
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
384 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
385 """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
386
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
387 @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
388 @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
389 """
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
390 assert args
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
391 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
392 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
393 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
394 pass
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
395 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
396 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
397 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
398 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
399 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
400 except ValueError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
401 pass
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
402 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
403 log.debug(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
404 u"removed callback {cb} for event {event} on node {node}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
405 cb=callback, event=event, node=node
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
406 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
407 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
408 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
409 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
410 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
411 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
412 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
413 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 u"Trying to remove inexistant callback {cb} for node {node}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
415 cb=callback, node=node
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
416 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
417 )
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
418
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
419 # 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
420 # """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
421
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
422 # @param service (JID): target service
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
423 # @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
424 # @param profile (str): %(doc_profile)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
425 # @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
426 # """
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
427 # 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
428 # 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
429 # 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
430 # return d
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
431
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
432 # 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
433 # """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
434
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
435 # @param service (JID): target service
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
436 # @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
437 # @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
438 # - None: do not filter
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
439 # - '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
440 # - '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
441 # - 'subscribed': subscription is complete
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
442 # @param profile (str): %(doc_profile)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
443 # @return: Deferred list[str]
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
444 # """
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
445 # 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
446 # 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
447 # return d
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
448
2776
838f53730ce4 plugin pubsub admin: pubsub administrator first draft:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
449 def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra=None,
838f53730ce4 plugin pubsub admin: pubsub administrator first draft:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
450 profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
451 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
452 service = None if not service else jid.JID(service)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
453 d = self.sendItem(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
454 client, service, nodeIdentifier, payload, item_id or None, extra
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
455 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
456 d.addCallback(lambda ret: ret or u"")
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
457 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
458
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
459 def _sendItems(self, service, nodeIdentifier, items, extra=None,
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
460 profile_key=C.PROF_KEY_NONE):
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
461 client = self.host.getClient(profile_key)
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
462 service = None if not service else jid.JID(service)
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
463 try:
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
464 items = [generic.parseXml(item.encode('utf-8')) for item in items]
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
465 except Exception as e:
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
466 raise exceptions.DataError(_(u"Can't parse items: {msg}").format(
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
467 msg=e))
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
468 d = self.sendItems(
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
469 client, service, nodeIdentifier, items, extra
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
470 )
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
471 return d
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
472
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
473 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
474 """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
475
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
476 if not found original_id is returned, or empty string if it is None or empty
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
477 string
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
478 """
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
479 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
480 item_id = iq_elt.pubsub.publish.item["id"]
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
481 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
482 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
483 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
484
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
485 def sendItem(self, client, service, nodeIdentifier, payload, item_id=None,
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
486 extra=None):
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
487 """High level method to send one item
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
488
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
489 @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
490 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
491 @param NodeIdentifier(unicode): PubSub node to use
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
492 @param payload(domish.Element, unicode): payload of the item to send
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
493 @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
494 @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
495 @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
496 """
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
497 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
498 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
499 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
500 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
501
2800
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
502 def _publishCb(self, iq_result):
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
503 """Parse publish result, and return ids given by pubsub service"""
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
504 try:
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
505 item_ids = [item['id']
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
506 for item in iq_result.pubsub.publish.elements(pubsub.NS_PUBSUB, u'item')]
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
507 except AttributeError:
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
508 return []
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
509 return item_ids
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
510
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
511 def sendItems(self, client, service, nodeIdentifier, items, extra=None):
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
512 """High level method to send several items at once
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
513
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
514 @param service(jid.JID, None): service to send the item to
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
515 None to use PEP
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
516 @param NodeIdentifier(unicode): PubSub node to use
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
517 @param items(list[domish.Element]): whole item elements to send,
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
518 "id" will be used if set
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
519 @param extra(dict, None): extra option, not used yet
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
520 @return (list[unicode]): ids of the created items
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
521 """
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
522 parsed_items = []
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
523 for item in items:
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
524 if item.name != u'item':
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
525 raise exceptions.DataError(_(u"Invalid item: {xml}").format(item.toXml()))
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
526 item_id = item.getAttribute(u"id")
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
527 parsed_items.append(pubsub.Item(id=item_id, payload=item.firstChildElement()))
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
528 d = self.publish(client, service, nodeIdentifier, parsed_items)
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
529 d.addCallback(self._publishCb)
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
530 return d
3b68293a60d4 plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents: 2776
diff changeset
531
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
532 def publish(self, client, service, nodeIdentifier, items=None):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
533 return client.pubsub_client.publish(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
534 service, nodeIdentifier, items, client.pubsub_client.parent.jid
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
535 )
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
536
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
537 def _unwrapMAMMessage(self, message_elt):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
538 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
539 item_elt = (
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
540 message_elt.elements(mam.NS_MAM, "result").next()
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
541 .elements(C.NS_FORWARD, "forwarded").next()
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
542 .elements(C.NS_CLIENT, "message").next()
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
543 .elements("http://jabber.org/protocol/pubsub#event", "event").next()
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
544 .elements("http://jabber.org/protocol/pubsub#event", "items").next()
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
545 .elements("http://jabber.org/protocol/pubsub#event", "item").next()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
546 )
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
547 except StopIteration:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
548 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
549 return item_elt
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
550
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
551 def _getItems(self, service="", node="", max_items=10, item_ids=None, sub_id=None,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
552 extra_dict=None, profile_key=C.PROF_KEY_NONE):
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
553 """Get items from pubsub node
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
554
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
555 @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
556 """
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2352
diff changeset
557 client = self.host.getClient(profile_key)
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
558 service = jid.JID(service) if service else None
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
559 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
560 extra = self.parseExtra(extra_dict)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
561 d = self.getItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
562 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
563 service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
564 node or None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
565 max_items or None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
566 item_ids,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
567 sub_id or None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
568 extra.rsm_request,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
569 extra.extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
570 )
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
571 d.addCallback(self.serItemsData)
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
572 return d
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
573
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
574 def getItems(self, client, service, node, max_items=None, item_ids=None, sub_id=None,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
575 rsm_request=None, extra=None):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
576 """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
577
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
578 @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
579 @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
580 @param max_items (int): optional limit on the number of retrieved items.
2758
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
581 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
582 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
583 @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
584 @param rsm_request (rsm.RSMRequest): RSM request data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
585 @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
586 - list of items
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
587 - metadata with the following keys:
2718
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
588 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index
bb6adaa580ee plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents: 2702
diff changeset
589 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
590 - 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
591 """
2319
e715a29c4f9b plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents: 2314
diff changeset
592 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
593 max_items = None
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
594 if rsm_request and item_ids:
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
595 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
596 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
597 extra = {}
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
598 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
599 mam_query = extra["mam"]
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
600 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
601 d = client.pubsub_client.items(
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
602 service = service,
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
603 nodeIdentifier = node,
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
604 maxItems = max_items,
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
605 subscriptionIdentifier = sub_id,
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
606 sender = None,
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
607 itemIdentifiers = item_ids,
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
608 orderBy = extra.get(C.KEY_ORDER_BY),
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
609 rsm_request = rsm_request
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
610 )
2758
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
611 # we have no MAM data here, so we add None
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
612 d.addCallback(lambda data: data + (None,))
2769
9282b289b964 plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents: 2760
diff changeset
613 d.addTimeout(TIMEOUT, reactor)
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
614 else:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
615 # 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
616 if self._mam is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
617 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
618 if max_items is not None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
619 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
620 if item_ids:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
621 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
622 if mam_query.node is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
623 mam_query.node = node
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
624 elif mam_query.node != node:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
625 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
626 u"MAM query node is incoherent with getItems's node"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
627 )
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
628 if mam_query.rsm is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
629 mam_query.rsm = rsm_request
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
630 else:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
631 if mam_query.rsm != rsm_request:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
632 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
633 u"Conflict between RSM request and MAM's RSM request"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
634 )
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
635 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
636
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
637 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
638 subscribe = C.bool(extra["subscribe"])
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
639 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
640 subscribe = False
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
641
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
642 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
643 failure.trap(error.StanzaError)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
644 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
645 u"Could not subscribe to node {} on service {}: {}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
646 node, unicode(service), unicode(failure.value)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
647 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
648 )
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
649
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
650 def doSubscribe(data):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
651 self.subscribe(service, node, profile_key=client.profile).addErrback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
652 subscribeEb, service, node
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
653 )
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
654 return data
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
655
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
656 if subscribe:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
657 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
658
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
659 def addMetadata(result):
2758
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
660 # TODO: handle the third argument (mam_response)
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
661 items, rsm_response, mam_response = result
2314
01f0a954d506 plugin XEP-0060: fixed service in metadata for PEP
Goffi <goffi@goffi.org>
parents: 2305
diff changeset
662 service_jid = service if service else client.jid.userhostJID()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
663 metadata = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
664 "service": service_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
665 "node": node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
666 "uri": self.getNodeURI(service_jid, node),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
667 }
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
668 if rsm_request is not None and rsm_response is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
669 metadata.update(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
670 {
2758
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
671 u"rsm_" + key: value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
672 for key, value in rsm_response.toDict().iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
673 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
674 )
2758
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
675 if mam_response is not None:
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
676 for key, value in mam_response.iteritems():
f4070693814a plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents: 2718
diff changeset
677 metadata[u"mam_" + key] = value
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
678 return (items, metadata)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
679
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
680 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
681 return d
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
682
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
683 # @defer.inlineCallbacks
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
684 # 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
685 # """Massively retrieve pubsub items from many nodes.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
686 # @param service (JID): target service.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
687 # @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
688 # @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
689 # @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
690 # @param rsm (dict): RSM request data
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
691 # @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
692 # @return: a deferred dict with:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
693 # - 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
694 # - couple (list[dict], dict) containing:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
695 # - list of items
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
696 # - RSM response data
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
697 # """
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
698 # client = self.host.getClient(profile_key)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
699 # 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
700 # d_dict = {}
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
701 # for publisher, node in data.items():
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
702 # if node not in found_nodes:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
703 # 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
704 # 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
705 # 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
706 # 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
707
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
708 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
709 profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
710 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
711 return client.pubsub_client.getOptions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
712 service, nodeIdentifier, subscriber, subscriptionIdentifier
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
713 )
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
714
2643
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
715 def setOptions(self, service, nodeIdentifier, subscriber, options,
189e38fb11ff core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
716 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
717 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
718 return client.pubsub_client.setOptions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
719 service, nodeIdentifier, subscriber, options, subscriptionIdentifier
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
720 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
721
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
722 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
723 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
724 return self.createNode(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
725 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
726 )
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
727
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
728 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
729 """Create a new node
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
730
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
731 @param service(jid.JID): PubSub service,
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
732 @param NodeIdentifier(unicode, None): node name
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
733 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
734 @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
735 @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
736 """
2393
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2389
diff changeset
737 # TODO: if pubsub service doesn't hande publish-options, configure it in a second time
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
738 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
739
2389
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
740 @defer.inlineCallbacks
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
741 def createIfNewNode(self, client, service, nodeIdentifier, options=None):
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
742 """Helper method similar to createNode, but will not fail in case of conflict"""
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
743 try:
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
744 yield self.createNode(client, service, nodeIdentifier, options)
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
745 except error.StanzaError as e:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
746 if e.condition == "conflict":
2389
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
747 pass
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
748 else:
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
749 raise e
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
750
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
751 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
752 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
753 d = self.getConfiguration(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
754 client, jid.JID(service_s) if service_s else None, nodeIdentifier
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
755 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
756
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
757 def serialize(form):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
758 # 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
759 return {f.var: unicode(f.value) for f in form.fields.values()}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
760
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
761 d.addCallback(serialize)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
762 return d
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
763
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
764 def getConfiguration(self, client, service, nodeIdentifier):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
765 request = pubsub.PubSubRequest("configureGet")
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
766 request.recipient = service
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
767 request.nodeIdentifier = nodeIdentifier
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
768
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
769 def cb(iq):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
770 form = data_form.findForm(iq.pubsub.configure, pubsub.NS_PUBSUB_NODE_CONFIG)
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
771 form.typeCheck()
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
772 return form
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
773
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
774 d = request.send(client.xmlstream)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
775 d.addCallback(cb)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
776 return d
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
777
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
778 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
779 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
780 d = self.setConfiguration(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
781 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
782 )
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
783 return d
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
784
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
785 def setConfiguration(self, client, service, nodeIdentifier, options):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
786 request = pubsub.PubSubRequest("configureSet")
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
787 request.recipient = service
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
788 request.nodeIdentifier = nodeIdentifier
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
789
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
790 form = data_form.Form(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
791 formType="submit", formNamespace=pubsub.NS_PUBSUB_NODE_CONFIG
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
792 )
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
793 form.makeFields(options)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
794 request.options = form
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
795
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
796 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
797 return d
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
798
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
799 def _getAffiliations(self, service_s, nodeIdentifier, profile_key):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
800 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
801 d = self.getAffiliations(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
802 client, jid.JID(service_s) if service_s else None, nodeIdentifier or None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
803 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
804 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
805
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
806 def getAffiliations(self, client, service, nodeIdentifier=None):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
807 """Retrieve affiliations of an entity
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
808
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
809 @param nodeIdentifier(unicode, None): node to get affiliation from
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
810 None to get all nodes affiliations for this service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
811 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
812 request = pubsub.PubSubRequest("affiliations")
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
813 request.recipient = service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
814 request.nodeIdentifier = nodeIdentifier
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
815
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
816 def cb(iq_elt):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
817 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
818 affiliations_elt = next(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
819 iq_elt.pubsub.elements((pubsub.NS_PUBSUB, "affiliations"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
820 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
821 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
822 raise ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
823 _(u"Invalid result: missing <affiliations> element: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
824 iq_elt.toXml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
825 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
826 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
827 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
828 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
829 e["node"]: e["affiliation"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
830 for e in affiliations_elt.elements((pubsub.NS_PUBSUB, "affiliation"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
831 }
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
832 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
833 raise ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
834 _(u"Invalid result: bad <affiliation> element: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
835 iq_elt.toXml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
836 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
837 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
838
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
839 d = request.send(client.xmlstream)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
840 d.addCallback(cb)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
841 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
842
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
843 def _getNodeAffiliations(self, service_s, nodeIdentifier, profile_key):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
844 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
845 d = self.getNodeAffiliations(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
846 client, jid.JID(service_s) if service_s else None, nodeIdentifier
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
847 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
848 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
849 lambda affiliations: {j.full(): a for j, a in affiliations.iteritems()}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
850 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
851 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
852
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
853 def getNodeAffiliations(self, client, service, nodeIdentifier):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
854 """Retrieve affiliations of a node owned by profile"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
855 request = pubsub.PubSubRequest("affiliationsGet")
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
856 request.recipient = service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
857 request.nodeIdentifier = nodeIdentifier
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
858
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
859 def cb(iq_elt):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
860 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
861 affiliations_elt = next(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
862 iq_elt.pubsub.elements((pubsub.NS_PUBSUB_OWNER, "affiliations"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
863 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
864 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
865 raise ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
866 _(u"Invalid result: missing <affiliations> element: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
867 iq_elt.toXml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
868 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
869 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
870 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
871 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
872 jid.JID(e["jid"]): e["affiliation"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
873 for e in affiliations_elt.elements(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
874 (pubsub.NS_PUBSUB_OWNER, "affiliation")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
875 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
876 }
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
877 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
878 raise ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
879 _(u"Invalid result: bad <affiliation> element: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
880 iq_elt.toXml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
881 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
882 )
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
883
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
884 d = request.send(client.xmlstream)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
885 d.addCallback(cb)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
886 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
887
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
888 def _setNodeAffiliations(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
889 self, service_s, nodeIdentifier, affiliations, profile_key=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
890 ):
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
891 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
892 affiliations = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
893 jid.JID(jid_): affiliation for jid_, affiliation in affiliations.iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
894 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
895 d = self.setNodeAffiliations(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
896 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
897 jid.JID(service_s) if service_s else None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
898 nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
899 affiliations,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
900 )
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
901 return d
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
902
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
903 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
904 """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
905
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
906 @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
907 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
908 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
909 request = pubsub.PubSubRequest("affiliationsSet")
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
910 request.recipient = service
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
911 request.nodeIdentifier = nodeIdentifier
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
912 request.affiliations = affiliations
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
913 d = request.send(client.xmlstream)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
914 return d
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
915
2801
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
916 def _purgeNode(self, service_s, nodeIdentifier, profile_key):
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
917 client = self.host.getClient(profile_key)
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
918 return self.purgeNode(
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
919 client, jid.JID(service_s) if service_s else None, nodeIdentifier
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
920 )
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
921
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
922 def purgeNode(self, client, service, nodeIdentifier):
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
923 return client.pubsub_client.purgeNode(service, nodeIdentifier)
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
924
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
925 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
926 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
927 return self.deleteNode(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
928 client, jid.JID(service_s) if service_s else None, nodeIdentifier
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
929 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
930
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
931 def deleteNode(self, client, service, nodeIdentifier):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
932 return client.pubsub_client.deleteNode(service, nodeIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
933
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
934 def _addWatch(self, service_s, node, profile_key):
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
935 """watch modifications on a node
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
936
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
937 This method should only be called from bridge
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
938 """
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
939 client = self.host.getClient(profile_key)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
940 service = jid.JID(service_s) if service_s else client.jid.userhostJID()
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
941 client.pubsub_watching.add((service, node))
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
942
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
943 def _removeWatch(self, service_s, node, profile_key):
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
944 """remove a node watch
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
945
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
946 This method should only be called from bridge
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
947 """
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
948 client = self.host.getClient(profile_key)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
949 service = jid.JID(service_s) if service_s else client.jid.userhostJID()
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
950 client.pubsub_watching.remove((service, node))
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
951
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
952 def _retractItem(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
953 self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
954 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
955 return self._retractItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
956 service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
957 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
958
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
959 def _retractItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
960 self, service_s, nodeIdentifier, itemIdentifiers, notify, profile_key
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
961 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
962 return self.retractItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
963 jid.JID(service_s) if service_s else None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
964 nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
965 itemIdentifiers,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
966 notify,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
967 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
968 )
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
969
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
970 def retractItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
971 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
972 service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
973 nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
974 itemIdentifiers,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
975 notify=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
976 profile_key=C.PROF_KEY_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
977 ):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
978 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
979 return client.pubsub_client.retractItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
980 service, nodeIdentifier, itemIdentifiers, notify=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
981 )
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
982
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
983 def _subscribe(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE):
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
984 client = self.host.getClient(profile_key)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
985 service = None if not service else jid.JID(service)
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
986 d = self.subscribe(client, service, nodeIdentifier, options=options or None)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
987 d.addCallback(lambda subscription: subscription.subscriptionIdentifier or u"")
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
988 return d
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
989
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
990 def subscribe(self, client, service, nodeIdentifier, sub_jid=None, options=None):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
991 # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
992 return client.pubsub_client.subscribe(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
993 service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
994 )
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
995
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
996 def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
997 client = self.host.getClient(profile_key)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
998 service = None if not service else jid.JID(service)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
999 return self.unsubscribe(client, service, nodeIdentifier)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1000
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1001 def unsubscribe(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1002 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1003 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1004 service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1005 nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1006 sub_jid=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1007 subscriptionIdentifier=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1008 sender=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1009 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1010 return client.pubsub_client.unsubscribe(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1011 service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1012 nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1013 sub_jid or client.jid.userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1014 subscriptionIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1015 sender,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1016 )
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1017
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1018 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
1019 client = self.host.getClient(profile_key)
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1020 service = None if not service else jid.JID(service)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1021
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1022 def gotSubscriptions(subscriptions):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1023 # we replace pubsub.Subscription instance by dict that we can serialize
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1024 for idx, sub in enumerate(subscriptions):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1025 sub_dict = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1026 "node": sub.nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1027 "subscriber": sub.subscriber.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1028 "state": sub.state,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1029 }
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1030 if sub.subscriptionIdentifier is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1031 sub_dict["id"] = sub.subscriptionIdentifier
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1032 subscriptions[idx] = sub_dict
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
1033
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1034 return subscriptions
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1035
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1036 d = self.subscriptions(client, service, nodeIdentifier or None)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1037 d.addCallback(gotSubscriptions)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1038 return d
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1039
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1040 def subscriptions(self, client, service, nodeIdentifier=None):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1041 """retrieve subscriptions from a service
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1042
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1043 @param service(jid.JID): PubSub service
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1044 @param nodeIdentifier(unicode, None): node to check
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1045 None to get all subscriptions
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1046 """
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
1047 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
1048
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1049 ## misc tools ##
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1050
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1051 def getNodeURI(self, service, node, item=None):
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1052 """Return XMPP URI of a PubSub node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1053
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1054 @param service(jid.JID): PubSub service
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1055 @param node(unicode): node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1056 @return (unicode): URI of the node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1057 """
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
1058 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
1059 # 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
1060 # 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
1061 # urlencode MUST NOT BE USED.
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1062 query_data = [("node", node.encode("utf-8"))]
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1063 if item is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1064 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
1065 return "xmpp:{service}?;{query}".format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1066 service=service.userhost(), query=urllib.urlencode(query_data)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1067 ).decode("utf-8")
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
1068
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
1069 ## 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
1070
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1071 # generic #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1072
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1073 def getRTResults(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1074 self, session_id, on_success=None, on_error=None, profile=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1075 ):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1076 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
1077
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1078 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
1079 """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
1080
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1081 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
1082 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
1083 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
1084 @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
1085 @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
1086 @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
1087 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1088 items, metadata = items_data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1089 return (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1090 [item_cb(item) for item in items],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1091 {key: unicode(value) for key, value in metadata.iteritems()},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1092 )
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1093
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1094 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
1095 """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
1096
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1097 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
1098 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
1099 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
1100 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
1101 @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
1102 @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
1103 @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
1104 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1105 items, metadata = items_data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1106
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1107 def eb(failure):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1108 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1109 "Error while serialising/parsing item: {}".format(unicode(failure.value))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1110 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1111
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1112 d = defer.gatherResults([item_cb(item).addErrback(eb) for item in items])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1113
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1114 def finishSerialisation(serialised_items):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1115 return (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1116 [item for item in serialised_items if item is not None],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1117 {key: unicode(value) for key, value in metadata.iteritems()},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1118 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1119
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1120 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
1121 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
1122
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1123 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
1124 """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
1125
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1126 @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
1127 @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
1128 (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
1129 @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
1130 - 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
1131 - result
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1132 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1133 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
1134 failure_result = ()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1135 return [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1136 ("", result)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1137 if success
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1138 else (unicode(result.result) or UNSPECIFIED, failure_result)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1139 for success, result in results
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1140 ]
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
1141
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
1142 # 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
1143
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1144 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
1145 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1146 d = self.getNodeSubscriptions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1147 client, jid.JID(service_s) if service_s else None, nodeIdentifier
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1148 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1149 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1150 lambda subscriptions: {j.full(): a for j, a in subscriptions.iteritems()}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1151 )
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1152 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1153
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1154 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
1155 """Retrieve subscriptions to a node
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1156
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1157 @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
1158 """
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1159 if not nodeIdentifier:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1160 raise exceptions.DataError("node identifier can't be empty")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1161 request = pubsub.PubSubRequest("subscriptionsGet")
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1162 request.recipient = service
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1163 request.nodeIdentifier = nodeIdentifier
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1164
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1165 def cb(iq_elt):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1166 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1167 subscriptions_elt = next(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1168 iq_elt.pubsub.elements((pubsub.NS_PUBSUB, "subscriptions"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1169 )
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1170 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1171 raise ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1172 _(u"Invalid result: missing <subscriptions> element: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1173 iq_elt.toXml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1174 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1175 )
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1176 except AttributeError as e:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1177 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
1178 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1179 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1180 jid.JID(s["jid"]): s["subscription"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1181 for s in subscriptions_elt.elements(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1182 (pubsub.NS_PUBSUB, "subscription")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1183 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1184 }
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1185 except KeyError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1186 raise ValueError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1187 _(u"Invalid result: bad <subscription> element: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1188 iq_elt.toXml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1189 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1190 )
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1191
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1192 d = request.send(client.xmlstream)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1193 d.addCallback(cb)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1194 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1195
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1196 def _setNodeSubscriptions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1197 self, service_s, nodeIdentifier, subscriptions, profile_key=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1198 ):
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1199 client = self.host.getClient(profile_key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1200 subscriptions = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1201 jid.JID(jid_): subscription
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1202 for jid_, subscription in subscriptions.iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1203 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1204 d = self.setNodeSubscriptions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1205 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1206 jid.JID(service_s) if service_s else None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1207 nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1208 subscriptions,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1209 )
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1210 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1211
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1212 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
1213 """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
1214
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1215 @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
1216 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
1217 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1218 request = pubsub.PubSubRequest("subscriptionsSet")
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1219 request.recipient = service
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1220 request.nodeIdentifier = nodeIdentifier
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1221 request.subscriptions = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1222 pubsub.Subscription(nodeIdentifier, jid_, state)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1223 for jid_, state in subscriptions.iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1224 }
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1225 d = request.send(client.xmlstream)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1226 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
1227
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
1228 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
1229 """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
1230
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
1231 @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
1232 @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
1233 - 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
1234 - 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
1235 - 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
1236 - 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
1237 - 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
1238 @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
1239 """
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
1240 profile = self.host.getClient(profile_key).profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1241 d = self.rt_sessions.getResults(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1242 session_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1243 on_success=lambda result: "",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1244 on_error=lambda failure: unicode(failure.value),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1245 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1246 )
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
1247 # we need to convert jid.JID to unicode with full() to serialise it for the bridge
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1248 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1249 lambda ret: (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1250 ret[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1251 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1252 (service.full(), node, "" if success else failure or UNSPECIFIED)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1253 for (service, node), (success, failure) in ret[1].iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1254 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1255 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1256 )
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
1257 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
1258
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1259 def _subscribeToMany(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1260 self, node_data, subscriber=None, options=None, profile_key=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1261 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1262 return self.subscribeToMany(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1263 [(jid.JID(service), unicode(node)) for service, node in node_data],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1264 jid.JID(subscriber),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1265 options,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1266 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1267 )
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
1268
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1269 def subscribeToMany(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1270 self, node_data, subscriber, options=None, profile_key=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1271 ):
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
1272 """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
1273
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
1274 @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
1275 - 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
1276 - 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
1277 @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
1278 @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
1279 @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
1280 @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
1281 """
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
1282 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
1283 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
1284 for service, node in node_data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1285 deferreds[(service, node)] = client.pubsub_client.subscribe(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1286 service, node, subscriber, options=options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1287 )
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
1288 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
1289 # 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
1290 # 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
1291 # 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
1292 # 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
1293 # 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
1294 # 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
1295 # 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
1296 # 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
1297 # 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
1298
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1299 # get #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1300
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1301 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
1302 """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
1303
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1304 @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
1305 @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
1306 @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
1307 - 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
1308 - 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
1309 - service (unicode): pubsub service
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1310 - node (unicode): pubsub node
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1311 - 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
1312 - 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
1313 - metadata(dict): serialised metadata
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1314 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1315 profile = self.host.getClient(profile_key).profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1316 d = self.rt_sessions.getResults(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1317 session_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1318 on_success=lambda result: ("", self.serItemsData(result)),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1319 on_error=lambda failure: (unicode(failure.value) or UNSPECIFIED, ([], {})),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1320 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1321 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1322 d.addCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1323 lambda ret: (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1324 ret[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1325 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1326 (service.full(), node, failure, items, metadata)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1327 for (service, node), (success, (failure, (items, metadata))) in ret[
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1328 1
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1329 ].iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1330 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1331 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1332 )
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1333 return d
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1334
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1335 def _getFromMany(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1336 self, node_data, max_item=10, extra_dict=None, profile_key=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1337 ):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1338 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1339 @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
1340 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1341 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
1342 extra = self.parseExtra(extra_dict)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1343 return self.getFromMany(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1344 [(jid.JID(service), unicode(node)) for service, node in node_data],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1345 max_item,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1346 extra.rsm_request,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1347 extra.extra,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1348 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1349 )
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1350
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1351 def getFromMany(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1352 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1353 node_data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1354 max_item=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1355 rsm_request=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1356 extra=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1357 profile_key=C.PROF_KEY_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1358 ):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1359 """Get items from many nodes at once
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
1360
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1361 @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
1362 - 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
1363 - 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
1364 @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
1365 @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
1366 @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
1367 @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
1368 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1369 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
1370 deferreds = {}
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1371 for service, node in node_data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1372 deferreds[(service, node)] = self.getItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1373 client, service, node, max_item, rsm_request=rsm_request, extra=extra
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1374 )
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
1375 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
1376
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1377
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
1378 class SatPubSubClient(rsm.PubSubClient):
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1379 implements(disco.IDisco)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1380
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1381 def __init__(self, host, parent_plugin):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1382 self.host = host
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1383 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
1384 rsm.PubSubClient.__init__(self)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1385
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1386 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
1387 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
1388
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
1389 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
1390 """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
1391
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
1392 @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
1393 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
1394 @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
1395 @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
1396 """
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
1397 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
1398 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
1399 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
1400 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
1401 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
1402 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
1403 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
1404 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
1405
2760
3480d4fdf83a plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents: 2758
diff changeset
1406
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1407 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
1408 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
1409 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
1410 callback(self.parent, event)
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
1411 client = self.parent
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
1412 if (event.sender, event.nodeIdentifier) in client.pubsub_watching:
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
1413 raw_items = [i.toXml() for i in event.items]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1414 self.host.bridge.psEventRaw(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1415 event.sender.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1416 event.nodeIdentifier,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1417 C.PS_ITEMS,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1418 raw_items,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1419 client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1420 )
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1421
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1422 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
1423 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
1424 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
1425 callback(self.parent, event)
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
1426 client = self.parent
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
1427 if (event.sender, event.nodeIdentifier) in client.pubsub_watching:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1428 self.host.bridge.psEventRaw(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1429 event.sender.full(), event.nodeIdentifier, C.PS_DELETE, [], client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1430 )
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
1431
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1432 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
1433 """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
1434
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1435 @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
1436 @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
1437 @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
1438 @type nodeIdentifier: C{unicode}
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1439 @return (list[pubsub.Subscription]): list of subscriptions
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1440 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1441 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
1442 request.recipient = service
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1443 request.nodeIdentifier = nodeIdentifier
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1444 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
1445 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
1446
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
1447 def cb(iq):
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1448 subs = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1449 for subscription_elt in iq.pubsub.subscriptions.elements(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1450 pubsub.NS_PUBSUB, "subscription"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1451 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1452 subscription = pubsub.Subscription(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1453 subscription_elt["node"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1454 jid.JID(subscription_elt["jid"]),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1455 subscription_elt["subscription"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1456 subscriptionIdentifier=subscription_elt.getAttribute("subid"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1457 )
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1458 subs.append(subscription)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
1459 return subs
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
1460
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
1461 return d.addCallback(cb)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1462
2801
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1463 def purgeNode(self, service, nodeIdentifier):
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1464 """Purge a node (i.e. delete all items from it)
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1465
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1466 @param service(jid.JID, None): service to send the item to
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1467 None to use PEP
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1468 @param NodeIdentifier(unicode): PubSub node to use
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1469 """
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1470 # TODO: propose this upstream and remove it once merged
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1471 request = pubsub.PubSubRequest('purge')
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1472 request.recipient = service
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1473 request.nodeIdentifier = nodeIdentifier
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1474 return request.send(self.xmlstream)
ae127e14b040 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents: 2800
diff changeset
1475
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1476 def getDiscoInfo(self, requestor, service, nodeIdentifier=""):
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1477 disco_info = []
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1478 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
1479 return disco_info
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
1480
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1481 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
1482 return []