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