Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0020.py @ 3167:d0fb79f97466
quick frontends (app): added an "ignore_missing" argument to RemoveListener:
normally an error is logged when removeListener is call on a inexisting listener, but
sometimes listeners are added only in specific scenarios, and it may be handy to try to
delete them without having to explictly check that they have been used.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 12 Feb 2020 19:44:05 +0100 |
parents | 559a625a236b |
children | be6d91572633 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing xep-0020 |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
24 log = getLogger(__name__) |
1665
14fcbaa82fd4
plugin XEP-0020: fixed bad import
souliane <souliane@mailoo.org>
parents:
1577
diff
changeset
|
25 from sat.core import exceptions |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.words.xish import domish |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
3028 | 28 from zope.interface import implementer |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 try: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from twisted.words.protocols.xmlstream import XMPPHandler |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 except ImportError: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from wokkel.subprotocols import XMPPHandler |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from wokkel import disco, iwokkel, data_form |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 NS_FEATURE_NEG = "http://jabber.org/protocol/feature-neg" |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 C.PI_NAME: "XEP 0020 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
41 C.PI_IMPORT_NAME: "XEP-0020", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
42 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
43 C.PI_PROTOCOLS: ["XEP-0020"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
44 C.PI_MAIN: "XEP_0020", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
45 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 C.PI_DESCRIPTION: _("""Implementation of Feature Negotiation"""), |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 } |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
49 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
50 class XEP_0020(object): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
52 log.info(_("Plugin XEP_0020 initialization")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
53 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
54 def getHandler(self, client): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 return XEP_0020_handler() |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 def getFeatureElt(self, elt): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 """Check element's children to find feature elements |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
59 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
60 @param elt(domish.Element): parent element of the feature element |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
61 @return: feature elements |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
62 @raise exceptions.NotFound: no feature element found |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
63 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
64 try: |
3028 | 65 feature_elt = next(elt.elements(NS_FEATURE_NEG, "feature")) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
66 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
67 raise exceptions.NotFound |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
68 return feature_elt |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
69 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
70 def _getForm(self, elt, namespace): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
71 """Return the first child data form |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
73 @param elt(domish.Element): parent of the data form |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
74 @param namespace (None, unicode): form namespace or None to ignore |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
75 @return (None, data_form.Form): data form or None is nothing is found |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
76 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
77 if namespace is None: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
78 try: |
3028 | 79 form_elt = next(elt.elements(data_form.NS_X_DATA)) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
80 except StopIteration: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
81 return None |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
82 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
83 return data_form.Form.fromElement(form_elt) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
84 else: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
85 return data_form.findForm(elt, namespace) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
86 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
87 def getChoosedOptions(self, feature_elt, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 """Return choosed feature for feature element |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
89 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
90 @param feature_elt(domish.Element): feature domish element |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
91 @param namespace (None, unicode): form namespace or None to ignore |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
92 @return (dict): feature name as key, and choosed option as value |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
93 @raise exceptions.NotFound: not data form is found |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
94 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
95 form = self._getForm(feature_elt, namespace) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
96 if form is None: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
97 raise exceptions.NotFound |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 result = {} |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 for field in form.fields: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 values = form.fields[field].values |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 result[field] = values[0] if values else None |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
102 if len(values) > 1: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 _( |
3028 | 105 "More than one value choosed for {}, keeping the first one" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 ).format(field) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 ) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 return result |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
110 def negotiate(self, feature_elt, name, negotiable_values, namespace): |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
111 """Negotiate the feature options |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
112 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
113 @param feature_elt(domish.Element): feature element |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
114 @param name: the option name (i.e. field's var attribute) to negotiate |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
115 @param negotiable_values(iterable): acceptable values for this negotiation |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
116 first corresponding value will be returned |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
117 @param namespace (None, unicode): form namespace or None to ignore |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
118 @raise KeyError: name is not found in data form fields |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
119 """ |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
120 form = self._getForm(feature_elt, namespace) |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
121 options = [option.value for option in form.fields[name].options] |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
122 for value in negotiable_values: |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 if value in options: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 return value |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 return None |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
127 def chooseOption(self, options, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 """Build a feature element with choosed options |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
129 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
130 @param options(dict): dict with feature as key and choosed option as value |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
131 @param namespace (None, unicode): form namespace or None to ignore |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
132 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 feature_elt = domish.Element((NS_FEATURE_NEG, "feature")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 x_form = data_form.Form("submit", formNamespace=namespace) |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
135 x_form.makeFields(options) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 feature_elt.addChild(x_form.toElement()) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 return feature_elt |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
139 def proposeFeatures(self, options_dict, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 """Build a feature element with options to propose |
1577
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
141 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
142 @param options_dict(dict): dict with feature as key and iterable of acceptable options as value |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
143 @param namespace(None, unicode): feature namespace |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
144 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 feature_elt = domish.Element((NS_FEATURE_NEG, "feature")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 x_form = data_form.Form("form", formNamespace=namespace) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 for field in options_dict: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 x_form.addField( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 data_form.Field( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 "list-single", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 field, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 options=[data_form.Option(option) for option in options_dict[field]], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 ) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 feature_elt.addChild(x_form.toElement()) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 return feature_elt |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
158 |
3028 | 159 @implementer(iwokkel.IDisco) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 class XEP_0020_handler(XMPPHandler): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
161 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 return [disco.DiscoFeature(NS_FEATURE_NEG)] |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 return [] |