comparison sat/core/xmpp.py @ 3238:199fc4c551e9

core (xmpp): use asDeferred for profileConnecting and profileConnected
author Goffi <goffi@goffi.org>
date Mon, 30 Mar 2020 19:59:12 +0200
parents cc3fea71c365
children b10d207f95f9
comparison
equal deleted inserted replaced
3237:b0c57c9a4bd8 3238:199fc4c551e9
42 from sat.core.log import getLogger 42 from sat.core.log import getLogger
43 from sat.core import exceptions 43 from sat.core import exceptions
44 from sat.memory import encryption 44 from sat.memory import encryption
45 from sat.memory import persistent 45 from sat.memory import persistent
46 from sat.tools import xml_tools 46 from sat.tools import xml_tools
47 from sat.tools import utils
47 from sat.tools.common import data_format 48 from sat.tools.common import data_format
48 from zope.interface import implementer 49 from zope.interface import implementer
49 50
50 log = getLogger(__name__) 51 log = getLogger(__name__)
51 52
119 # profileConnecting/profileConnected methods handling 120 # profileConnecting/profileConnected methods handling
120 121
121 # profile connecting is called right now (before actually starting client) 122 # profile connecting is called right now (before actually starting client)
122 connecting_cb = getattr(plugin, "profileConnecting", None) 123 connecting_cb = getattr(plugin, "profileConnecting", None)
123 if connecting_cb is not None: 124 if connecting_cb is not None:
124 yield connecting_cb(self) 125 yield utils.asDeferred(connecting_cb, self)
125 126
126 # profile connected is called after client is ready and roster is got 127 # profile connected is called after client is ready and roster is got
127 connected_cb = getattr(plugin, "profileConnected", None) 128 connected_cb = getattr(plugin, "profileConnected", None)
128 if connected_cb is not None: 129 if connected_cb is not None:
129 plugin_conn_cb.append((plugin, connected_cb)) 130 plugin_conn_cb.append((plugin, connected_cb))
234 235
235 # Call profileConnected callback for all plugins, 236 # Call profileConnected callback for all plugins,
236 # and print error message if any of them fails 237 # and print error message if any of them fails
237 conn_cb_list = [] 238 conn_cb_list = []
238 for __, callback in plugin_conn_cb: 239 for __, callback in plugin_conn_cb:
239 conn_cb_list.append(defer.maybeDeferred(callback, entity)) 240 conn_cb_list.append(utils.asDeferred(callback, entity))
240 list_d = defer.DeferredList(conn_cb_list) 241 list_d = defer.DeferredList(conn_cb_list)
241 242
242 def logPluginResults(results): 243 def logPluginResults(results):
243 all_succeed = all([success for success, result in results]) 244 all_succeed = all([success for success, result in results])
244 if not all_succeed: 245 if not all_succeed: