comparison sat/plugins/plugin_xep_0166.py @ 3333:ac9342f359e9

plugin XEP-0329: download thumbnails: - thumbnails are now downloaded directly when BoB is used, `filename` is then filled - `utils.asDeferred` is now used for Jingle methods, so `async` coroutines can be used - (XEP-0231): fixed `dumpData`
author Goffi <goffi@goffi.org>
date Thu, 13 Aug 2020 23:46:18 +0200
parents 559a625a236b
children 26a0af6e32c1
comparison
equal deleted inserted replaced
3332:1512cbd6c4ac 3333:ac9342f359e9
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 3 # SàT plugin for Jingle (XEP-0166)
4 # SAT plugin for Jingle (XEP-0166)
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) 4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
6 5
7 # This program is free software: you can redistribute it and/or modify 6 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by 7 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or 8 # the Free Software Foundation, either version 3 of the License, or
15 # GNU Affero General Public License for more details. 14 # GNU Affero General Public License for more details.
16 15
17 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 18
19
20 import uuid
21 import time
22 from collections import namedtuple
23 from zope.interface import implementer
24 from twisted.words.protocols.jabber import jid
25 from twisted.internet import defer
26 from twisted.internet import reactor
27 from twisted.words.protocols.jabber import error
28 from twisted.words.protocols.jabber import xmlstream
29 from twisted.python import failure
30 from wokkel import disco, iwokkel
31 from sat.core import exceptions
20 from sat.core.i18n import _, D_ 32 from sat.core.i18n import _, D_
21 from sat.core.constants import Const as C 33 from sat.core.constants import Const as C
22 from sat.core.log import getLogger 34 from sat.core.log import getLogger
23 from sat.tools import xml_tools 35 from sat.tools import xml_tools
36 from sat.tools import utils
37
24 38
25 log = getLogger(__name__) 39 log = getLogger(__name__)
26 from sat.core import exceptions
27 from twisted.words.protocols.jabber import jid
28 from twisted.internet import defer
29 from twisted.internet import reactor
30 from wokkel import disco, iwokkel
31 from twisted.words.protocols.jabber import error
32 from twisted.words.protocols.jabber import xmlstream
33 from twisted.python import failure
34 from collections import namedtuple
35 import uuid
36 import time
37
38 from zope.interface import implementer
39 40
40 41
41 IQ_SET = '/iq[@type="set"]' 42 IQ_SET = '/iq[@type="set"]'
42 NS_JINGLE = "urn:xmpp:jingle:1" 43 NS_JINGLE = "urn:xmpp:jingle:1"
43 NS_JINGLE_ERROR = "urn:xmpp:jingle:errors:1" 44 NS_JINGLE_ERROR = "urn:xmpp:jingle:errors:1"
755 method = default_cb 756 method = default_cb
756 if elements: 757 if elements:
757 elt = content_data.pop(elt_name) if delete else content_data[elt_name] 758 elt = content_data.pop(elt_name) if delete else content_data[elt_name]
758 else: 759 else:
759 elt = force_element 760 elt = force_element
760 d = defer.maybeDeferred( 761 d = utils.asDeferred(
761 method, client, action, session, content_name, elt 762 method, client, action, session, content_name, elt
762 ) 763 )
763 defers_list.append(d) 764 defers_list.append(d)
764 765
765 return defers_list 766 return defers_list
844 content_elt["name"] = content_name 845 content_elt["name"] = content_name
845 846
846 application = content_data["application"] 847 application = content_data["application"]
847 app_session_accept_cb = application.handler.jingleHandler 848 app_session_accept_cb = application.handler.jingleHandler
848 849
849 app_d = defer.maybeDeferred( 850 app_d = utils.asDeferred(
850 app_session_accept_cb, 851 app_session_accept_cb,
851 client, 852 client,
852 XEP_0166.A_SESSION_INITIATE, 853 XEP_0166.A_SESSION_INITIATE,
853 session, 854 session,
854 content_name, 855 content_name,
858 defers_list.append(app_d) 859 defers_list.append(app_d)
859 860
860 transport = content_data["transport"] 861 transport = content_data["transport"]
861 transport_session_accept_cb = transport.handler.jingleHandler 862 transport_session_accept_cb = transport.handler.jingleHandler
862 863
863 transport_d = defer.maybeDeferred( 864 transport_d = utils.asDeferred(
864 transport_session_accept_cb, 865 transport_session_accept_cb,
865 client, 866 client,
866 XEP_0166.A_SESSION_INITIATE, 867 XEP_0166.A_SESSION_INITIATE,
867 session, 868 session,
868 content_name, 869 content_name,