Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0070.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 | a55a14c3cbf4 |
children | 559a625a236b |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
24 | 24 |
25 log = getLogger(__name__) | 25 log = getLogger(__name__) |
26 from sat.tools import xml_tools | 26 from sat.tools import xml_tools |
27 | 27 |
28 from wokkel import disco, iwokkel | 28 from wokkel import disco, iwokkel |
29 from zope.interface import implements | 29 from zope.interface import implementer |
30 | 30 |
31 try: | 31 try: |
32 from twisted.words.protocols.xmlstream import XMPPHandler | 32 from twisted.words.protocols.xmlstream import XMPPHandler |
33 except ImportError: | 33 except ImportError: |
34 from wokkel.subprotocols import XMPPHandler | 34 from wokkel.subprotocols import XMPPHandler |
61 """ | 61 """ |
62 Implementation for XEP 0070. | 62 Implementation for XEP 0070. |
63 """ | 63 """ |
64 | 64 |
65 def __init__(self, host): | 65 def __init__(self, host): |
66 log.info(_(u"Plugin XEP_0070 initialization")) | 66 log.info(_("Plugin XEP_0070 initialization")) |
67 self.host = host | 67 self.host = host |
68 self._dictRequest = dict() | 68 self._dictRequest = dict() |
69 | 69 |
70 def getHandler(self, client): | 70 def getHandler(self, client): |
71 return XEP_0070_handler(self, client.profile) | 71 return XEP_0070_handler(self, client.profile) |
88 log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (message)")) | 88 log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (message)")) |
89 self._treatHttpAuthRequest(msg_elt, MSG, client) | 89 self._treatHttpAuthRequest(msg_elt, MSG, client) |
90 | 90 |
91 def _treatHttpAuthRequest(self, elt, stanzaType, client): | 91 def _treatHttpAuthRequest(self, elt, stanzaType, client): |
92 elt.handled = True | 92 elt.handled = True |
93 auth_elt = elt.elements(NS_HTTP_AUTH, "confirm").next() | 93 auth_elt = next(elt.elements(NS_HTTP_AUTH, "confirm")) |
94 auth_id = auth_elt["id"] | 94 auth_id = auth_elt["id"] |
95 auth_method = auth_elt["method"] | 95 auth_method = auth_elt["method"] |
96 auth_url = auth_elt["url"] | 96 auth_url = auth_elt["url"] |
97 self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt) | 97 self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt) |
98 title = D_(u"Auth confirmation") | 98 title = D_("Auth confirmation") |
99 message = D_(u"{auth_url} needs to validate your identity, do you agree?\n" | 99 message = D_("{auth_url} needs to validate your identity, do you agree?\n" |
100 u"Validation code : {auth_id}\n\n" | 100 "Validation code : {auth_id}\n\n" |
101 u"Please check that this code is the same as on {auth_url}" | 101 "Please check that this code is the same as on {auth_url}" |
102 ).format(auth_url=auth_url, auth_id=auth_id) | 102 ).format(auth_url=auth_url, auth_id=auth_id) |
103 d = xml_tools.deferConfirm(self.host, message=message, title=title, | 103 d = xml_tools.deferConfirm(self.host, message=message, title=title, |
104 profile=client.profile) | 104 profile=client.profile) |
105 d.addCallback(self._authRequestCallback, client) | 105 d.addCallback(self._authRequestCallback, client) |
106 | 106 |
112 authorized = False | 112 authorized = False |
113 | 113 |
114 if authorized: | 114 if authorized: |
115 if stanzaType == IQ: | 115 if stanzaType == IQ: |
116 # iq | 116 # iq |
117 log.debug(_(u"XEP-0070 reply iq")) | 117 log.debug(_("XEP-0070 reply iq")) |
118 iq_result_elt = xmlstream.toResponse(elt, "result") | 118 iq_result_elt = xmlstream.toResponse(elt, "result") |
119 client.send(iq_result_elt) | 119 client.send(iq_result_elt) |
120 elif stanzaType == MSG: | 120 elif stanzaType == MSG: |
121 # message | 121 # message |
122 log.debug(_(u"XEP-0070 reply message")) | 122 log.debug(_("XEP-0070 reply message")) |
123 msg_result_elt = xmlstream.toResponse(elt, "result") | 123 msg_result_elt = xmlstream.toResponse(elt, "result") |
124 msg_result_elt.addChild(elt.elements(NS_HTTP_AUTH, "confirm").next()) | 124 msg_result_elt.addChild(next(elt.elements(NS_HTTP_AUTH, "confirm"))) |
125 client.send(msg_result_elt) | 125 client.send(msg_result_elt) |
126 else: | 126 else: |
127 log.debug(_(u"XEP-0070 reply error")) | 127 log.debug(_("XEP-0070 reply error")) |
128 result_elt = jabber.error.StanzaError("not-authorized").toResponse(elt) | 128 result_elt = jabber.error.StanzaError("not-authorized").toResponse(elt) |
129 client.send(result_elt) | 129 client.send(result_elt) |
130 | 130 |
131 | 131 |
132 @implementer(iwokkel.IDisco) | |
132 class XEP_0070_handler(XMPPHandler): | 133 class XEP_0070_handler(XMPPHandler): |
133 implements(iwokkel.IDisco) | |
134 | 134 |
135 def __init__(self, plugin_parent, profile): | 135 def __init__(self, plugin_parent, profile): |
136 self.plugin_parent = plugin_parent | 136 self.plugin_parent = plugin_parent |
137 self.host = plugin_parent.host | 137 self.host = plugin_parent.host |
138 self.profile = profile | 138 self.profile = profile |