Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0060.py @ 2023:224c8b0886bc
plugin XEP-0184: Implementation of XEP-0184 (Message Delivery Receipts)
author | Geoffrey POUZET <chteufleur@kingpenguin.tk> |
---|---|
date | Thu, 28 Jul 2016 19:11:31 +0200 |
parents | 2daf7b4c6756 |
children | 1d3f73e065e1 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1904
diff
changeset
|
1 #!/usr/bin/env python2 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for Publish-Subscribe (xep-0060) |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 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 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
25 |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
26 from sat.tools import sat_defer |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
27 |
1678
c2d96f74105e
plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents:
1552
diff
changeset
|
28 from twisted.words.protocols.jabber import jid, error |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
29 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
|
30 from wokkel import disco |
1777 | 31 from wokkel import data_form |
32 from zope.interface import implements | |
33 from collections import namedtuple | |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
34 import urllib |
1777 | 35 import datetime |
36 from dateutil import tz | |
37 # XXX: tmp.wokkel.pubsub is actually use instead of wokkel version | |
38 # mam and rsm come from tmp.wokkel too | |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
39 from wokkel import pubsub |
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
40 from wokkel import rsm |
1777 | 41 from wokkel import mam |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
42 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
45 "name": "Publish-Subscribe", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
46 "import_name": "XEP-0060", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
48 "protocols": ["XEP-0060"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
49 "dependencies": [], |
1777 | 50 "recommendations": ["XEP-0313"], |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
51 "main": "XEP_0060", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
52 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
53 "description": _("""Implementation of PubSub Protocol""") |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 } |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
1777 | 56 UNSPECIFIED = "unspecified error" |
57 MAM_FILTER = "mam_filter_" | |
58 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
59 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
60 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
|
61 # 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
|
62 # 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
|
63 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
64 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 ACCESS_ROSTER = 'roster' |
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() |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
88 host.bridge.addMethod("psDeleteNode", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
89 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
|
90 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 def getHandler(self, profile): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
98 client = self.host.getClient(profile) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
99 client.pubsub_client = SatPubSubClient(self.host, self) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
100 return client.pubsub_client |
1282
74d558e6c9fd
plugin XEP-0060: free SatPubSubClient instance on profile disconnection
souliane <souliane@mailoo.org>
parents:
1268
diff
changeset
|
101 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
102 @defer.inlineCallbacks |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
103 def profileConnected(self, profile): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
104 client = self.host.getClient(profile) |
1552
e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
Goffi <goffi@goffi.org>
parents:
1512
diff
changeset
|
105 pubsub_services = yield self.host.findServiceEntities("pubsub", "service", profile=profile) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
106 if pubsub_services: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
107 # we use one of the found services as our default pubsub service |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
108 client.pubsub_service = pubsub_services.pop() |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
109 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
110 client.pubsub_service = None |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
111 |
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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 return {} |
0f0889028eea
plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents:
1459
diff
changeset
|
125 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
126 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
|
127 """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
|
128 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
129 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
|
130 @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
|
131 @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
|
132 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
133 if extra is not None: |
1777 | 134 # rsm |
135 rsm_args = {} | |
136 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
|
137 try: |
1777 | 138 argname = "max_" if arg == 'max' else arg |
139 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
|
140 except KeyError: |
1777 | 141 continue |
142 | |
143 if rsm_args: | |
144 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
|
145 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
146 rsm_request = None |
1777 | 147 |
148 # mam | |
149 mam_args = {} | |
150 for arg in ('start', 'end'): | |
151 try: | |
152 mam_args[arg] = datetime.datetime.fromtimestamp(int(extra.pop('{}{}'.format(MAM_FILTER, arg))), tz.tzutc()) | |
153 except (TypeError, ValueError): | |
154 log.warning(u"Bad value for {} filter".format(arg)) | |
155 except KeyError: | |
156 continue | |
157 | |
158 try: | |
159 mam_args['with_jid'] = jid.JID(extra.pop('{}jid'.format(MAM_FILTER))) | |
160 except (jid.InvalidFormat): | |
161 log.warning(u"Bad value for jid filter") | |
162 except KeyError: | |
163 pass | |
164 | |
1778
442303b62a16
plugin XEP-0060: fixed extra mam filters parsing
Goffi <goffi@goffi.org>
parents:
1777
diff
changeset
|
165 for name, value in extra.iteritems(): |
1777 | 166 if name.startswith(MAM_FILTER): |
1778
442303b62a16
plugin XEP-0060: fixed extra mam filters parsing
Goffi <goffi@goffi.org>
parents:
1777
diff
changeset
|
167 var = name[len(MAM_FILTER):] |
1777 | 168 extra_fields = mam_args.setdefault('extra_fields', []) |
169 extra_fields.append(data_form.Field(var=var, value=value)) | |
170 | |
171 if mam_args: | |
172 assert 'mam' not in extra | |
173 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
|
174 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
175 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
|
176 extra = {} |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
177 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
|
178 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
179 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
|
180 """Add a handler for a node |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
181 |
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
|
182 @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
|
183 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
|
184 @param **kwargs: method(s) to call when the node is found |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
185 the methode must be named after PubSub constants in lower case |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
186 and suffixed with "_cb" |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
187 e.g.: "publish_cb" for C.PS_PUBLISH, "delete_cb" for C.PS_DELETE |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
188 """ |
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
|
189 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
|
190 assert kwargs |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
197 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
|
198 """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
|
199 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
200 @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
|
201 @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
|
202 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
203 assert args |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
204 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
205 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
|
206 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
207 pass |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
208 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
209 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
|
210 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
|
211 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
212 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
|
213 except ValueError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
214 pass |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
215 else: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 return |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
223 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
|
224 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
225 # 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
|
226 # """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
|
227 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
228 # @param service (JID): target service |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
229 # @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
|
230 # @param profile (str): %(doc_profile)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
231 # @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
|
232 # """ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
233 # d = self.host.getDiscoItems(service, nodeIdentifier, profile_key=profile) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
234 # 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
|
235 # return d |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
236 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
237 # 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
|
238 # """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
|
239 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
240 # @param service (JID): target service |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
241 # @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
|
242 # @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
|
243 # - None: do not filter |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
244 # - '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
|
245 # - '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
|
246 # - 'subscribed': subscription is complete |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
247 # @param profile (str): %(doc_profile)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
248 # @return: Deferred list[str] |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
249 # """ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
250 # 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
|
251 # 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
|
252 # return d |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
253 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
254 def publish(self, service, nodeIdentifier, items=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
|
255 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
256 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
|
257 |
1777 | 258 def _unwrapMAMMessage(self, message_elt): |
259 try: | |
260 item_elt = (message_elt.elements(mam.NS_MAM, 'result').next() | |
261 .elements(C.NS_FORWARD, 'forwarded').next() | |
262 .elements(C.NS_CLIENT, 'message').next() | |
263 .elements('http://jabber.org/protocol/pubsub#event', 'event').next() | |
264 .elements('http://jabber.org/protocol/pubsub#event', 'items').next() | |
265 .elements('http://jabber.org/protocol/pubsub#event', 'item').next()) | |
266 except StopIteration: | |
267 raise exceptions.DataError(u"Can't find Item in MAM message element") | |
268 return item_elt | |
269 | |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
270 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
271 """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
|
272 |
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
|
273 @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
|
274 @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
|
275 @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
|
276 @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
|
277 @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
|
278 @param rsm_request (rsm.RSMRequest): RSM request data |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
279 @param profile_key (unicode): %(doc_profile_key)s |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
280 @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
|
281 - list of items |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
282 - metadata with the following keys: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
283 - 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
|
284 - 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
|
285 """ |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
286 if rsm_request and item_ids: |
1773
6e867caf4621
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
287 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
|
288 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
|
289 extra = {} |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
290 client = self.host.getClient(profile_key) |
1777 | 291 try: |
292 mam_query = extra['mam'] | |
293 except KeyError: | |
294 d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, None, rsm_request) | |
295 else: | |
296 # if mam is requested, we have to do a totally different query | |
297 if self._mam is None: | |
298 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available") | |
299 if max_items is not None: | |
300 raise exceptions.DataError(u"max_items parameter can't be used with MAM") | |
301 if item_ids: | |
302 raise exceptions.DataError(u"items_ids parameter can't be used with MAM") | |
303 if mam_query.node is None: | |
304 mam_query.node = node | |
305 elif mam_query.node != node: | |
306 raise exceptions.DataError(u"MAM query node is incoherent with getItems's node") | |
307 if mam_query.rsm is None: | |
308 mam_query.rsm = rsm_request | |
309 else: | |
310 if mam_query.rsm != rsm_request: | |
311 raise exceptions.DataError(u"Conflict between RSM request and MAM's RSM request") | |
312 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
|
313 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
314 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
315 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
|
316 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
317 subscribe = False |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
318 |
1678
c2d96f74105e
plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents:
1552
diff
changeset
|
319 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
|
320 failure.trap(error.StanzaError) |
1773
6e867caf4621
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
321 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
|
322 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
323 def doSubscribe(items): |
1678
c2d96f74105e
plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents:
1552
diff
changeset
|
324 self.subscribe(service, node, profile_key=profile_key).addErrback(subscribeEb, service, node) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
325 return items |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
326 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
327 if subscribe: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
328 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
|
329 |
1773
6e867caf4621
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
330 def addMetadata(result): |
6e867caf4621
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
331 items, rsm_response = result |
1904
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
332 service_jid = service if service else jid.JID(client.jid.host) |
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
333 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
|
334 'node': node, |
1904
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
335 '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
|
336 } |
1773
6e867caf4621
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
337 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
|
338 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
|
339 return (items, metadata) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
340 |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
341 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
|
342 return d |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
343 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
344 # @defer.inlineCallbacks |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
345 # 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
|
346 # """Massively retrieve pubsub items from many nodes. |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
347 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
348 # @param service (JID): target service. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
349 # @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
|
350 # @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
|
351 # @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
|
352 # @param rsm (dict): RSM request data |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
353 # @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
|
354 # @return: a deferred dict with: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
355 # - 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
|
356 # - couple (list[dict], dict) containing: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
357 # - list of items |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
358 # - RSM response data |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
359 # """ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
360 # client = self.host.getClient(profile_key) |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
361 # 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
|
362 # d_dict = {} |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
363 # for publisher, node in data.items(): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
364 # if node not in found_nodes: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
365 # 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
|
366 # 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
|
367 # 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
|
368 # 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
|
369 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
370 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
|
371 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
372 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
|
373 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
374 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
|
375 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
376 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
|
377 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
378 def createNode(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
379 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
380 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
|
381 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
382 def _deleteNode(self, service_s, nodeIdentifier, profile_key): |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
383 return self.deleteNode(jid.JID(service_s) if service_s else None, nodeIdentifier, profile_key) |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
384 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
385 def deleteNode(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
|
386 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
387 return client.pubsub_client.deleteNode(service, nodeIdentifier) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
388 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
389 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
|
390 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
|
391 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
392 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
|
393 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
|
394 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
891
diff
changeset
|
399 def subscribe(self, service, nodeIdentifier, sub_jid=None, options=None, profile_key=C.PROF_KEY_NONE): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
400 # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
401 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
402 return client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.pubsub_client.parent.jid.userhostJID(), options=options) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
403 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
404 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
|
405 client = self.host.getClient(profile_key) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
406 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
|
407 |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
408 ## misc tools ## |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
409 |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
410 def getNodeURI(self, service, node, item=None): |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
411 """Return XMPP URI of a PubSub node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
412 |
1904
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
413 @param service(jid.JID): PubSub service, |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
414 @param node(unicode): node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
415 @return (unicode): URI of the node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
416 """ |
1904
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
417 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
|
418 # 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
|
419 # 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
|
420 # urlencode MUST NOT BE USED. |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
421 query_data = [('node', node.encode('utf-8'))] |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
422 if item is not None: |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
423 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
|
424 return "xmpp:{service}?;{query}".format( |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
425 service=service.userhost(), |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
426 query=urllib.urlencode(query_data) |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
427 ).decode('utf-8') |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
428 |
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
|
429 ## 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
|
430 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
431 # generic # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
432 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
433 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
|
434 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
|
435 |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
436 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
|
437 """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
|
438 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 @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
|
443 @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
|
444 @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
|
445 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
446 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
|
447 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
|
448 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
449 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
|
450 """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
|
451 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
452 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
|
453 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
|
454 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
|
455 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
|
456 @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
|
457 @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
|
458 @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
|
459 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
469 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
|
470 """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
|
471 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
472 @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
|
473 @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
|
474 (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
|
475 @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
|
476 - 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
|
477 - result |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
478 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
479 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
|
480 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
|
481 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
|
482 |
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
|
483 # 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
|
484 |
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
|
485 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
|
486 """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
|
487 |
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
|
488 @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
|
489 @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
|
490 - 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
|
491 - 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
|
492 - 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
|
493 - 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
|
494 - 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
|
495 @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
|
496 """ |
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
|
497 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
|
498 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
|
499 # 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
|
500 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
|
501 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
|
502 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
|
503 |
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
|
504 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
|
505 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
|
506 |
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
|
507 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
|
508 """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
|
509 |
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
|
510 @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
|
511 - 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
|
512 - 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
|
513 @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
|
514 @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
|
515 @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
|
516 @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
|
517 """ |
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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 # 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
|
524 # 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
|
525 # 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
|
526 # 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
|
527 # 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
|
528 # 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
|
529 # 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
|
530 # 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
|
531 # 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
|
532 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
533 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
534 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
535 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
|
536 """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
|
537 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
538 @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
|
539 @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
|
540 @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
|
541 - 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
|
542 - 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
|
543 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
544 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
545 - 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
|
546 - 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
|
547 - metadata(dict): serialised metadata |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
548 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
549 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
|
550 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
|
551 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
|
552 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
|
553 profile=profile) |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
554 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
|
555 [(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
|
556 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
|
557 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
558 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
559 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
|
560 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
561 @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
|
562 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
563 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
|
564 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
|
565 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
|
566 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
567 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
|
568 """Get items from many nodes at once |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
569 @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
|
570 - 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
|
571 - 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
|
572 @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
|
573 @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
|
574 @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
|
575 @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
|
576 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
577 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
|
578 deferreds = {} |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
579 for service, node in node_data: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
580 deferreds[(service, node)] = self.getItems(service, node, max_item, rsm_request=rsm_request, extra=extra, profile_key=profile_key) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
581 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
|
582 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
583 |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
584 class SatPubSubClient(rsm.PubSubClient): |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
585 implements(disco.IDisco) |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
586 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
587 def __init__(self, host, parent_plugin): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
588 self.host = host |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
589 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
|
590 rsm.PubSubClient.__init__(self) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
591 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
592 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
|
593 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
|
594 |
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
|
595 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
|
596 """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
|
597 |
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
|
598 @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
|
599 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
|
600 @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
|
601 @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
|
602 """ |
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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
612 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
|
613 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
|
614 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS): |
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
|
615 callback(event, self.parent.profile) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
616 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
617 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
|
618 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
|
619 for callback in self._getNodeCallbacks(event.nodeIdentifier, 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
|
620 callback(event, self.parent.profile) |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
621 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
622 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
|
623 """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
|
624 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
625 @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
|
626 @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
|
627 @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
|
628 @type nodeIdentifier: C{unicode} |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
629 """ |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
630 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
|
631 request.recipient = service |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
632 request.nodeIdentifier = nodeIdentifier |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
633 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
|
634 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
|
635 |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
636 def cb(iq): |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
637 # FIXME: to be checked |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
638 return [sub for sub in iq.pubsub.subscriptions.elements() if |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
639 (sub.uri == pubsub.NS_PUBSUB and sub.name == 'subscription')] |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
640 |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
641 return d.addCallback(cb) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
642 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
643 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
|
644 disco_info = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
645 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
|
646 return disco_info |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
647 |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
648 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
|
649 return [] |