comparison sat/plugins/plugin_xep_0020.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT plugin for managing xep-0020 4 # SAT plugin for managing xep-0020
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
23 23
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat.core import exceptions 25 from sat.core import exceptions
26 from twisted.words.xish import domish 26 from twisted.words.xish import domish
27 27
28 from zope.interface import implements 28 from zope.interface import implementer
29 29
30 try: 30 try:
31 from twisted.words.protocols.xmlstream import XMPPHandler 31 from twisted.words.protocols.xmlstream import XMPPHandler
32 except ImportError: 32 except ImportError:
33 from wokkel.subprotocols import XMPPHandler 33 from wokkel.subprotocols import XMPPHandler
60 @param elt(domish.Element): parent element of the feature element 60 @param elt(domish.Element): parent element of the feature element
61 @return: feature elements 61 @return: feature elements
62 @raise exceptions.NotFound: no feature element found 62 @raise exceptions.NotFound: no feature element found
63 """ 63 """
64 try: 64 try:
65 feature_elt = elt.elements(NS_FEATURE_NEG, "feature").next() 65 feature_elt = next(elt.elements(NS_FEATURE_NEG, "feature"))
66 except StopIteration: 66 except StopIteration:
67 raise exceptions.NotFound 67 raise exceptions.NotFound
68 return feature_elt 68 return feature_elt
69 69
70 def _getForm(self, elt, namespace): 70 def _getForm(self, elt, namespace):
74 @param namespace (None, unicode): form namespace or None to ignore 74 @param namespace (None, unicode): form namespace or None to ignore
75 @return (None, data_form.Form): data form or None is nothing is found 75 @return (None, data_form.Form): data form or None is nothing is found
76 """ 76 """
77 if namespace is None: 77 if namespace is None:
78 try: 78 try:
79 form_elt = elt.elements(data_form.NS_X_DATA).next() 79 form_elt = next(elt.elements(data_form.NS_X_DATA))
80 except StopIteration: 80 except StopIteration:
81 return None 81 return None
82 else: 82 else:
83 return data_form.Form.fromElement(form_elt) 83 return data_form.Form.fromElement(form_elt)
84 else: 84 else:
100 values = form.fields[field].values 100 values = form.fields[field].values
101 result[field] = values[0] if values else None 101 result[field] = values[0] if values else None
102 if len(values) > 1: 102 if len(values) > 1:
103 log.warning( 103 log.warning(
104 _( 104 _(
105 u"More than one value choosed for {}, keeping the first one" 105 "More than one value choosed for {}, keeping the first one"
106 ).format(field) 106 ).format(field)
107 ) 107 )
108 return result 108 return result
109 109
110 def negotiate(self, feature_elt, name, negotiable_values, namespace): 110 def negotiate(self, feature_elt, name, negotiable_values, namespace):
154 ) 154 )
155 feature_elt.addChild(x_form.toElement()) 155 feature_elt.addChild(x_form.toElement())
156 return feature_elt 156 return feature_elt
157 157
158 158
159 @implementer(iwokkel.IDisco)
159 class XEP_0020_handler(XMPPHandler): 160 class XEP_0020_handler(XMPPHandler):
160 implements(iwokkel.IDisco)
161 161
162 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): 162 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
163 return [disco.DiscoFeature(NS_FEATURE_NEG)] 163 return [disco.DiscoFeature(NS_FEATURE_NEG)]
164 164
165 def getDiscoItems(self, requestor, target, nodeIdentifier=""): 165 def getDiscoItems(self, requestor, target, nodeIdentifier=""):