comparison sat/plugins/plugin_xep_0033.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 378188abe941
children 559a625a236b
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 Extended Stanza Addressing (xep-0033) 4 # SAT plugin for Extended Stanza Addressing (xep-0033)
5 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) 5 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
6 6
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 23
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat.core import exceptions 25 from sat.core import exceptions
26 from wokkel import disco, iwokkel 26 from wokkel import disco, iwokkel
27 from zope.interface import implements 27 from zope.interface import implementer
28 from twisted.words.protocols.jabber.jid import JID 28 from twisted.words.protocols.jabber.jid import JID
29 from twisted.python import failure 29 from twisted.python import failure
30 import copy 30 import copy
31 31
32 try: 32 try:
95 if not entities: 95 if not entities:
96 log.warning( 96 log.warning(
97 _("XEP-0033 is being used but the server doesn't support it!") 97 _("XEP-0033 is being used but the server doesn't support it!")
98 ) 98 )
99 raise failure.Failure( 99 raise failure.Failure(
100 exceptions.CancelError(u"Cancelled by XEP-0033") 100 exceptions.CancelError("Cancelled by XEP-0033")
101 ) 101 )
102 if mess_data["to"] not in entities: 102 if mess_data["to"] not in entities:
103 expected = _(" or ").join([entity.userhost() for entity in entities]) 103 expected = _(" or ").join([entity.userhost() for entity in entities])
104 log.warning( 104 log.warning(
105 _( 105 _(
106 u"Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!" 106 "Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!"
107 ) 107 )
108 % {"expected": expected, "current": mess_data["to"]} 108 % {"expected": expected, "current": mess_data["to"]}
109 ) 109 )
110 log.warning( 110 log.warning(
111 _( 111 _(
112 u"TODO: addressing has been fixed by the backend... fix it in the frontend!" 112 "TODO: addressing has been fixed by the backend... fix it in the frontend!"
113 ) 113 )
114 ) 114 )
115 mess_data["to"] = list(entities)[0].userhostJID() 115 mess_data["to"] = list(entities)[0].userhostJID()
116 element = mess_data["xml"].addElement("addresses", NS_ADDRESS) 116 element = mess_data["xml"].addElement("addresses", NS_ADDRESS)
117 entries = [ 117 entries = [
126 ) 126 )
127 ) 127 )
128 # when the prosody plugin is completed, we can immediately return mess_data from here 128 # when the prosody plugin is completed, we can immediately return mess_data from here
129 self.sendAndStoreMessage(mess_data, entries, profile) 129 self.sendAndStoreMessage(mess_data, entries, profile)
130 log.debug("XEP-0033 took over") 130 log.debug("XEP-0033 took over")
131 raise failure.Failure(exceptions.CancelError(u"Cancelled by XEP-0033")) 131 raise failure.Failure(exceptions.CancelError("Cancelled by XEP-0033"))
132 132
133 d = self.host.findFeaturesSet(client, [NS_ADDRESS]) 133 d = self.host.findFeaturesSet(client, [NS_ADDRESS])
134 d.addCallbacks(discoCallback, lambda __: discoCallback(None)) 134 d.addCallbacks(discoCallback, lambda __: discoCallback(None))
135 return d 135 return d
136 136
211 address["jid"], 211 address["jid"],
212 ) 212 )
213 return data 213 return data
214 214
215 try: 215 try:
216 addresses = message.elements(NS_ADDRESS, "addresses").next() 216 addresses = next(message.elements(NS_ADDRESS, "addresses"))
217 except StopIteration: 217 except StopIteration:
218 pass # no addresses 218 pass # no addresses
219 else: 219 else:
220 post_treat.addCallback(post_treat_addr, addresses.children) 220 post_treat.addCallback(post_treat_addr, addresses.children)
221 return True 221 return True
222 222
223 def getHandler(self, client): 223 def getHandler(self, client):
224 return XEP_0033_handler(self, client.profile) 224 return XEP_0033_handler(self, client.profile)
225 225
226 226
227 @implementer(iwokkel.IDisco)
227 class XEP_0033_handler(XMPPHandler): 228 class XEP_0033_handler(XMPPHandler):
228 implements(iwokkel.IDisco)
229 229
230 def __init__(self, plugin_parent, profile): 230 def __init__(self, plugin_parent, profile):
231 self.plugin_parent = plugin_parent 231 self.plugin_parent = plugin_parent
232 self.host = plugin_parent.host 232 self.host = plugin_parent.host
233 self.profile = profile 233 self.profile = profile