comparison sat/plugins/plugin_xep_0261.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 69e4716d6268
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 Jingle (XEP-0261) 4 # SAT plugin for Jingle (XEP-0261)
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
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
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 wokkel import disco, iwokkel 25 from wokkel import disco, iwokkel
26 from zope.interface import implements 26 from zope.interface import implementer
27 from twisted.words.xish import domish 27 from twisted.words.xish import domish
28 import uuid 28 import uuid
29 29
30 try: 30 try:
31 from twisted.words.protocols.xmlstream import XMPPHandler 31 from twisted.words.protocols.xmlstream import XMPPHandler
66 def jingleSessionInit(self, client, session, content_name): 66 def jingleSessionInit(self, client, session, content_name):
67 transport_elt = domish.Element((NS_JINGLE_IBB, "transport")) 67 transport_elt = domish.Element((NS_JINGLE_IBB, "transport"))
68 content_data = session["contents"][content_name] 68 content_data = session["contents"][content_name]
69 transport_data = content_data["transport_data"] 69 transport_data = content_data["transport_data"]
70 transport_data["block_size"] = self._ibb.BLOCK_SIZE 70 transport_data["block_size"] = self._ibb.BLOCK_SIZE
71 transport_elt["block-size"] = unicode(transport_data["block_size"]) 71 transport_elt["block-size"] = str(transport_data["block_size"])
72 transport_elt["sid"] = transport_data["sid"] = unicode(uuid.uuid4()) 72 transport_elt["sid"] = transport_data["sid"] = str(uuid.uuid4())
73 return transport_elt 73 return transport_elt
74 74
75 def jingleHandler(self, client, action, session, content_name, transport_elt): 75 def jingleHandler(self, client, action, session, content_name, transport_elt):
76 content_data = session["contents"][content_name] 76 content_data = session["contents"][content_name]
77 transport_data = content_data["transport_data"] 77 transport_data = content_data["transport_data"]
97 else: 97 else:
98 d = self._ibb.createSession( 98 d = self._ibb.createSession(
99 client, stream_object, local_jid, peer_jid, sid) 99 client, stream_object, local_jid, peer_jid, sid)
100 d.chainDeferred(content_data["finished_d"]) 100 d.chainDeferred(content_data["finished_d"])
101 else: 101 else:
102 log.warning(u"FIXME: unmanaged action {}".format(action)) 102 log.warning("FIXME: unmanaged action {}".format(action))
103 return transport_elt 103 return transport_elt
104 104
105 105
106 @implementer(iwokkel.IDisco)
106 class XEP_0261_handler(XMPPHandler): 107 class XEP_0261_handler(XMPPHandler):
107 implements(iwokkel.IDisco)
108 108
109 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): 109 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
110 return [disco.DiscoFeature(NS_JINGLE_IBB)] 110 return [disco.DiscoFeature(NS_JINGLE_IBB)]
111 111
112 def getDiscoItems(self, requestor, target, nodeIdentifier=""): 112 def getDiscoItems(self, requestor, target, nodeIdentifier=""):