Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0020.py @ 1589:add1a6c8c594
jp: optional positional arguments on "param get" command
category and name are both optionals:
- if nothing is given, categories list is printed
- if only a category is given, a list of params and their values is printed
- if both category and name are given, the requested param is printed
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 14 Nov 2015 19:18:10 +0100 |
parents | d04d7402b8e9 |
children | 14fcbaa82fd4 |
rev | line source |
---|---|
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
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 |
1396 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 _ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
21 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
22 log = getLogger(__name__) |
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
|
23 from core import exceptions |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from zope.interface import implements |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 try: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from twisted.words.protocols.xmlstream import XMPPHandler |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 except ImportError: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from wokkel.subprotocols import XMPPHandler |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from wokkel import disco, iwokkel, data_form |
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 NS_FEATURE_NEG = 'http://jabber.org/protocol/feature-neg' |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 PLUGIN_INFO = { |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
38 "name": "XEP 0020 Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
39 "import_name": "XEP-0020", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 "type": "XEP", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
41 "protocols": ["XEP-0020"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
42 "main": "XEP_0020", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
43 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
44 "description": _("""Implementation of Feature Negotiation""") |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 } |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
47 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
48 class XEP_0020(object): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
51 log.info(_("Plugin XEP_0020 initialization")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
52 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def getHandler(self, profile): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 return XEP_0020_handler() |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def getFeatureElt(self, elt): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 """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
|
58 |
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 @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
|
60 @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
|
61 @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
|
62 """ |
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 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 |
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 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
|
70 """Return the first child data form |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
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
|
72 @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
|
73 @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
|
74 @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
|
75 """ |
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 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 |
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 def getChoosedOptions(self, feature_elt, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 """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
|
88 |
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 @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
|
90 @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
|
91 @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
|
92 @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
|
93 """ |
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 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
|
95 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
|
96 raise exceptions.NotFound |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 result = {} |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 for field in form.fields: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 values = form.fields[field].values |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 return result |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
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
|
105 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
|
106 """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
|
107 |
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 @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
|
109 @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
|
110 @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
|
111 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
|
112 @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
|
113 @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
|
114 """ |
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 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
|
116 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
|
117 for value in negotiable_values: |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 if value in options: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 return value |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 return None |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
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
|
122 def chooseOption(self, options, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 """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
|
124 |
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 @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
|
126 @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
|
127 """ |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 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
|
129 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
|
130 x_form.makeFields(options) |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 feature_elt.addChild(x_form.toElement()) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 return feature_elt |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
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
|
134 def proposeFeatures(self, options_dict, namespace): |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 """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
|
136 |
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 @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
|
138 @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
|
139 """ |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 feature_elt = domish.Element((NS_FEATURE_NEG, 'feature')) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 x_form = data_form.Form('form', formNamespace=namespace) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 for field in options_dict: |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 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
|
144 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
|
145 feature_elt.addChild(x_form.toElement()) |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 return feature_elt |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
148 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 class XEP_0020_handler(XMPPHandler): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 implements(iwokkel.IDisco) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
151 |
383
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 return [disco.DiscoFeature(NS_FEATURE_NEG)] |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
98e1d44d5cd4
plugins: feature negociation (XEP-0020) implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 return [] |