comparison sat/plugins/plugin_xep_0261.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
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 log = getLogger(__name__) 24 log = getLogger(__name__)
24 from wokkel import disco, iwokkel 25 from wokkel import disco, iwokkel
25 from zope.interface import implements 26 from zope.interface import implements
26 from twisted.words.xish import domish 27 from twisted.words.xish import domish
27 import uuid 28 import uuid
30 from twisted.words.protocols.xmlstream import XMPPHandler 31 from twisted.words.protocols.xmlstream import XMPPHandler
31 except ImportError: 32 except ImportError:
32 from wokkel.subprotocols import XMPPHandler 33 from wokkel.subprotocols import XMPPHandler
33 34
34 35
35 NS_JINGLE_IBB = 'urn:xmpp:jingle:transports:ibb:1' 36 NS_JINGLE_IBB = "urn:xmpp:jingle:transports:ibb:1"
36 37
37 PLUGIN_INFO = { 38 PLUGIN_INFO = {
38 C.PI_NAME: "Jingle In-Band Bytestreams", 39 C.PI_NAME: "Jingle In-Band Bytestreams",
39 C.PI_IMPORT_NAME: "XEP-0261", 40 C.PI_IMPORT_NAME: "XEP-0261",
40 C.PI_TYPE: "XEP", 41 C.PI_TYPE: "XEP",
41 C.PI_MODES: C.PLUG_MODE_BOTH, 42 C.PI_MODES: C.PLUG_MODE_BOTH,
42 C.PI_PROTOCOLS: ["XEP-0261"], 43 C.PI_PROTOCOLS: ["XEP-0261"],
43 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0047"], 44 C.PI_DEPENDENCIES: ["XEP-0166", "XEP-0047"],
44 C.PI_MAIN: "XEP_0261", 45 C.PI_MAIN: "XEP_0261",
45 C.PI_HANDLER: "yes", 46 C.PI_HANDLER: "yes",
46 C.PI_DESCRIPTION: _("""Implementation of Jingle In-Band Bytestreams""") 47 C.PI_DESCRIPTION: _("""Implementation of Jingle In-Band Bytestreams"""),
47 } 48 }
48 49
49 50
50 class XEP_0261(object): 51 class XEP_0261(object):
51 NAMESPACE = NS_JINGLE_IBB # used by XEP-0260 plugin for transport-replace 52 NAMESPACE = NS_JINGLE_IBB # used by XEP-0260 plugin for transport-replace
52 53
53 def __init__(self, host): 54 def __init__(self, host):
54 log.info(_("plugin Jingle In-Band Bytestreams")) 55 log.info(_("plugin Jingle In-Band Bytestreams"))
55 self.host = host 56 self.host = host
56 self._j = host.plugins["XEP-0166"] # shortcut to access jingle 57 self._j = host.plugins["XEP-0166"] # shortcut to access jingle
57 self._ibb = host.plugins["XEP-0047"] # and in-band bytestream 58 self._ibb = host.plugins["XEP-0047"] # and in-band bytestream
58 self._j.registerTransport(NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000) # must be the lowest priority 59 self._j.registerTransport(
60 NS_JINGLE_IBB, self._j.TRANSPORT_STREAMING, self, -10000
61 ) # must be the lowest priority
59 62
60 def getHandler(self, client): 63 def getHandler(self, client):
61 return XEP_0261_handler() 64 return XEP_0261_handler()
62 65
63 def jingleSessionInit(self, client, session, content_name): 66 def jingleSessionInit(self, client, session, content_name):
64 transport_elt = domish.Element((NS_JINGLE_IBB, "transport")) 67 transport_elt = domish.Element((NS_JINGLE_IBB, "transport"))
65 content_data = session['contents'][content_name] 68 content_data = session["contents"][content_name]
66 transport_data = content_data['transport_data'] 69 transport_data = content_data["transport_data"]
67 transport_data['block_size'] = self._ibb.BLOCK_SIZE 70 transport_data["block_size"] = self._ibb.BLOCK_SIZE
68 transport_elt['block-size'] = unicode(transport_data['block_size']) 71 transport_elt["block-size"] = unicode(transport_data["block_size"])
69 transport_elt['sid'] = transport_data['sid'] = unicode(uuid.uuid4()) 72 transport_elt["sid"] = transport_data["sid"] = unicode(uuid.uuid4())
70 return transport_elt 73 return transport_elt
71 74
72 def jingleHandler(self, client, action, session, content_name, transport_elt): 75 def jingleHandler(self, client, action, session, content_name, transport_elt):
73 content_data = session['contents'][content_name] 76 content_data = session["contents"][content_name]
74 transport_data = content_data['transport_data'] 77 transport_data = content_data["transport_data"]
75 if action in (self._j.A_SESSION_ACCEPT, 78 if action in (
76 self._j.A_ACCEPTED_ACK, 79 self._j.A_SESSION_ACCEPT,
77 self._j.A_TRANSPORT_ACCEPT): 80 self._j.A_ACCEPTED_ACK,
81 self._j.A_TRANSPORT_ACCEPT,
82 ):
78 pass 83 pass
79 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE): 84 elif action in (self._j.A_SESSION_INITIATE, self._j.A_TRANSPORT_REPLACE):
80 transport_data['sid'] = transport_elt['sid'] 85 transport_data["sid"] = transport_elt["sid"]
81 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER): 86 elif action in (self._j.A_START, self._j.A_PREPARE_RESPONDER):
82 peer_jid = session['peer_jid'] 87 peer_jid = session["peer_jid"]
83 sid = transport_data['sid'] 88 sid = transport_data["sid"]
84 stream_object = content_data['stream_object'] 89 stream_object = content_data["stream_object"]
85 if action == self._j.A_START: 90 if action == self._j.A_START:
86 block_size = transport_data['block_size'] 91 block_size = transport_data["block_size"]
87 d = self._ibb.startStream(client, stream_object, peer_jid, sid, block_size) 92 d = self._ibb.startStream(
88 d.chainDeferred(content_data['finished_d']) 93 client, stream_object, peer_jid, sid, block_size
94 )
95 d.chainDeferred(content_data["finished_d"])
89 else: 96 else:
90 d = self._ibb.createSession(client, stream_object, peer_jid, sid) 97 d = self._ibb.createSession(client, stream_object, peer_jid, sid)
91 d.chainDeferred(content_data['finished_d']) 98 d.chainDeferred(content_data["finished_d"])
92 else: 99 else:
93 log.warning(u"FIXME: unmanaged action {}".format(action)) 100 log.warning(u"FIXME: unmanaged action {}".format(action))
94 return transport_elt 101 return transport_elt
95 102
96 103
97 class XEP_0261_handler(XMPPHandler): 104 class XEP_0261_handler(XMPPHandler):
98 implements(iwokkel.IDisco) 105 implements(iwokkel.IDisco)
99 106
100 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): 107 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
101 return [disco.DiscoFeature(NS_JINGLE_IBB)] 108 return [disco.DiscoFeature(NS_JINGLE_IBB)]
102 109
103 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 110 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
104 return [] 111 return []