Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0060.py @ 4401:ae26233b655f default tip
doc (components): Add message cleaning section to email gateway doc:
fix 464
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 11 Sep 2025 21:17:51 +0200 |
parents | c2228563bf0f |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
3 # SàT plugin for Publish-Subscribe (xep-0060) |
3479 | 4 # Copyright (C) 2009-2021 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
|
5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
6 # 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
|
7 # 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
|
8 # 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
|
9 # (at your option) any later version. |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
11 # 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
|
12 # 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
|
13 # 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
|
14 # 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
|
15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
16 # 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
|
17 # 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
|
18 |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
19 |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
20 from collections import namedtuple |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
21 from functools import reduce |
4391
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
22 from typing import Any, Callable, ClassVar, Dict, Iterable, List, Optional, Self, Set, Union |
3815 | 23 import urllib.parse |
24 | |
4391
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
25 from pydantic import BaseModel, Field |
3815 | 26 from twisted.internet import defer, reactor |
27 from twisted.words.protocols.jabber import error, jid | |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
28 from twisted.words.xish import domish |
1449
389357fd79ce
plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents:
1446
diff
changeset
|
29 from wokkel import disco |
1777 | 30 from wokkel import data_form |
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
|
31 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
|
32 from wokkel import rsm |
1777 | 33 from wokkel import mam |
3815 | 34 from zope.interface import implementer |
35 | |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
36 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
37 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
38 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
39 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
40 from libervia.backend.core.log import getLogger |
4384
33468e175ade
backend: various fixes, and type hints improvments.
Goffi <goffi@goffi.org>
parents:
4356
diff
changeset
|
41 from libervia.backend.core.core_types import SatXMPPClient |
4391
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
42 from libervia.backend.models.types import JIDType |
4356
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
43 from libervia.backend.plugins.plugin_xep_0059 import RSMRequest |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
44 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
45 from libervia.backend.tools import sat_defer |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
46 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
47 from libervia.backend.tools.common import data_format |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
48 |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
49 |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
50 log = getLogger(__name__) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 PLUGIN_INFO = { |
3028 | 53 C.PI_NAME: "Publish-Subscribe", |
54 C.PI_IMPORT_NAME: "XEP-0060", | |
55 C.PI_TYPE: "XEP", | |
3726
33d75cd3c371
plugin XEP-0060, XEP-0163, XEP-0277, text syntaxes: make those plugins usable with components
Goffi <goffi@goffi.org>
parents:
3723
diff
changeset
|
56 C.PI_MODES: C.PLUG_MODE_BOTH, |
3028 | 57 C.PI_PROTOCOLS: ["XEP-0060"], |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
58 C.PI_DEPENDENCIES: [], |
3028 | 59 C.PI_RECOMMENDATIONS: ["XEP-0059", "XEP-0313"], |
60 C.PI_MAIN: "XEP_0060", | |
61 C.PI_HANDLER: "yes", | |
62 C.PI_DESCRIPTION: _("""Implementation of PubSub Protocol"""), | |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 } |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
1777 | 65 UNSPECIFIED = "unspecified error" |
66 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
67 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 Extra = namedtuple("Extra", ("rsm_request", "extra")) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
69 # 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
|
70 # extra is a potentially empty dict |
2769
9282b289b964
plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents:
2760
diff
changeset
|
71 TIMEOUT = 30 |
3756
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
72 # minimum features that a pubsub service must have to be selectable as default |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
73 DEFAULT_PUBSUB_MIN_FEAT = { |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
74 "http://jabber.org/protocol/pubsub#persistent-items", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
75 "http://jabber.org/protocol/pubsub#publish", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
76 "http://jabber.org/protocol/pubsub#retract-items", |
3756
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
77 } |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
78 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
79 |
4391
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
80 class NodeMetadata(BaseModel): |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
81 """Node metadata model.""" |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
82 model_config = { |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
83 "extra": "allow" |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
84 } |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
85 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
86 type: str | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
87 creator: JIDType | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
88 creation_date: float | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
89 title: str | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
90 description: str | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
91 language: str | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
92 contact: list[JIDType] | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
93 access_model: str | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
94 publish_model: str | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
95 max_items: int | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
96 owner: list[JIDType] | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
97 publisher: list[JIDType] | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
98 num_subscribers: int | None = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
99 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
100 _fields_defs: ClassVar[dict] = { |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
101 "pubsub#type": {"type": "text-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
102 "pubsub#creator": {"type": "jid-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
103 "pubsub#creation_date": {"type": "text-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
104 "pubsub#title": {"type": "text-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
105 "pubsub#description": {"type": "text-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
106 "pubsub#language": {"type": "list-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
107 "pubsub#contact": {"type": "jid-multi"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
108 "pubsub#access_model": {"type": "list-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
109 "pubsub#publish_model": {"type": "list-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
110 "pubsub#max_items": {"type": "text-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
111 "pubsub#owner": {"type": "jid-multi"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
112 "pubsub#publisher": {"type": "jid-multi"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
113 "pubsub#num_subscribers": {"type": "text-single"}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
114 } |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
115 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
116 @classmethod |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
117 def from_data_form(cls, form: data_form.Form) -> Self: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
118 """Create a NodeMetadata instance from a data form. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
119 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
120 @param form: Data form containing node metadata. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
121 @return: Filled instance of this class. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
122 @raise TypeError: Type of the form do not correspond to what is expected according |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
123 to specifications. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
124 """ |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
125 fields = {} |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
126 form.typeCheck(cls._fields_defs) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
127 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
128 for field in form.fields.values(): |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
129 if field.var == "pubsub#type": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
130 fields["type"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
131 elif field.var == "pubsub#creator": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
132 fields["creator"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
133 elif field.var == "pubsub#creation_date": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
134 fields["creation_date"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
135 elif field.var == "pubsub#title": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
136 fields["title"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
137 elif field.var == "pubsub#description": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
138 fields["description"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
139 elif field.var == "pubsub#language": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
140 fields["language"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
141 elif field.var == "pubsub#contact": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
142 fields["contact"] = field.values |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
143 elif field.var == "pubsub#access_model": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
144 fields["access_model"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
145 elif field.var == "pubsub#publish_model": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
146 fields["publish_model"] = field.value |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
147 elif field.var == "pubsub#max_items": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
148 if field.value == "max": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
149 fields["max_items"] = -1 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
150 else: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
151 try: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
152 fields["max_items"] = int(field.value) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
153 except (ValueError, TypeError): |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
154 log.warning(f"Invalid max_items found: {field.value!r}.") |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
155 fields["max_items"] = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
156 elif field.var == "pubsub#owner": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
157 fields["owner"] = field.values |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
158 elif field.var == "pubsub#publisher": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
159 fields["publisher"] = field.values |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
160 elif field.var == "pubsub#num_subscribers": |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
161 try: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
162 fields["num_subscribers"] = int(field.value) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
163 except (ValueError, TypeError): |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
164 log.warning(f"Invalid num_subscribers found: {field.value!r}.") |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
165 fields["num_subscribers"] = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
166 elif field.var is None: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
167 continue |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
168 else: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
169 # We use debug and not warning here because fields can be handled by |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
170 # subclasses. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
171 log.debug(f"Ignored field: {field.var!r} (values: {field.values!r}).") |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
172 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
173 return cls(**fields) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
174 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
175 def to_data_form(self) -> data_form.Form: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
176 """Convert this instance to a data form. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
177 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
178 @return: Data form representation of this instance. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
179 """ |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
180 form = data_form.Form(formType="result", formNamespace=pubsub.NS_PUBSUB_META_DATA) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
181 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
182 # Handle max_items conversion from -1 to "max" for the spec. |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
183 if self.max_items is not None: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
184 max_items_value = "max" if self.max_items == -1 else str(self.max_items) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
185 else: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
186 max_items_value = None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
187 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
188 fields_map = { |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
189 "pubsub#type": self.type, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
190 "pubsub#creator": self.creator, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
191 "pubsub#creation_date": self.creation_date, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
192 "pubsub#title": self.title, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
193 "pubsub#description": self.description, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
194 "pubsub#language": self.language, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
195 "pubsub#contact": self.contact, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
196 "pubsub#access_model": self.access_model, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
197 "pubsub#publish_model": self.publish_model, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
198 "pubsub#max_items": max_items_value, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
199 "pubsub#owner": self.owner, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
200 "pubsub#publisher": self.publisher, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
201 "pubsub#num_subscribers": ( |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
202 str(self.num_subscribers) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
203 if self.num_subscribers is not None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
204 else None |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
205 ), |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
206 } |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
207 form.makeFields( |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
208 {k: v for k, v in fields_map.items() if v}, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
209 fieldDefs=self._fields_defs, |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
210 ) |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
211 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
212 return form |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
213 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
214 def to_element(self) -> domish.Element: |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
215 """Generate the <x> element corresponding to this form.""" |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
216 return self.to_data_form().toElement() |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
217 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
218 |
c2228563bf0f
plugin XEP-0060: Add a model to handle node metadata:
Goffi <goffi@goffi.org>
parents:
4384
diff
changeset
|
219 class XEP_0060: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 OPT_ACCESS_MODEL = "pubsub#access_model" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 OPT_PERSIST_ITEMS = "pubsub#persist_items" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 OPT_MAX_ITEMS = "pubsub#max_items" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
223 OPT_DELIVER_PAYLOADS = "pubsub#deliver_payloads" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 OPT_SEND_ITEM_SUBSCRIBE = "pubsub#send_item_subscribe" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 OPT_NODE_TYPE = "pubsub#node_type" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 OPT_SUBSCRIPTION_TYPE = "pubsub#subscription_type" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 OPT_SUBSCRIPTION_DEPTH = "pubsub#subscription_depth" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 OPT_ROSTER_GROUPS_ALLOWED = "pubsub#roster_groups_allowed" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 OPT_PUBLISH_MODEL = "pubsub#publish_model" |
3468
36cac8e6f57d
plugin XEP-0060: added constants for overwrite policy configuration option
Goffi <goffi@goffi.org>
parents:
3467
diff
changeset
|
230 OPT_OVERWRITE_POLICY = "pubsub#overwrite_policy" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 ACCESS_OPEN = "open" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 ACCESS_PRESENCE = "presence" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 ACCESS_ROSTER = "roster" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 ACCESS_PUBLISHER_ROSTER = "publisher-roster" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 ACCESS_AUTHORIZE = "authorize" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 ACCESS_WHITELIST = "whitelist" |
3451
f37e6e78db12
plugin XEP-0060: add constants for common values of publish model
Goffi <goffi@goffi.org>
parents:
3394
diff
changeset
|
237 PUBLISH_MODEL_PUBLISHERS = "publishers" |
f37e6e78db12
plugin XEP-0060: add constants for common values of publish model
Goffi <goffi@goffi.org>
parents:
3394
diff
changeset
|
238 PUBLISH_MODEL_SUBSCRIBERS = "subscribers" |
f37e6e78db12
plugin XEP-0060: add constants for common values of publish model
Goffi <goffi@goffi.org>
parents:
3394
diff
changeset
|
239 PUBLISH_MODEL_OPEN = "open" |
3468
36cac8e6f57d
plugin XEP-0060: added constants for overwrite policy configuration option
Goffi <goffi@goffi.org>
parents:
3467
diff
changeset
|
240 OWPOL_ORIGINAL = "original_publisher" |
36cac8e6f57d
plugin XEP-0060: added constants for overwrite policy configuration option
Goffi <goffi@goffi.org>
parents:
3467
diff
changeset
|
241 OWPOL_ANY_PUB = "any_publisher" |
2647
1bf7e89fded0
plugin XEP-0060: added singleton ID ("current")
Goffi <goffi@goffi.org>
parents:
2643
diff
changeset
|
242 ID_SINGLETON = "current" |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
243 EXTRA_PUBLISH_OPTIONS = "publish_options" |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
244 EXTRA_ON_PRECOND_NOT_MET = "on_precondition_not_met" |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
245 EXTRA_AUTOCREATE = "autocreate" |
3597
5d108ce026d7
plugin pubsub cache: Pubsub Caching implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
246 # extra disco needed for RSM, cf. XEP-0060 § 6.5.4 |
5d108ce026d7
plugin pubsub cache: Pubsub Caching implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
247 DISCO_RSM = "http://jabber.org/protocol/pubsub#rsm" |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 def __init__(self, host): |
3028 | 250 log.info(_("PubSub plugin initialization")) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 self.host = host |
3028 | 252 self._rsm = host.plugins.get("XEP-0059") |
253 self._mam = host.plugins.get("XEP-0313") | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
254 self._node_cb = ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
255 {} |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
256 ) # 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
|
257 self.rt_sessions = sat_defer.RTDeferredSessions() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
258 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
259 "ps_node_create", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
263 method=self._create_node, |
3028 | 264 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
266 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
267 "ps_node_configuration_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 out_sign="a{ss}", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
271 method=self._get_node_configuration, |
3028 | 272 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
274 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
275 "ps_node_configuration_set", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
279 method=self._set_node_configuration, |
3028 | 280 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
282 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
283 "ps_node_affiliations_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
285 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
286 out_sign="a{ss}", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
287 method=self._get_node_affiliations, |
3028 | 288 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
289 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
290 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
291 "ps_node_affiliations_set", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
295 method=self._set_node_affiliations, |
3028 | 296 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
297 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
298 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
299 "ps_node_subscriptions_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
300 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
302 out_sign="a{ss}", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
303 method=self._get_node_subscriptions, |
3028 | 304 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
305 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
306 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
307 "ps_node_subscriptions_set", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
308 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
311 method=self._set_node_subscriptions, |
3028 | 312 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
313 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
314 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
315 "ps_node_purge", |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
316 ".plugin", |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
317 in_sign="sss", |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
318 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
319 method=self._purge_node, |
3028 | 320 async_=True, |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
321 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
322 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
323 "ps_node_delete", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
324 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
325 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
327 method=self._delete_node, |
3028 | 328 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
330 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
331 "ps_node_watch_add", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
333 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
334 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
335 method=self._addWatch, |
3028 | 336 async_=False, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
338 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
339 "ps_node_watch_remove", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
342 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
343 method=self._remove_watch, |
3028 | 344 async_=False, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
345 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
346 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
347 "ps_affiliations_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
348 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
349 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
350 out_sign="a{ss}", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
351 method=self._get_affiliations, |
3028 | 352 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
353 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
354 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
355 "ps_items_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
356 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
357 in_sign="ssiassss", |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
358 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
359 method=self._get_items, |
3028 | 360 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
361 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
362 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
363 "ps_item_send", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
364 ".plugin", |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
365 in_sign="ssssss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
366 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
367 method=self._send_item, |
3028 | 368 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
370 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
371 "ps_items_send", |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
372 ".plugin", |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
373 in_sign="ssasss", |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
374 out_sign="as", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
375 method=self._send_items, |
3028 | 376 async_=True, |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
377 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
378 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
379 "ps_item_retract", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
380 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
381 in_sign="sssbs", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
382 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
383 method=self._retract_item, |
3028 | 384 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
385 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
386 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
387 "ps_items_retract", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 in_sign="ssasbs", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
390 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
391 method=self._retract_items, |
3028 | 392 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
393 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
394 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
395 "ps_item_rename", |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
396 ".plugin", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
397 in_sign="sssss", |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
398 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
399 method=self._rename_item, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
400 async_=True, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
401 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
402 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
403 "ps_subscribe", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
404 ".plugin", |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
405 in_sign="ssss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
406 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
407 method=self._subscribe, |
3028 | 408 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
410 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
411 "ps_unsubscribe", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 method=self._unsubscribe, |
3028 | 416 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
417 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
418 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
419 "ps_subscriptions_get", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
420 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
421 in_sign="sss", |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
422 out_sign="s", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
423 method=self._subscriptions, |
3028 | 424 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
426 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
427 "ps_subscribe_to_many", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 in_sign="a(ss)sa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
431 method=self._subscribe_to_many, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
433 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
434 "ps_get_subscribe_rt_result", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
437 out_sign="(ua(sss))", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
438 method=self._many_subscribe_rt_result, |
3028 | 439 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
441 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
442 "ps_get_from_many", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
443 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
444 in_sign="a(ss)iss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
445 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
446 method=self._get_from_many, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
447 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
448 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
449 "ps_get_from_many_rt_result", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
451 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
452 out_sign="(ua(sssasa{ss}))", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
453 method=self._get_from_many_rt_result, |
3028 | 454 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
455 ) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
456 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
457 # high level observer method |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
458 host.bridge.add_signal( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
459 "ps_event", ".plugin", signature="ssssss" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
460 ) # 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
|
461 |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
462 # low level observer method, used if service/node is in watching list (see psNodeWatch* methods) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
463 host.bridge.add_signal( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
464 "ps_event_raw", ".plugin", signature="sssass" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
465 ) # args: service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), list of item_xml, profile |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
466 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
467 def get_handler(self, client): |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
468 client.pubsub_client = SatPubSubClient(self.host, self) |
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
469 return client.pubsub_client |
1282
74d558e6c9fd
plugin XEP-0060: free SatPubSubClient instance on profile disconnection
souliane <souliane@mailoo.org>
parents:
1268
diff
changeset
|
470 |
4096
087902fbb77a
plugin XEP-0060: move setting of `pubsub_watching` to `profile_connecting` so it's available early
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
471 def profile_connecting(self, client): |
087902fbb77a
plugin XEP-0060: move setting of `pubsub_watching` to `profile_connecting` so it's available early
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
472 client.pubsub_watching = set() |
087902fbb77a
plugin XEP-0060: move setting of `pubsub_watching` to `profile_connecting` so it's available early
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
473 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
474 async def profile_connected(self, client): |
2459
a9c092bf4ee9
plugin XEP-0060: added an config option to set pubsub service
Goffi <goffi@goffi.org>
parents:
2444
diff
changeset
|
475 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
476 client.pubsub_service = jid.JID( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
477 self.host.memory.config_get("", "pubsub_service") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
478 ) |
2459
a9c092bf4ee9
plugin XEP-0060: added an config option to set pubsub service
Goffi <goffi@goffi.org>
parents:
2444
diff
changeset
|
479 except RuntimeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
480 log.info( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
481 _( |
3756
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
482 "Can't retrieve pubsub_service from conf, we'll use first one that " |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
483 "we find" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
484 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
485 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
486 pubsub_services = await self.host.find_service_entities( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
487 client, "pubsub", "service" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
488 ) |
3756
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
489 for service_jid in pubsub_services: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
490 infos = await self.host.memory.disco.get_infos(client, service_jid) |
3756
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
491 if not DEFAULT_PUBSUB_MIN_FEAT.issubset(infos.features): |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
492 continue |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
493 names = {(n or "").lower() for n in infos.identities.values()} |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
494 if "libervia pubsub service" in names: |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
495 # this is the name of Libervia's side project pubsub service, we know |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
496 # that it is a suitable default pubsub service |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
497 client.pubsub_service = service_jid |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
498 break |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
499 categories = {(i[0] or "").lower() for i in infos.identities.keys()} |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
500 if "gateway" in categories or "gateway" in names: |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
501 # we don't want to use a gateway as default pubsub service |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
502 continue |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
503 if "jabber:iq:register" in infos.features: |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
504 # may be present on gateways, and we don't want a service |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
505 # where registration is needed |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
506 continue |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
507 client.pubsub_service = service_jid |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
508 break |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
509 else: |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
510 client.pubsub_service = None |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
511 pubsub_service_str = ( |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
512 client.pubsub_service.full() if client.pubsub_service else "PEP" |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
513 ) |
aa923e6b369f
plugin XEP-0060: better filtering when looking for default pubsub service
Goffi <goffi@goffi.org>
parents:
3737
diff
changeset
|
514 log.info(f"default pubsub service: {pubsub_service_str}") |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
515 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
516 def features_get(self, profile): |
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
|
517 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
518 client = self.host.get_client(profile) |
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
|
519 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
|
520 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
|
521 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
522 return { |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
523 "service": ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
524 client.pubsub_service.full() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
525 if client.pubsub_service is not None |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
526 else "" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
527 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
528 } |
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
|
529 except AttributeError: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
530 if self.host.is_connected(profile): |
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
|
531 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
|
532 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
|
533 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
|
534 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
|
535 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
536 def parse_extra(self, extra): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
537 """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
|
538 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
539 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
|
540 @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
|
541 @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
|
542 """ |
2484 | 543 if extra is None: |
544 rsm_request = None | |
545 extra = {} | |
546 else: | |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
547 # order-by |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
548 if C.KEY_ORDER_BY in extra: |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
549 # FIXME: we temporarily manage only one level of ordering |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
550 # we need to switch to a fully serialised extra data |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
551 # to be able to encode a whole ordered list |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
552 extra[C.KEY_ORDER_BY] = [extra.pop(C.KEY_ORDER_BY)] |
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
553 |
1777 | 554 # rsm |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
555 if self._rsm is None: |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
556 rsm_request = None |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
557 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
558 rsm_request = self._rsm.parse_extra(extra) |
1777 | 559 |
560 # mam | |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
561 if self._mam is None: |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
562 mam_request = None |
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
563 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
564 mam_request = self._mam.parse_extra(extra, with_rsm=False) |
1777 | 565 |
2702
6555e9835ff8
plugin XEP-0060: use new parseExtra methods from MAM and RSM
Goffi <goffi@goffi.org>
parents:
2647
diff
changeset
|
566 if mam_request is not None: |
3028 | 567 assert "mam" not in extra |
568 extra["mam"] = mam_request | |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
569 |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
570 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
|
571 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
572 def add_managed_node(self, node: str, priority: int = 0, **kwargs: Callable): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
573 """Add a handler for a node |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
574 |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
575 @param node: node to monitor |
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
|
576 all node *prefixed* with this one will be triggered |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
577 @param priority: priority of the callback. Callbacks with higher priority will be |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
578 called first. |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
579 @param **kwargs: method(s) to call when the node is found |
2305
972e33507609
plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
580 the method must be named after PubSub constants in lower case |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
581 and suffixed with "_cb" |
2305
972e33507609
plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents:
2272
diff
changeset
|
582 e.g.: "items_cb" for C.PS_ITEMS, "delete_cb" for C.PS_DELETE |
3597
5d108ce026d7
plugin pubsub cache: Pubsub Caching implementation
Goffi <goffi@goffi.org>
parents:
3591
diff
changeset
|
583 note: only C.PS_ITEMS and C.PS_DELETE are implemented so far |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
584 """ |
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
|
585 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
|
586 assert kwargs |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
587 callbacks = self._node_cb.setdefault(node, {}) |
3028 | 588 for event, cb in kwargs.items(): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
589 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
|
590 assert event_name in C.PS_EVENTS |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
591 cb_list = callbacks.setdefault(event_name, []) |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
592 cb_list.append((cb, priority)) |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
593 cb_list.sort(key=lambda c: c[1], reverse=True) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
594 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
595 def remove_managed_node(self, node, *args): |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
596 """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
|
597 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
598 @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
|
599 @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
|
600 """ |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
601 assert args |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
602 try: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
603 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
|
604 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
605 pass |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
606 else: |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
607 removed = False |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
608 for callback in args: |
3028 | 609 for event, cb_list in registred_cb.items(): |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
610 to_remove = [] |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
611 for cb in cb_list: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
612 if cb[0] == callback: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
613 to_remove.append(cb) |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
614 for cb in to_remove: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
615 cb_list.remove(cb) |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
616 if not cb_list: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
617 del registred_cb[event] |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
618 if not registred_cb: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
619 del self._node_cb[node] |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
620 removed = True |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
621 break |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
622 |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
623 if not removed: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
624 log.error( |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
625 f"Trying to remove inexistant callback {callback} for node {node}" |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
626 ) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
627 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
628 # 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
|
629 # """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
|
630 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
631 # @param service (JID): target service |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
632 # @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
|
633 # @param profile (str): %(doc_profile)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
634 # @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
|
635 # """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
636 # client = self.host.get_client(profile) |
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
637 # d = self.host.getDiscoItems(client, service, nodeIdentifier) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
638 # 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
|
639 # return d |
1242
f584fbda4773
plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents:
1219
diff
changeset
|
640 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
641 # 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
|
642 # """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
|
643 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
644 # @param service (JID): target service |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
645 # @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
|
646 # @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
|
647 # - None: do not filter |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
648 # - '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
|
649 # - '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
|
650 # - 'subscribed': subscription is complete |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
651 # @param profile (str): %(doc_profile)s |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
652 # @return: Deferred list[str] |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
653 # """ |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
654 # 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
|
655 # 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
|
656 # return d |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
657 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
658 def _send_item( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
659 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
660 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
661 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
662 payload, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
663 item_id=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
664 extra_ser="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
665 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
666 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
667 client = self.host.get_client(profile_key) |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
668 service = None if not service else jid.JID(service) |
3394
23af257ae780
plugin XEP-0060: use `xml_tools.parse` instead of `wokkel.generic.parseXml`:
Goffi <goffi@goffi.org>
parents:
3312
diff
changeset
|
669 payload = xml_tools.parse(payload) |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
670 extra = data_format.deserialise(extra_ser) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
671 d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
672 self.send_item( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
673 client, service, nodeIdentifier, payload, item_id or None, extra |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
674 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
675 ) |
3028 | 676 d.addCallback(lambda ret: ret or "") |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
677 return d |
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
678 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
679 def _send_items( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
680 self, service, nodeIdentifier, items, extra_ser=None, profile_key=C.PROF_KEY_NONE |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
681 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
682 client = self.host.get_client(profile_key) |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
683 service = None if not service else jid.JID(service) |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
684 try: |
3394
23af257ae780
plugin XEP-0060: use `xml_tools.parse` instead of `wokkel.generic.parseXml`:
Goffi <goffi@goffi.org>
parents:
3312
diff
changeset
|
685 items = [xml_tools.parse(item) for item in items] |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
686 except Exception as e: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
687 raise exceptions.DataError(_("Can't parse items: {msg}").format(msg=e)) |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
688 extra = data_format.deserialise(extra_ser) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
689 return defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
690 self.send_items(client, service, nodeIdentifier, items, extra=extra) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
691 ) |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
692 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
693 async def send_item( |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
694 self, |
4384
33468e175ade
backend: various fixes, and type hints improvments.
Goffi <goffi@goffi.org>
parents:
4356
diff
changeset
|
695 client: SatXMPPEntity, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
696 service: Union[jid.JID, None], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
697 nodeIdentifier: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
698 payload: domish.Element, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
699 item_id: Optional[str] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
700 extra: Optional[Dict[str, Any]] = None, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
701 ) -> Optional[str]: |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
702 """High level method to send one item |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
703 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
704 @param service: service to send the item to None to use PEP |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
705 @param NodeIdentifier: PubSub node to use |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
706 @param payload: payload of the item to send |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
707 @param item_id: id to use or None to create one |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
708 @param extra: extra options |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
709 @return: id of the created item |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
710 """ |
3272
4c98f4972db5
plugin XEP-0060: fixed payload parsing in sendItem
Goffi <goffi@goffi.org>
parents:
3213
diff
changeset
|
711 assert isinstance(payload, domish.Element) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
712 item_elt = domish.Element((pubsub.NS_PUBSUB, "item")) |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
713 if item_id is not None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
714 item_elt["id"] = item_id |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
715 item_elt.addChild(payload) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
716 published_ids = await self.send_items( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
717 client, service, nodeIdentifier, [item_elt], extra=extra |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
718 ) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
719 try: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
720 return published_ids[0] |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
721 except IndexError: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
722 return item_id |
2272
b5befe7722d3
plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents:
2226
diff
changeset
|
723 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
724 async def send_items( |
3815 | 725 self, |
726 client: SatXMPPEntity, | |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
727 service: Optional[jid.JID], |
3815 | 728 nodeIdentifier: str, |
729 items: List[domish.Element], | |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
730 sender: Optional[jid.JID] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
731 extra: Optional[Dict[str, Any]] = None, |
3815 | 732 ) -> List[str]: |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
733 """High level method to send several items at once |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
734 |
3815 | 735 @param service: service to send the item to |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
736 None to use PEP |
3815 | 737 @param NodeIdentifier: PubSub node to use |
738 @param items: whole item elements to send, | |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
739 "id" will be used if set |
3815 | 740 @param extra: extra options. Key can be: |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
741 - self.EXTRA_PUBLISH_OPTIONS(dict): publish options, cf. XEP-0060 § 7.1.5 |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
742 the dict maps option name to value(s) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
743 - self.EXTRA_ON_PRECOND_NOT_MET(str): policy to have when publishing is |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
744 failing du to failing precondition. Value can be: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
745 * raise (default): raise the exception |
4283
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
746 * force: try to re-configure the node with the given option. Be sure to |
4284 | 747 use this option carefully, and not give public access to a node |
4283
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
748 which has not on purpose. |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
749 * publish_without_options: re-publish without the publish-options. |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
750 A warning will be logged showing that the publish-options could not |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
751 be used |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
752 - self.EXTRA_AUTOCREATE(bool): Create the node if it's not found, and the |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
753 service doesn't do autocreate itself. |
3815 | 754 @return: ids of the created items |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
755 """ |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
756 if extra is None: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3069
diff
changeset
|
757 extra = {} |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
758 if service is None: |
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
759 service = client.jid.userhostJID() |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
760 parsed_items = [] |
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
761 for item in items: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
762 if item.name != "item": |
3028 | 763 raise exceptions.DataError(_("Invalid item: {xml}").format(item.toXml())) |
764 item_id = item.getAttribute("id") | |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
765 parsed_items.append(pubsub.Item(id=item_id, payload=item.firstChildElement())) |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
766 publish_options = extra.get(self.EXTRA_PUBLISH_OPTIONS) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
767 try: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
768 iq_result = await self.publish( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
769 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
770 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
771 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
772 parsed_items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
773 options=publish_options, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
774 sender=sender, |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
775 ) |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
776 except error.StanzaError as e: |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
777 if e.condition == "item-not-found": |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
778 if extra.get(self.EXTRA_AUTOCREATE, False): |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
779 # Autocreate is requested, we create the requested node. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
780 await self.createNode( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
781 client, service, nodeIdentifier, publish_options |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
782 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
783 # And we try again. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
784 iq_result = await self.publish( |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
785 client, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
786 service, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
787 nodeIdentifier, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
788 parsed_items, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
789 options=publish_options, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
790 sender=sender, |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
791 ) |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
792 else: |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
793 raise e |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
794 |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
795 elif ( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
796 e.condition == "conflict" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
797 and e.appCondition |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
798 and e.appCondition.name == "precondition-not-met" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
799 and publish_options is not None |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
800 ): |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
801 # this usually happens when publish-options can't be set |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
802 policy = extra.get(self.EXTRA_ON_PRECOND_NOT_MET, "raise") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
803 if policy == "raise": |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
804 raise e |
4283
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
805 elif policy == "force": |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
806 log.debug( |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
807 f"[{client.profile}] Force configuration for {nodeIdentifier!r} " |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
808 f"at {service}: {publish_options}" |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
809 ) |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
810 await self.setConfiguration( |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
811 client, service, nodeIdentifier, publish_options |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
812 ) |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
813 log.debug("Configuration updated.") |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
814 return await self.send_items( |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
815 client, service, nodeIdentifier, items, sender, extra |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
816 ) |
23842a63ea00
plugin XEP-0060: add a `force` options for publish options in `send_items`:
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
817 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
818 elif policy == "publish_without_options": |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
819 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
820 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
821 "Can't use publish-options ({options}) on node {node}, " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
822 "re-publishing without them: {reason}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
823 ).format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
824 options=", ".join( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
825 f"{k} = {v}" for k, v in publish_options.items() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
826 ), |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
827 node=nodeIdentifier, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
828 reason=e, |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
829 ) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
830 ) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
831 iq_result = await self.publish( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
832 client, service, nodeIdentifier, parsed_items |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
833 ) |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
834 else: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
835 raise exceptions.InternalError( |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
836 f"Invalid policy in extra's {self.EXTRA_ON_PRECOND_NOT_MET!r}: " |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
837 f"{policy}" |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
838 ) |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
839 else: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
840 raise e |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
841 try: |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
842 return [ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
843 item["id"] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
844 for item in iq_result.pubsub.publish.elements(pubsub.NS_PUBSUB, "item") |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
845 ] |
3213
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
846 except AttributeError: |
c2f958dde5d2
plugin XEP-0060: async sendItems + precondition-not-met policy:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
847 return [] |
2800
3b68293a60d4
plugin XEP-0060: added sendItems/psItemsSend method to publish several items at once
Goffi <goffi@goffi.org>
parents:
2776
diff
changeset
|
848 |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
849 async def publish( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
850 self, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
851 client: SatXMPPEntity, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
852 service: jid.JID, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
853 nodeIdentifier: str, |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
854 items: list[pubsub.Item] | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
855 options: dict | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
856 sender: jid.JID | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
857 extra: dict[str, Any] | None = None, |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
858 ) -> domish.Element: |
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
859 """Publish pubsub items |
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
860 |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
861 @param sender: sender of the request, |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
862 client.jid will be used if not set |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
863 @param extra: extra data |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
864 not used directly by ``publish``, but may be used in triggers |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
865 @return: IQ result stanza |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
866 @trigger XEP-0060_publish: called just before publication. |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
867 if it returns False, extra must have a "iq_result_elt" key set with |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
868 domish.Element to return. |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
869 """ |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
870 if sender is None: |
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
871 sender = client.jid |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
872 if extra is None: |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
873 extra = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
874 if not await self.host.trigger.async_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
875 "XEP-0060_publish", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
876 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
877 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
878 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
879 items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
880 options, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
881 sender, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
882 extra, |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
883 ): |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
884 return extra["iq_result_elt"] |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
885 iq_result_elt = await client.pubsub_client.publish( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
886 service, nodeIdentifier, items, sender, options=options |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
887 ) |
3854
8a2c46122a11
plugin XEP-0060: fix bad naming of return variable
Goffi <goffi@goffi.org>
parents:
3849
diff
changeset
|
888 return iq_result_elt |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
889 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
890 def _unwrap_mam_message(self, message_elt): |
1777 | 891 try: |
3062
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
892 item_elt = reduce( |
93e8793a735a
plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
893 lambda elt, ns_name: next(elt.elements(*ns_name)), |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
894 ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
895 message_elt, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
896 (mam.NS_MAM, "result"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
897 (C.NS_FORWARD, "forwarded"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
898 (C.NS_CLIENT, "message"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
899 ("http://jabber.org/protocol/pubsub#event", "event"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
900 ("http://jabber.org/protocol/pubsub#event", "items"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
901 ("http://jabber.org/protocol/pubsub#event", "item"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
902 ), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
903 ) |
1777 | 904 except StopIteration: |
3028 | 905 raise exceptions.DataError("Can't find Item in MAM message element") |
1777 | 906 return item_elt |
907 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
908 def serialise_items(self, items_data): |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
909 items, metadata = items_data |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
910 metadata["items"] = items |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
911 return data_format.serialise(metadata) |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3308
diff
changeset
|
912 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
913 def _get_items( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
914 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
915 service="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
916 node="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
917 max_items=10, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
918 item_ids=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
919 sub_id=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
920 extra="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
921 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
922 ): |
2185
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
923 """Get items from pubsub node |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
924 |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
925 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
926 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
927 client = self.host.get_client(profile_key) |
2185
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
928 service = jid.JID(service) if service else None |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
929 max_items = None if max_items == C.NO_LIMIT else max_items |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
930 extra = self.parse_extra(data_format.deserialise(extra)) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
931 d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
932 self.get_items( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
933 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
934 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
935 node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
936 max_items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
937 item_ids, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
938 sub_id or None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
939 extra.rsm_request, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
940 extra.extra, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
941 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
942 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
943 d.addCallback(self.trans_items_data) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
944 d.addCallback(self.serialise_items) |
2185
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
945 return d |
dd53d7a3219a
plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents:
2148
diff
changeset
|
946 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
947 async def get_items( |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
948 self, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
949 client: SatXMPPEntity, |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
950 service: jid.JID | None, |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
951 node: str, |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
952 max_items: int | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
953 item_ids: list[str] | None = None, |
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
954 sub_id: str | None = None, |
4356
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
955 rsm_request: rsm.RSMRequest | RSMRequest | None = None, |
4334
111dce64dcb5
plugins XEP-0300, XEP-0446, XEP-0447, XEP0448 and others: Refactoring to use Pydantic:
Goffi <goffi@goffi.org>
parents:
4327
diff
changeset
|
956 extra: dict | None = None, |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
957 ) -> tuple[list[domish.Element], dict]: |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
958 """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
|
959 |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
960 @param service: pubsub service. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
961 @param node: node id. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
962 @param max_items: optional limit on the number of retrieved items. |
2758
f4070693814a
plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents:
2718
diff
changeset
|
963 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be |
3860
e417c478b488
plugin XEP-0060, tools (utils): doc/type hints
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
964 used with rsm_request). If requested items don't exist, they won't be |
e417c478b488
plugin XEP-0060, tools (utils): doc/type hints
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
965 returned, meaning that we can have an empty list as result (NotFound |
e417c478b488
plugin XEP-0060, tools (utils): doc/type hints
Goffi <goffi@goffi.org>
parents:
3859
diff
changeset
|
966 exception is NOT raised). |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
967 @param sub_id : optional subscription identifier. |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
968 @param rsm_request: RSM request data |
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
969 @return: a deferred tuple containing: |
1268
bb30bf3ae932
plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
1267
diff
changeset
|
970 - list of items |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
971 - metadata with the following keys: |
2718
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2702
diff
changeset
|
972 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index |
bb6adaa580ee
plugin XEP-0313, XEP-0045: loop MAM requests until whole archive is retrieved:
Goffi <goffi@goffi.org>
parents:
2702
diff
changeset
|
973 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
|
974 - 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
|
975 """ |
4356
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
976 if rsm_request is not None: |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
977 # For the moment we convert RSMRequest to wokkel rsm.RSMRequest for backward |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
978 # compatibility with other plugins. In the future we should work as much as |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
979 # possible with XEP-0059's plugin RSMRequest, and convert to Wokkel |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
980 # rsm.RSMRequest only when we need to work with wokkel directly. |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
981 if isinstance(rsm_request, rsm.RSMRequest): |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
982 log.warning("Use for rsm.RSMRequest is deprecated") |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
983 else: |
c9626f46b63e
plugin XEP-0059: Use Pydantic models for RSM.
Goffi <goffi@goffi.org>
parents:
4341
diff
changeset
|
984 rsm_request = rsm_request.to_wokkel_request() |
2319
e715a29c4f9b
plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents:
2314
diff
changeset
|
985 if item_ids and max_items is not None: |
e715a29c4f9b
plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents:
2314
diff
changeset
|
986 max_items = None |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
987 if rsm_request and item_ids: |
3028 | 988 raise ValueError("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
|
989 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
|
990 extra = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
991 cont, ret = await self.host.trigger.async_return_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
992 "XEP-0060_getItems", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
993 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
994 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
995 node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
996 max_items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
997 item_ids, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
998 sub_id, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
999 rsm_request, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1000 extra, |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1001 ) |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1002 if not cont: |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1003 return ret |
1777 | 1004 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1005 mam_query = extra["mam"] |
1777 | 1006 except KeyError: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1007 d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1008 client.pubsub_client.items( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1009 service=service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1010 nodeIdentifier=node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1011 maxItems=max_items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1012 subscriptionIdentifier=sub_id, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1013 sender=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1014 itemIdentifiers=item_ids, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1015 orderBy=extra.get(C.KEY_ORDER_BY), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1016 rsm_request=rsm_request, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1017 extra=extra, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1018 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1019 ) |
2758
f4070693814a
plugin XEP-0060: fixed MAM return value on getItems():
Goffi <goffi@goffi.org>
parents:
2718
diff
changeset
|
1020 # we have no MAM data here, so we add None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1021 d.addErrback(sat_defer.stanza_2_not_found) |
2769
9282b289b964
plugin XEP-0060: set a 30s timeout on items get
Goffi <goffi@goffi.org>
parents:
2760
diff
changeset
|
1022 d.addTimeout(TIMEOUT, reactor) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1023 items, rsm_response = await d |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1024 mam_response = None |
1777 | 1025 else: |
1026 # if mam is requested, we have to do a totally different query | |
1027 if self._mam is None: | |
3028 | 1028 raise exceptions.NotFound("MAM (XEP-0313) plugin is not available") |
1777 | 1029 if max_items is not None: |
3028 | 1030 raise exceptions.DataError("max_items parameter can't be used with MAM") |
1777 | 1031 if item_ids: |
3028 | 1032 raise exceptions.DataError("items_ids parameter can't be used with MAM") |
1777 | 1033 if mam_query.node is None: |
1034 mam_query.node = node | |
1035 elif mam_query.node != node: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1036 raise exceptions.DataError( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1037 "MAM query node is incoherent with get_items's node" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1038 ) |
1777 | 1039 if mam_query.rsm is None: |
1040 mam_query.rsm = rsm_request | |
1041 else: | |
1042 if mam_query.rsm != rsm_request: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1043 raise exceptions.DataError( |
3028 | 1044 "Conflict between RSM request and MAM's RSM request" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1045 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1046 items, rsm_response, mam_response = await self._mam.get_archives( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1047 client, mam_query, service, self._unwrap_mam_message |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1048 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1049 |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1050 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1051 subscribe = C.bool(extra["subscribe"]) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1052 except KeyError: |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1053 subscribe = False |
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1054 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1055 if subscribe: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1056 try: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1057 await self.subscribe(client, service, node) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1058 except error.StanzaError as e: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1059 log.warning( |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1060 f"Could not subscribe to node {node} on service {service}: {e}" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1061 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1062 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1063 # TODO: handle mam_response |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1064 service_jid = service if service else client.jid.userhostJID() |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1065 metadata = { |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1066 "service": service_jid, |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1067 "node": node, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1068 "uri": self.get_node_uri(service_jid, node), |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1069 } |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1070 if mam_response is not None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1071 # mam_response is a dict with "complete" and "stable" keys |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1072 # we can put them directly in metadata |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1073 metadata.update(mam_response) |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1074 if rsm_request is not None and rsm_response is not None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1075 metadata["rsm"] = rsm_response.toDict() |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1076 if mam_response is None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1077 index = rsm_response.index |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1078 count = rsm_response.count |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1079 if index is None or count is None: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1080 # we don't have enough information to know if the data is complete |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1081 # or not |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1082 metadata["complete"] = None |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1083 else: |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1084 # normally we have a strict equality here but XEP-0059 states |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1085 # that index MAY be approximative, so just in case… |
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1086 metadata["complete"] = index + len(items) >= count |
3948
cd4d95b3fed3
plugin OXPS, XEP-0060: indicate which items were e2ee:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1087 # encrypted metadata can be added by plugins in XEP-0060_items trigger |
cd4d95b3fed3
plugin OXPS, XEP-0060: indicate which items were e2ee:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1088 if "encrypted" in extra: |
cd4d95b3fed3
plugin OXPS, XEP-0060: indicate which items were e2ee:
Goffi <goffi@goffi.org>
parents:
3934
diff
changeset
|
1089 metadata["encrypted"] = extra["encrypted"] |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1090 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1091 return (items, metadata) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
1092 |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1093 # @defer.inlineCallbacks |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1094 # 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
|
1095 # """Massively retrieve pubsub items from many nodes. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1096 # @param service (JID): target service. |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1097 # @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
|
1098 # @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
|
1099 # @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
|
1100 # @param rsm (dict): RSM request data |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1101 # @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
|
1102 # @return: a deferred dict with: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1103 # - 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
|
1104 # - couple (list[dict], dict) containing: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1105 # - list of items |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1106 # - RSM response data |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1107 # """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1108 # client = self.host.get_client(profile_key) |
1446
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1109 # 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
|
1110 # d_dict = {} |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1111 # for publisher, node in data.items(): |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1112 # if node not in found_nodes: |
e8c8e467964b
plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents:
1420
diff
changeset
|
1113 # 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
|
1114 # continue # avoid pubsub "item-not-found" error |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1115 # d_dict[publisher] = self.get_items(service, node, max_items, None, sub_id, rsm, client.profile) |
4341
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4334
diff
changeset
|
1116 # return d_dict |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1117 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1118 def getOptions( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1119 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1120 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1121 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1122 subscriber, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1123 subscriptionIdentifier=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1124 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1125 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1126 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1127 return client.pubsub_client.getOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1128 service, nodeIdentifier, subscriber, subscriptionIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1129 ) |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
1130 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1131 def setOptions( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1132 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1133 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1134 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1135 subscriber, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1136 options, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1137 subscriptionIdentifier=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1138 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1139 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1140 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1141 return client.pubsub_client.setOptions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1142 service, nodeIdentifier, subscriber, options, subscriptionIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1143 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1144 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1145 def _create_node(self, service_s, nodeIdentifier, options, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1146 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1147 return self.createNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1148 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1149 ) |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
1150 |
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1151 def createNode( |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1152 self, |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
1153 client: SatXMPPEntity, |
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1154 service: jid.JID, |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1155 nodeIdentifier: Optional[str] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1156 options: Optional[Dict[str, str]] = None, |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
1157 ) -> defer.Deferred[str]: |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
1158 """Create a new node |
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
1159 |
3933
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1160 @param service: PubSub service, |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1161 @param NodeIdentifier: node name use None to create instant node (identifier will |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1162 be returned by this method) |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1163 @param option: node configuration options |
cecf45416403
plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
Syndace <me@syndace.dev>
parents:
3911
diff
changeset
|
1164 @return: identifier of the created node (may be different from requested name) |
2218
6a2fa651d7fa
plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents:
2206
diff
changeset
|
1165 """ |
2393
8ed4ac10cb5e
plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents:
2389
diff
changeset
|
1166 # TODO: if pubsub service doesn't hande publish-options, configure it in a second time |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
1167 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
|
1168 |
2389
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1169 @defer.inlineCallbacks |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1170 def create_if_new_node(self, client, service, nodeIdentifier, options=None): |
2389
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1171 """Helper method similar to createNode, but will not fail in case of conflict""" |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1172 try: |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1173 yield self.createNode(client, service, nodeIdentifier, options) |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1174 except error.StanzaError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1175 if e.condition == "conflict": |
2389
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1176 pass |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1177 else: |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1178 raise e |
5675af905725
plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents:
2360
diff
changeset
|
1179 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1180 def _get_node_configuration(self, service_s, nodeIdentifier, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1181 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1182 d = self.getConfiguration( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1183 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1184 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1185 |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1186 def serialize(form): |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1187 # FIXME: better more generic dataform serialisation should be available in SàT |
3028 | 1188 return {f.var: str(f.value) for f in list(form.fields.values())} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1189 |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1190 d.addCallback(serialize) |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1191 return d |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1192 |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1193 def getConfiguration(self, client, service, nodeIdentifier): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1194 request = pubsub.PubSubRequest("configureGet") |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1195 request.recipient = service |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1196 request.nodeIdentifier = nodeIdentifier |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1197 |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1198 def cb(iq): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1199 form = data_form.findForm(iq.pubsub.configure, pubsub.NS_PUBSUB_NODE_CONFIG) |
2196
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1200 form.typeCheck() |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1201 return form |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1202 |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1203 d = request.send(client.xmlstream) |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1204 d.addCallback(cb) |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1205 return d |
d3e48c9a255e
plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
1206 |
3993
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1207 def make_configuration_form(self, options: dict) -> data_form.Form: |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1208 """Build a configuration form""" |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1209 form = data_form.Form( |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1210 formType="submit", formNamespace=pubsub.NS_PUBSUB_NODE_CONFIG |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1211 ) |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1212 form.makeFields(options) |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1213 return form |
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1214 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1215 def _set_node_configuration(self, service_s, nodeIdentifier, options, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1216 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1217 d = self.setConfiguration( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1218 client, jid.JID(service_s) if service_s else None, nodeIdentifier, options |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1219 ) |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1220 return d |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1221 |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1222 def setConfiguration(self, client, service, nodeIdentifier, options): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1223 request = pubsub.PubSubRequest("configureSet") |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1224 request.recipient = service |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1225 request.nodeIdentifier = nodeIdentifier |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1226 |
3993
722c25818778
plugin XEP-0470: create a default configuration if node config can't be accessed
Goffi <goffi@goffi.org>
parents:
3948
diff
changeset
|
1227 form = self.make_configuration_form(options) |
2198
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1228 request.options = form |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1229 |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1230 d = request.send(client.xmlstream) |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1231 return d |
44f12990e275
plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents:
2196
diff
changeset
|
1232 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1233 def _get_affiliations(self, service_s, nodeIdentifier, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1234 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1235 d = self.get_affiliations( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1236 client, jid.JID(service_s) if service_s else None, nodeIdentifier or None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1237 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1238 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1239 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1240 def get_affiliations(self, client, service, nodeIdentifier=None): |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1241 """Retrieve affiliations of an entity |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1242 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1243 @param nodeIdentifier(unicode, None): node to get affiliation from |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1244 None to get all nodes affiliations for this service |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1245 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1246 request = pubsub.PubSubRequest("affiliations") |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1247 request.recipient = service |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1248 request.nodeIdentifier = nodeIdentifier |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1249 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1250 def cb(iq_elt): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1251 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1252 affiliations_elt = next( |
3859
3ef988734869
core: fix calls to `domish.Element.elements`:
Goffi <goffi@goffi.org>
parents:
3854
diff
changeset
|
1253 iq_elt.pubsub.elements(pubsub.NS_PUBSUB, "affiliations") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1254 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1255 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1256 raise ValueError( |
3028 | 1257 _("Invalid result: missing <affiliations> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1258 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1259 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1260 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1261 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1262 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1263 e["node"]: e["affiliation"] |
3859
3ef988734869
core: fix calls to `domish.Element.elements`:
Goffi <goffi@goffi.org>
parents:
3854
diff
changeset
|
1264 for e in affiliations_elt.elements(pubsub.NS_PUBSUB, "affiliation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1265 } |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1266 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1267 raise ValueError( |
3028 | 1268 _("Invalid result: bad <affiliation> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1269 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1270 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1271 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1272 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1273 d = request.send(client.xmlstream) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1274 d.addCallback(cb) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1275 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1276 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1277 def _get_node_affiliations(self, service_s, nodeIdentifier, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1278 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1279 d = self.get_node_affiliations( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1280 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1281 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1282 d.addCallback(lambda affiliations: {j.full(): a for j, a in affiliations.items()}) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1283 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1284 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1285 def get_node_affiliations(self, client, service, nodeIdentifier): |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1286 """Retrieve affiliations of a node owned by profile""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1287 request = pubsub.PubSubRequest("affiliationsGet") |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1288 request.recipient = service |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1289 request.nodeIdentifier = nodeIdentifier |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1290 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1291 def cb(iq_elt): |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1292 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1293 affiliations_elt = next( |
3859
3ef988734869
core: fix calls to `domish.Element.elements`:
Goffi <goffi@goffi.org>
parents:
3854
diff
changeset
|
1294 iq_elt.pubsub.elements(pubsub.NS_PUBSUB_OWNER, "affiliations") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1295 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1296 except StopIteration: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1297 raise ValueError( |
3028 | 1298 _("Invalid result: missing <affiliations> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1299 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1300 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1301 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1302 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1303 return { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1304 jid.JID(e["jid"]): e["affiliation"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1305 for e in affiliations_elt.elements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1306 (pubsub.NS_PUBSUB_OWNER, "affiliation") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1307 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1308 } |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1309 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1310 raise ValueError( |
3028 | 1311 _("Invalid result: bad <affiliation> element: {}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1312 iq_elt.toXml |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1313 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1314 ) |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1315 |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1316 d = request.send(client.xmlstream) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1317 d.addCallback(cb) |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1318 return d |
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1319 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1320 def _set_node_affiliations( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1321 self, service_s, nodeIdentifier, affiliations, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1322 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1323 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1324 affiliations = { |
3028 | 1325 jid.JID(jid_): affiliation for jid_, affiliation in affiliations.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1326 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1327 d = self.set_node_affiliations( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1328 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1329 jid.JID(service_s) if service_s else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1330 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1331 affiliations, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1332 ) |
2206
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1333 return d |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1334 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1335 def set_node_affiliations(self, client, service, nodeIdentifier, affiliations): |
2206
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1336 """Update affiliations of a node owned by profile |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1337 |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1338 @param affiliations(dict[jid.JID, unicode]): affiliations to set |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1339 check https://xmpp.org/extensions/xep-0060.html#affiliations for a list of possible affiliations |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1340 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1341 request = pubsub.PubSubRequest("affiliationsSet") |
2206
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1342 request.recipient = service |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1343 request.nodeIdentifier = nodeIdentifier |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1344 request.affiliations = affiliations |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1345 d = request.send(client.xmlstream) |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1346 return d |
59d3de85a0cb
plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents:
2203
diff
changeset
|
1347 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1348 def _purge_node(self, service_s, nodeIdentifier, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1349 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1350 return self.purge_node( |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1351 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1352 ) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1353 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1354 def purge_node(self, client, service, nodeIdentifier): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1355 return client.pubsub_client.purge_node(service, nodeIdentifier) |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
1356 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1357 def _delete_node(self, service_s, nodeIdentifier, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1358 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1359 return self.deleteNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1360 client, jid.JID(service_s) if service_s else None, nodeIdentifier |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1361 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1362 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1363 def deleteNode( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1364 self, client: SatXMPPClient, service: jid.JID, nodeIdentifier: str |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1365 ) -> defer.Deferred: |
1420
7c0acb966fd6
plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
1366 return client.pubsub_client.deleteNode(service, nodeIdentifier) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1367 |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1368 def _addWatch(self, service_s, node, profile_key): |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1369 """watch modifications on a node |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1370 |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1371 This method should only be called from bridge |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1372 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1373 client = self.host.get_client(profile_key) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1374 service = jid.JID(service_s) if service_s else client.jid.userhostJID() |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1375 client.pubsub_watching.add((service, node)) |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1376 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1377 def _remove_watch(self, service_s, node, profile_key): |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1378 """remove a node watch |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1379 |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1380 This method should only be called from bridge |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1381 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1382 client = self.host.get_client(profile_key) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1383 service = jid.JID(service_s) if service_s else client.jid.userhostJID() |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1384 client.pubsub_watching.remove((service, node)) |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1385 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1386 def _retract_item( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1387 self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1388 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1389 return self._retract_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1390 service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1391 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1392 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1393 def _retract_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1394 self, service_s, nodeIdentifier, itemIdentifiers, notify, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1395 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1396 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1397 return self.retract_items( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1398 client, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1399 jid.JID(service_s) if service_s else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1400 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1401 itemIdentifiers, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1402 notify, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1403 ) |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1404 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1405 def retract_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1406 self, |
4327
554a87ae17a6
plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents:
4294
diff
changeset
|
1407 client: SatXMPPEntity, |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1408 service: jid.JID, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1409 nodeIdentifier: str, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1410 itemIdentifiers: Iterable[str], |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1411 notify: bool = True, |
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3899
diff
changeset
|
1412 ) -> defer.Deferred: |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1413 return client.pubsub_client.retractItems( |
3590
1269c2d788be
plugin XEP-0060: fix notification handling in `retractItems`
Goffi <goffi@goffi.org>
parents:
3589
diff
changeset
|
1414 service, nodeIdentifier, itemIdentifiers, notify=notify |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1415 ) |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1416 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1417 def _rename_item( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1418 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1419 service, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1420 node, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1421 item_id, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1422 new_id, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1423 profile_key=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1424 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1425 client = self.host.get_client(profile_key) |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1426 service = jid.JID(service) if service else None |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1427 return defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1428 self.rename_item(client, service, node, item_id, new_id) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1429 ) |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1430 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1431 async def rename_item( |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1432 self, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1433 client: SatXMPPEntity, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1434 service: Optional[jid.JID], |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1435 node: str, |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1436 item_id: str, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1437 new_id: str, |
3519
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1438 ) -> None: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1439 """Rename an item by recreating it then deleting it |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1440 |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1441 we have to recreate then delete because there is currently no rename operation |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1442 with PubSub |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1443 """ |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1444 if not item_id or not new_id: |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1445 raise ValueError("item_id and new_id must not be empty") |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1446 # retract must be done last, so if something goes wrong, the exception will stop |
02eec2a5b5f9
plugin XEP-0060, XEP-0277: new rename methods (`psItemRename`, `mbRename`):
Goffi <goffi@goffi.org>
parents:
3492
diff
changeset
|
1447 # the workflow and no accidental delete should happen |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1448 item_elt = (await self.get_items(client, service, node, item_ids=[item_id]))[0][0] |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1449 await self.send_item(client, service, node, item_elt.firstChildElement(), new_id) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1450 await self.retract_items(client, service, node, [item_id]) |
745
812dc38c0094
plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
704
diff
changeset
|
1451 |
2442
b8ffb7f8056b
plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents:
2432
diff
changeset
|
1452 def _subscribe(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1453 client = self.host.get_client(profile_key) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1454 service = None if not service else jid.JID(service) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1455 d = defer.ensureDeferred( |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1456 self.subscribe( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1457 client, service, nodeIdentifier, options=data_format.deserialise(options) |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1458 ) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1459 ) |
3028 | 1460 d.addCallback(lambda subscription: subscription.subscriptionIdentifier or "") |
2442
b8ffb7f8056b
plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents:
2432
diff
changeset
|
1461 return d |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1462 |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1463 async def subscribe( |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1464 self, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1465 client: SatXMPPEntity, |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
1466 service: Optional[jid.JID], |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1467 nodeIdentifier: str, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1468 sub_jid: Optional[jid.JID] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1469 options: Optional[dict] = None, |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1470 ) -> pubsub.Subscription: |
1459
4c4f88d7b156
plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents:
1452
diff
changeset
|
1471 # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe |
3867
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
1472 if service is None: |
c3e6c54660da
plugin XEP-0060: sender can now be specified in `sendItems` and `publish`:
Goffi <goffi@goffi.org>
parents:
3860
diff
changeset
|
1473 service = client.jid.userhostJID() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1474 cont, trigger_sub = await self.host.trigger.async_return_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1475 "XEP-0060_subscribe", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1476 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1477 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1478 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1479 sub_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1480 options, |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1481 ) |
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1482 if not cont: |
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1483 return trigger_sub |
3899
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1484 try: |
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1485 subscription = await client.pubsub_client.subscribe( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1486 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1487 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1488 sub_jid or client.jid.userhostJID(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1489 options=options, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1490 sender=client.jid.userhostJID(), |
3899
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1491 ) |
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1492 except error.StanzaError as e: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1493 if e.condition == "item-not-found": |
3899
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1494 raise exceptions.NotFound(e.text or e.condition) |
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1495 else: |
1e64f1ed3ebd
plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`:
Goffi <goffi@goffi.org>
parents:
3867
diff
changeset
|
1496 raise e |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1497 return subscription |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1498 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1499 def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1500 client = self.host.get_client(profile_key) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1501 service = None if not service else jid.JID(service) |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1502 return defer.ensureDeferred(self.unsubscribe(client, service, nodeIdentifier)) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1503 |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1504 async def unsubscribe( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1505 self, |
3589
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1506 client: SatXMPPEntity, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1507 service: jid.JID, |
ed037c98df37
plugin XEP-0060: add trigger points
Goffi <goffi@goffi.org>
parents:
3588
diff
changeset
|
1508 nodeIdentifier: str, |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1509 sub_jid: Optional[jid.JID] = None, |
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1510 subscriptionIdentifier: Optional[str] = None, |
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1511 sender: Optional[jid.JID] = None, |
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1512 ) -> None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1513 if not await self.host.trigger.async_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1514 "XEP-0060_unsubscribe", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1515 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1516 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1517 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1518 sub_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1519 subscriptionIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1520 sender, |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1521 ): |
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3756
diff
changeset
|
1522 return |
3791
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1523 try: |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1524 await client.pubsub_client.unsubscribe( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1525 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1526 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1527 sub_jid or client.jid.userhostJID(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1528 subscriptionIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1529 sender, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1530 ) |
3791
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1531 except error.StanzaError as e: |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1532 try: |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1533 next(e.getElement().elements(pubsub.NS_PUBSUB_ERRORS, "not-subscribed")) |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1534 except StopIteration: |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1535 raise e |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1536 else: |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1537 log.info( |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1538 f"{sender.full() if sender else client.jid.full()} was not " |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1539 f"subscribed to node {nodeIdentifier!s} at {service.full()}" |
c61233f51b86
plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1540 ) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1541 |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1542 @utils.ensure_deferred |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1543 async def _subscriptions( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1544 self, service="", nodeIdentifier="", profile_key=C.PROF_KEY_NONE |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1545 ) -> str: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1546 client = self.host.get_client(profile_key) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1547 service = None if not service else jid.JID(service) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1548 subs = await self.subscriptions(client, service, nodeIdentifier or None) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1549 return data_format.serialise(subs) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1550 |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1551 async def subscriptions( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1552 self, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1553 client: SatXMPPEntity, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1554 service: Optional[jid.JID] = None, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1555 node: Optional[str] = None, |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1556 ) -> List[Dict[str, Union[str, bool]]]: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1557 """Retrieve subscriptions from a service |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1558 |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1559 @param service(jid.JID): PubSub service |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1560 @param nodeIdentifier(unicode, None): node to check |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1561 None to get all subscriptions |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1562 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1563 cont, ret = await self.host.trigger.async_return_point( |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1564 "XEP-0060_subscriptions", client, service, node |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1565 ) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1566 if not cont: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1567 return ret |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1568 subs = await client.pubsub_client.subscriptions(service, node) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1569 ret = [] |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1570 for sub in subs: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1571 sub_dict = { |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1572 "service": service.host if service else client.jid.host, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1573 "node": sub.nodeIdentifier, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1574 "subscriber": sub.subscriber.full(), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1575 "state": sub.state, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1576 } |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1577 if sub.subscriptionIdentifier is not None: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1578 sub_dict["id"] = sub.subscriptionIdentifier |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1579 ret.append(sub_dict) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1580 return ret |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
1581 |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1582 ## misc tools ## |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1583 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1584 def get_node_uri(self, service, node, item=None): |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1585 """Return XMPP URI of a PubSub node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1586 |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
1587 @param service(jid.JID): PubSub service |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1588 @param node(unicode): node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1589 @return (unicode): URI of the node |
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1590 """ |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1591 # FIXME: deprecated, use sat.tools.common.uri instead |
1904
614f3abb2c69
plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents:
1903
diff
changeset
|
1592 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
|
1593 # 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
|
1594 # 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
|
1595 # urlencode MUST NOT BE USED. |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1596 query_data = [("node", node.encode("utf-8"))] |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1597 if item is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1598 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
|
1599 return "xmpp:{service}?;{query}".format( |
3028 | 1600 service=service.userhost(), query=urllib.parse.urlencode(query_data) |
1601 ) | |
1829
6079752ffeae
plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents:
1778
diff
changeset
|
1602 |
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
|
1603 ## 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
|
1604 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1605 # generic # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1606 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1607 def get_rt_results( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1608 self, session_id, on_success=None, on_error=None, profile=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1609 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1610 return self.rt_sessions.get_results(session_id, on_success, on_error, profile) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1611 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1612 def trans_items_data(self, items_data, item_cb=lambda item: item.toXml()): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1613 """Helper method to transform result from [get_items] |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1614 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1615 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode]) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1616 as returned by [get_items]. |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1617 @param items_data(tuple): tuple returned by [get_items] |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1618 @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
|
1619 @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
|
1620 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1621 items, metadata = items_data |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1622 items = [item_cb(item) for item in items] |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1623 |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1624 return (items, metadata) |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1625 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1626 def trans_items_data_d(self, items_data, item_cb): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1627 """Helper method to transform result from [get_items], deferred version |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1628 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1629 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode]) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1630 as returned by [get_items]. metadata values are then casted to unicode and |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1631 each item is passed to items_cb. |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1632 An errback is added to item_cb, and when it is fired the value is filtered from |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2801
diff
changeset
|
1633 final items |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1634 @param items_data(tuple): tuple returned by [get_items] |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1635 @param item_cb(callable): method to transform each item (must return a deferred) |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1636 @return (tuple): a deferred which fire a dict which can be serialised to go |
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1637 throught bridge |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1638 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1639 items, metadata = items_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1640 |
3069
73db9db8b9e1
plugin XEP-0277: fixed comments URLs parsing
Goffi <goffi@goffi.org>
parents:
3062
diff
changeset
|
1641 def eb(failure_): |
3308
384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
Goffi <goffi@goffi.org>
parents:
3272
diff
changeset
|
1642 log.warning(f"Error while parsing item: {failure_.value}") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1643 |
4384
33468e175ade
backend: various fixes, and type hints improvments.
Goffi <goffi@goffi.org>
parents:
4356
diff
changeset
|
1644 d = defer.gatherResults( |
33468e175ade
backend: various fixes, and type hints improvments.
Goffi <goffi@goffi.org>
parents:
4356
diff
changeset
|
1645 [utils.as_deferred(item_cb, item).addErrback(eb) for item in items] |
33468e175ade
backend: various fixes, and type hints improvments.
Goffi <goffi@goffi.org>
parents:
4356
diff
changeset
|
1646 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1647 d.addCallback( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1648 lambda parsed_items: ([i for i in parsed_items if i is not None], metadata) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1649 ) |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1650 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
|
1651 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1652 def ser_d_list(self, results, failure_result=None): |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1653 """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
|
1654 |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1655 @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
|
1656 @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
|
1657 (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
|
1658 @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
|
1659 - 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
|
1660 - result |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1661 """ |
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1662 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
|
1663 failure_result = () |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1664 return [ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1665 ( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1666 ("", result) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1667 if success |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1668 else (str(result.result) or UNSPECIFIED, failure_result) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1669 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1670 for success, result in results |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1671 ] |
1451
9b88b19b1ca8
plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents:
1449
diff
changeset
|
1672 |
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
|
1673 # 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
|
1674 |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1675 @utils.ensure_deferred |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1676 async def _get_node_subscriptions( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1677 self, service: str, node: str, profile_key: str |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1678 ) -> Dict[str, str]: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1679 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1680 subs = await self.get_node_subscriptions( |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1681 client, jid.JID(service) if service else None, node |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1682 ) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1683 return {j.full(): a for j, a in subs.items()} |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1684 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1685 async def get_node_subscriptions( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1686 self, client: SatXMPPEntity, service: Optional[jid.JID], nodeIdentifier: str |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1687 ) -> Dict[jid.JID, str]: |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1688 """Retrieve subscriptions to a node |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1689 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1690 @param nodeIdentifier(unicode): node to get subscriptions from |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1691 """ |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1692 if not nodeIdentifier: |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1693 raise exceptions.DataError("node identifier can't be empty") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1694 request = pubsub.PubSubRequest("subscriptionsGet") |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1695 request.recipient = service |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1696 request.nodeIdentifier = nodeIdentifier |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1697 |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1698 iq_elt = await request.send(client.xmlstream) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1699 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1700 subscriptions_elt = next( |
4006
9456852d3286
plugin XEP-0060: fix namespace on node subscriptions request
Goffi <goffi@goffi.org>
parents:
3993
diff
changeset
|
1701 iq_elt.pubsub.elements(pubsub.NS_PUBSUB_OWNER, "subscriptions") |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1702 ) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1703 except StopIteration: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1704 raise ValueError( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1705 _("Invalid result: missing <subscriptions> element: {}").format( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1706 iq_elt.toXml |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1707 ) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1708 ) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1709 except AttributeError as e: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1710 raise ValueError(_("Invalid result: {}").format(e)) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1711 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1712 return { |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1713 jid.JID(s["jid"]): s["subscription"] |
4294
a0ed5c976bf8
component conferences, plugin XEP-0167, XEP-0298: add stream user metadata:
Goffi <goffi@goffi.org>
parents:
4284
diff
changeset
|
1714 for s in subscriptions_elt.elements(pubsub.NS_PUBSUB, "subscription") |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1715 } |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1716 except KeyError: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1717 raise ValueError( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1718 _("Invalid result: bad <subscription> element: {}").format(iq_elt.toXml) |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1719 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1720 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1721 def _set_node_subscriptions( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1722 self, service_s, nodeIdentifier, subscriptions, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1723 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1724 client = self.host.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1725 subscriptions = { |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1726 jid.JID(jid_): subscription for jid_, subscription in subscriptions.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1727 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1728 d = self.set_node_subscriptions( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1729 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1730 jid.JID(service_s) if service_s else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1731 nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1732 subscriptions, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1733 ) |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1734 return d |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1735 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1736 def set_node_subscriptions(self, client, service, nodeIdentifier, subscriptions): |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1737 """Set or update subscriptions of a node owned by profile |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1738 |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1739 @param subscriptions(dict[jid.JID, unicode]): subscriptions to set |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1740 check https://xmpp.org/extensions/xep-0060.html#substates for a list of possible subscriptions |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1741 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1742 request = pubsub.PubSubRequest("subscriptionsSet") |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1743 request.recipient = service |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1744 request.nodeIdentifier = nodeIdentifier |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1745 request.subscriptions = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1746 pubsub.Subscription(nodeIdentifier, jid_, state) |
3028 | 1747 for jid_, state in subscriptions.items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1748 } |
2338
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1749 d = request.send(client.xmlstream) |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1750 return d |
b1bbd2994ceb
plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents:
2319
diff
changeset
|
1751 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1752 def _many_subscribe_rt_result(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
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
|
1753 """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
|
1754 |
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
|
1755 @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
|
1756 @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
|
1757 - 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
|
1758 - 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
|
1759 - 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
|
1760 - 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
|
1761 - 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
|
1762 @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
|
1763 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1764 profile = self.host.get_client(profile_key).profile |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1765 d = self.rt_sessions.get_results( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1766 session_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1767 on_success=lambda result: "", |
3028 | 1768 on_error=lambda failure: str(failure.value), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1769 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1770 ) |
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
|
1771 # we need to convert jid.JID to unicode with full() to serialise it for the bridge |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1772 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1773 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1774 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1775 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1776 (service.full(), node, "" if success else failure or UNSPECIFIED) |
3028 | 1777 for (service, node), (success, failure) in ret[1].items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1778 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1779 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1780 ) |
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
|
1781 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
|
1782 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1783 def _subscribe_to_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1784 self, node_data, subscriber=None, options=None, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1785 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1786 return self.subscribe_to_many( |
3028 | 1787 [(jid.JID(service), str(node)) for service, node in node_data], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1788 jid.JID(subscriber), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1789 options, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1790 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1791 ) |
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
|
1792 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1793 def subscribe_to_many( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1794 self, node_data, subscriber, options=None, profile_key=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1795 ): |
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
|
1796 """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
|
1797 |
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
|
1798 @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
|
1799 - 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
|
1800 - 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
|
1801 @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
|
1802 @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
|
1803 @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
|
1804 @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
|
1805 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1806 client = self.host.get_client(profile_key) |
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
|
1807 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
|
1808 for service, node in node_data: |
3584
edc79cefe968
plugin XEP-0060: `getItem(s)`, `publish` and `(un)subscribe` are now coroutines
Goffi <goffi@goffi.org>
parents:
3519
diff
changeset
|
1809 deferreds[(service, node)] = defer.ensureDeferred( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1810 client.pubsub_client.subscribe(service, node, subscriber, options=options) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1811 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1812 return self.rt_sessions.new_session(deferreds, client.profile) |
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
|
1813 # 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
|
1814 # 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
|
1815 # 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
|
1816 # 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
|
1817 # 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
|
1818 # 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
|
1819 # 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
|
1820 # d_list.append(client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.pubsub_client.parent.jid.userhostJID(), options=options)) |
4341
e9971a4b0627
remove uses of twisted.internet.defer.returnValue
Povilas Kanapickas <povilas@radix.lt>
parents:
4334
diff
changeset
|
1821 # return d_list |
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
|
1822 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1823 # get # |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1824 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1825 def _get_from_many_rt_result(self, session_id, profile_key=C.PROF_KEY_DEFAULT): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1826 """Get real-time results for get_from_many session |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1827 |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1828 @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
|
1829 @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
|
1830 @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
|
1831 - 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
|
1832 - 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
|
1833 - service (unicode): pubsub service |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1834 - node (unicode): pubsub node |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1835 - 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
|
1836 - 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
|
1837 - metadata(dict): serialised metadata |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1838 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1839 profile = self.host.get_client(profile_key).profile |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1840 d = self.rt_sessions.get_results( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1841 session_id, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1842 on_success=lambda result: ("", self.trans_items_data(result)), |
3028 | 1843 on_error=lambda failure: (str(failure.value) or UNSPECIFIED, ([], {})), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1844 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1845 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1846 d.addCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1847 lambda ret: ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1848 ret[0], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1849 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1850 (service.full(), node, failure, items, metadata) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1851 for (service, node), (success, (failure, (items, metadata))) in ret[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1852 1 |
3028 | 1853 ].items() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1854 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1855 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1856 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1857 return d |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1858 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1859 def _get_from_many( |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3584
diff
changeset
|
1860 self, node_data, max_item=10, extra="", profile_key=C.PROF_KEY_NONE |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1861 ): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1862 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1863 @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
|
1864 """ |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1865 max_item = None if max_item == C.NO_LIMIT else max_item |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1866 extra = self.parse_extra(data_format.deserialise(extra)) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1867 return self.get_from_many( |
3028 | 1868 [(jid.JID(service), str(node)) for service, node in node_data], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1869 max_item, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1870 extra.rsm_request, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1871 extra.extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1872 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1873 ) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1874 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1875 def get_from_many( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1876 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1877 node_data, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1878 max_item=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1879 rsm_request=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1880 extra=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1881 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1882 ): |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1883 """Get items from many nodes at once |
2203
427391c706eb
plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents:
2201
diff
changeset
|
1884 |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1885 @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
|
1886 - 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
|
1887 - 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
|
1888 @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
|
1889 @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
|
1890 @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
|
1891 @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
|
1892 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1893 client = self.host.get_client(profile_key) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1894 deferreds = {} |
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1895 for service, node in node_data: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1896 deferreds[(service, node)] = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1897 self.get_items( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1898 client, service, node, max_item, rsm_request=rsm_request, extra=extra |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1899 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1900 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1901 return self.rt_sessions.new_session(deferreds, client.profile) |
1452
5116d70ddd1c
plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents:
1451
diff
changeset
|
1902 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1903 |
3028 | 1904 @implementer(disco.IDisco) |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
1905 class SatPubSubClient(rsm.PubSubClient): |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1906 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1907 def __init__(self, host, parent_plugin): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1908 self.host = host |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1909 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
|
1910 rsm.PubSubClient.__init__(self) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1911 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1912 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
|
1913 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
|
1914 |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1915 async def items( |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1916 self, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1917 service: Optional[jid.JID], |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1918 nodeIdentifier: str, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1919 maxItems: Optional[int] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1920 subscriptionIdentifier: Optional[str] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1921 sender: Optional[jid.JID] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1922 itemIdentifiers: Optional[Set[str]] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1923 orderBy: Optional[List[str]] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1924 rsm_request: Optional[rsm.RSMRequest] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1925 extra: Optional[Dict[str, Any]] = None, |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1926 ): |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1927 if extra is None: |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1928 extra = {} |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1929 items, rsm_response = await super().items( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1930 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1931 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1932 maxItems, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1933 subscriptionIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1934 sender, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1935 itemIdentifiers, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1936 orderBy, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1937 rsm_request, |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1938 ) |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1939 # items must be returned, thus this async point can't stop the workflow (but it |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1940 # can modify returned items) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1941 await self.host.trigger.async_point( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1942 "XEP-0060_items", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1943 self.parent, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1944 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1945 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1946 items, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1947 rsm_response, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1948 extra, |
3934
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1949 ) |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1950 return items, rsm_response |
e345d93fb6e5
plugin OXPS: OpenPGP for XMPP Pubsub implementation:
Goffi <goffi@goffi.org>
parents:
3933
diff
changeset
|
1951 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1952 def _get_node_callbacks(self, node, event): |
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
|
1953 """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
|
1954 |
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
|
1955 @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
|
1956 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
|
1957 @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
|
1958 @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
|
1959 """ |
3028 | 1960 for registered_node, callbacks_dict in self.parent_plugin._node_cb.items(): |
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
|
1961 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
|
1962 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
|
1963 try: |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1964 for callback_data in callbacks_dict[event]: |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1965 yield callback_data[0] |
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
|
1966 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
|
1967 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
|
1968 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1969 async def _call_node_callbacks(self, client, event: pubsub.ItemsEvent) -> None: |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1970 """Call sequencially event callbacks of a node |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1971 |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1972 Callbacks are called sequencially and not in parallel to be sure to respect |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1973 priority (notably for plugin needing to get old items before they are modified or |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1974 deleted from cache). |
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1975 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1976 for callback in self._get_node_callbacks(event.nodeIdentifier, C.PS_ITEMS): |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1977 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1978 await utils.as_deferred(callback, client, event) |
3849
bc24ce903835
plugin XEP-0060: handle priority in `addManagedNode`:
Goffi <goffi@goffi.org>
parents:
3815
diff
changeset
|
1979 except Exception as e: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
1980 log.error(f"Error while running items event callback {callback}: {e}") |
2760
3480d4fdf83a
plugins XEP-0060, XEP-0313: implemented Order-By protoXEP:
Goffi <goffi@goffi.org>
parents:
2758
diff
changeset
|
1981 |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1982 def itemsReceived(self, event): |
3028 | 1983 log.debug("Pubsub items received") |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1984 client = self.parent |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1985 defer.ensureDeferred(self._call_node_callbacks(client, event)) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1986 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
1987 raw_items = [i.toXml() for i in event.items] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1988 self.host.bridge.ps_event_raw( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1989 event.sender.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1990 event.nodeIdentifier, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1991 C.PS_ITEMS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1992 raw_items, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1993 client.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1994 ) |
283
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1995 |
68cd30d982a5
core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1996 def deleteReceived(self, event): |
3028 | 1997 log.debug(("Publish node deleted")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1998 for callback in self._get_node_callbacks(event.nodeIdentifier, C.PS_DELETE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
1999 d = utils.as_deferred(callback, self.parent, event) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2000 d.addErrback( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2001 lambda f: log.error( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2002 f"Error while running delete event callback {callback}: {f}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2003 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2004 ) |
2444
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
2005 client = self.parent |
30278ea1ca7c
plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents:
2442
diff
changeset
|
2006 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
2007 self.host.bridge.ps_event_raw( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2008 event.sender.full(), event.nodeIdentifier, C.PS_DELETE, [], client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2009 ) |
615
6f4c31192c7c
plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
2010 |
3587
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2011 def purgeReceived(self, event): |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2012 log.debug(("Publish node purged")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
2013 for callback in self._get_node_callbacks(event.nodeIdentifier, C.PS_PURGE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
2014 d = utils.as_deferred(callback, self.parent, event) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2015 d.addErrback( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2016 lambda f: log.error( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2017 f"Error while running purge event callback {callback}: {f}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2018 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2019 ) |
3587
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2020 client = self.parent |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2021 if (event.sender, event.nodeIdentifier) in client.pubsub_watching: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
2022 self.host.bridge.ps_event_raw( |
3587
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2023 event.sender.full(), event.nodeIdentifier, C.PS_PURGE, [], client.profile |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2024 ) |
2715da5b2aa7
plugin XEP-0060: handle purge notifications
Goffi <goffi@goffi.org>
parents:
3586
diff
changeset
|
2025 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2026 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
|
2027 """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
|
2028 |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2029 @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
|
2030 @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
|
2031 @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
|
2032 @type nodeIdentifier: C{unicode} |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
2033 @return (list[pubsub.Subscription]): list of subscriptions |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2034 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2035 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
|
2036 request.recipient = service |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2037 request.nodeIdentifier = nodeIdentifier |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2038 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
|
2039 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
|
2040 |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
2041 def cb(iq): |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
2042 subs = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2043 for subscription_elt in iq.pubsub.subscriptions.elements( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2044 pubsub.NS_PUBSUB, "subscription" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2045 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2046 subscription = pubsub.Subscription( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2047 subscription_elt["node"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2048 jid.JID(subscription_elt["jid"]), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2049 subscription_elt["subscription"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2050 subscriptionIdentifier=subscription_elt.getAttribute("subid"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2051 ) |
2352
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
2052 subs.append(subscription) |
6c26f435a02d
plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents:
2338
diff
changeset
|
2053 return subs |
1267
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
2054 |
ea692d51a0ee
plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents:
1261
diff
changeset
|
2055 return d.addCallback(cb) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
2056 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4006
diff
changeset
|
2057 def purge_node(self, service, nodeIdentifier): |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2058 """Purge a node (i.e. delete all items from it) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2059 |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2060 @param service(jid.JID, None): service to send the item to |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2061 None to use PEP |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2062 @param NodeIdentifier(unicode): PubSub node to use |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2063 """ |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2064 # TODO: propose this upstream and remove it once merged |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4221
diff
changeset
|
2065 request = pubsub.PubSubRequest("purge") |
2801
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2066 request.recipient = service |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2067 request.nodeIdentifier = nodeIdentifier |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2068 return request.send(self.xmlstream) |
ae127e14b040
plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
Goffi <goffi@goffi.org>
parents:
2800
diff
changeset
|
2069 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2070 def getDiscoInfo(self, requestor, service, nodeIdentifier=""): |
1217
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2071 disco_info = [] |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2072 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
|
2073 return disco_info |
318eab3f93f8
plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
2074 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2075 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
|
2076 return [] |