Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0020.py @ 2320:f4a0723042ee
jp (pubsub/search): fixed encoding for stdin in external commands
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 09 Jul 2017 15:20:31 +0200 |
parents | 33c8c4973743 |
children | 8b37a62336c3 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
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 |
1766 | 5 # Copyright (C) 2009-2016 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 |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
23 log = getLogger(__name__) |
1665
14fcbaa82fd4
plugin XEP-0020: fixed bad import
souliane <souliane@mailoo.org>
parents:
1577
diff
changeset
|
24 from sat.core import exceptions |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from twisted.words.xish import domish |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from zope.interface import implements |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 try: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from twisted.words.protocols.xmlstream import XMPPHandler |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 except ImportError: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from wokkel.subprotocols import XMPPHandler |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from wokkel import disco, iwokkel, data_form |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 NS_FEATURE_NEG = 'http://jabber.org/protocol/feature-neg' |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 C.PI_HANDLER: "yes", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
45 C.PI_DESCRIPTION: _("""Implementation of Feature Negotiation""") |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 } |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
48 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
49 class XEP_0020(object): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
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: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
65 feature_elt = elt.elements(NS_FEATURE_NEG, 'feature').next() |
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: |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
79 form_elt = elt.elements(data_form.NS_X_DATA).next() |
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: |
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
|
103 log.warning(_(u"More than one value choosed for {}, keeping the first one").format(field)) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 return result |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
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
|
106 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
|
107 """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
|
108 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
109 @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
|
110 @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
|
111 @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
|
112 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
|
113 @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
|
114 @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
|
115 """ |
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 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
|
117 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
|
118 for value in negotiable_values: |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 if value in options: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 return value |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 return None |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 |
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
|
123 def chooseOption(self, options, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 """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
|
125 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
126 @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
|
127 @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
|
128 """ |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 feature_elt = domish.Element((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
|
130 x_form = data_form.Form('submit', formNamespace=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
|
131 x_form.makeFields(options) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 feature_elt.addChild(x_form.toElement()) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 return feature_elt |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
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 def proposeFeatures(self, options_dict, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 """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
|
137 |
d04d7402b8e9
plugins XEP-0020, XEP-0065, XEP-0095, XEP-0096: fixed file copy with Stream Initiation:
Goffi <goffi@goffi.org>
parents:
1409
diff
changeset
|
138 @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
|
139 @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
|
140 """ |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 feature_elt = domish.Element((NS_FEATURE_NEG, 'feature')) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 x_form = data_form.Form('form', formNamespace=namespace) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 for field in options_dict: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 x_form.addField(data_form.Field('list-single', field, |
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
|
145 options=[data_form.Option(option) for option in options_dict[field]])) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 feature_elt.addChild(x_form.toElement()) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 return feature_elt |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
149 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 class XEP_0020_handler(XMPPHandler): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
152 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 return [disco.DiscoFeature(NS_FEATURE_NEG)] |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 return [] |