comparison sat/bridge/dbus_bridge.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 c7c52c0dc13a
children 2cc2f65379f7
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: a jabber client 4 # SAT: a jabber client
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
99 if not "errback" in kwargs: 99 if not "errback" in kwargs:
100 log.error("errback is missing in method call [%s]" % name) 100 log.error("errback is missing in method call [%s]" % name)
101 raise InternalError 101 raise InternalError
102 callback = kwargs.pop("callback") 102 callback = kwargs.pop("callback")
103 errback = kwargs.pop("errback") 103 errback = kwargs.pop("errback")
104 async = True 104 async_ = True
105 else: 105 else:
106 async = False 106 async_ = False
107 result = self.cb[name](*args, **kwargs) 107 result = self.cb[name](*args, **kwargs)
108 if async: 108 if async_:
109 if not isinstance(result, Deferred): 109 if not isinstance(result, Deferred):
110 log.error("Asynchronous method [%s] does not return a Deferred." % name) 110 log.error("Asynchronous method [%s] does not return a Deferred." % name)
111 raise AsyncNotDeferred 111 raise AsyncNotDeferred
112 result.addCallback( 112 result.addCallback(
113 lambda result: callback() if result is None else callback(result) 113 lambda result: callback() if result is None else callback(result)
212 212
213 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 213 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
214 in_signature='s', out_signature='a(a{ss}si)', 214 in_signature='s', out_signature='a(a{ss}si)',
215 async_callbacks=None) 215 async_callbacks=None)
216 def actionsGet(self, profile_key="@DEFAULT@"): 216 def actionsGet(self, profile_key="@DEFAULT@"):
217 return self._callback("actionsGet", unicode(profile_key)) 217 return self._callback("actionsGet", str(profile_key))
218 218
219 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 219 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
220 in_signature='ss', out_signature='', 220 in_signature='ss', out_signature='',
221 async_callbacks=None) 221 async_callbacks=None)
222 def addContact(self, entity_jid, profile_key="@DEFAULT@"): 222 def addContact(self, entity_jid, profile_key="@DEFAULT@"):
223 return self._callback("addContact", unicode(entity_jid), unicode(profile_key)) 223 return self._callback("addContact", str(entity_jid), str(profile_key))
224 224
225 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 225 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
226 in_signature='s', out_signature='', 226 in_signature='s', out_signature='',
227 async_callbacks=('callback', 'errback')) 227 async_callbacks=('callback', 'errback'))
228 def asyncDeleteProfile(self, profile, callback=None, errback=None): 228 def asyncDeleteProfile(self, profile, callback=None, errback=None):
229 return self._callback("asyncDeleteProfile", unicode(profile), callback=callback, errback=errback) 229 return self._callback("asyncDeleteProfile", str(profile), callback=callback, errback=errback)
230 230
231 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 231 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
232 in_signature='sssis', out_signature='s', 232 in_signature='sssis', out_signature='s',
233 async_callbacks=('callback', 'errback')) 233 async_callbacks=('callback', 'errback'))
234 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): 234 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
235 return self._callback("asyncGetParamA", unicode(name), unicode(category), unicode(attribute), security_limit, unicode(profile_key), callback=callback, errback=errback) 235 return self._callback("asyncGetParamA", str(name), str(category), str(attribute), security_limit, str(profile_key), callback=callback, errback=errback)
236 236
237 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 237 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
238 in_signature='sis', out_signature='a{ss}', 238 in_signature='sis', out_signature='a{ss}',
239 async_callbacks=('callback', 'errback')) 239 async_callbacks=('callback', 'errback'))
240 def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): 240 def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
241 return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback) 241 return self._callback("asyncGetParamsValuesFromCategory", str(category), security_limit, str(profile_key), callback=callback, errback=errback)
242 242
243 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 243 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
244 in_signature='ssa{ss}', out_signature='b', 244 in_signature='ssa{ss}', out_signature='b',
245 async_callbacks=('callback', 'errback')) 245 async_callbacks=('callback', 'errback'))
246 def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None): 246 def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None):
247 return self._callback("connect", unicode(profile_key), unicode(password), options, callback=callback, errback=errback) 247 return self._callback("connect", str(profile_key), str(password), options, callback=callback, errback=errback)
248 248
249 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 249 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
250 in_signature='ss', out_signature='', 250 in_signature='ss', out_signature='',
251 async_callbacks=('callback', 'errback')) 251 async_callbacks=('callback', 'errback'))
252 def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None): 252 def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None):
253 return self._callback("delContact", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback) 253 return self._callback("delContact", str(entity_jid), str(profile_key), callback=callback, errback=errback)
254 254
255 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 255 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
256 in_signature='asa(ss)bbbbbs', out_signature='(a{sa(sss)}a{sa(sss)}a{sa(sss)})', 256 in_signature='asa(ss)bbbbbs', out_signature='(a{sa(sss)}a{sa(sss)}a{sa(sss)})',
257 async_callbacks=('callback', 'errback')) 257 async_callbacks=('callback', 'errback'))
258 def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key=u"@DEFAULT@", callback=None, errback=None): 258 def discoFindByFeatures(self, namespaces, identities, bare_jid=False, service=True, roster=True, own_jid=True, local_device=False, profile_key="@DEFAULT@", callback=None, errback=None):
259 return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, unicode(profile_key), callback=callback, errback=errback) 259 return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, str(profile_key), callback=callback, errback=errback)
260 260
261 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 261 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
262 in_signature='ssbs', out_signature='(asa(sss)a{sa(a{ss}as)})', 262 in_signature='ssbs', out_signature='(asa(sss)a{sa(a{ss}as)})',
263 async_callbacks=('callback', 'errback')) 263 async_callbacks=('callback', 'errback'))
264 def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None): 264 def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key="@DEFAULT@", callback=None, errback=None):
265 return self._callback("discoInfos", unicode(entity_jid), unicode(node), use_cache, unicode(profile_key), callback=callback, errback=errback) 265 return self._callback("discoInfos", str(entity_jid), str(node), use_cache, str(profile_key), callback=callback, errback=errback)
266 266
267 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 267 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
268 in_signature='ssbs', out_signature='a(sss)', 268 in_signature='ssbs', out_signature='a(sss)',
269 async_callbacks=('callback', 'errback')) 269 async_callbacks=('callback', 'errback'))
270 def discoItems(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None): 270 def discoItems(self, entity_jid, node=u'', use_cache=True, profile_key="@DEFAULT@", callback=None, errback=None):
271 return self._callback("discoItems", unicode(entity_jid), unicode(node), use_cache, unicode(profile_key), callback=callback, errback=errback) 271 return self._callback("discoItems", str(entity_jid), str(node), use_cache, str(profile_key), callback=callback, errback=errback)
272 272
273 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 273 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
274 in_signature='s', out_signature='', 274 in_signature='s', out_signature='',
275 async_callbacks=('callback', 'errback')) 275 async_callbacks=('callback', 'errback'))
276 def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None): 276 def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
277 return self._callback("disconnect", unicode(profile_key), callback=callback, errback=errback) 277 return self._callback("disconnect", str(profile_key), callback=callback, errback=errback)
278 278
279 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 279 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
280 in_signature='s', out_signature='s', 280 in_signature='s', out_signature='s',
281 async_callbacks=None) 281 async_callbacks=None)
282 def encryptionNamespaceGet(self, arg_0): 282 def encryptionNamespaceGet(self, arg_0):
283 return self._callback("encryptionNamespaceGet", unicode(arg_0)) 283 return self._callback("encryptionNamespaceGet", str(arg_0))
284 284
285 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 285 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
286 in_signature='', out_signature='aa{ss}', 286 in_signature='', out_signature='aa{ss}',
287 async_callbacks=None) 287 async_callbacks=None)
288 def encryptionPluginsGet(self, ): 288 def encryptionPluginsGet(self, ):
289 return self._callback("encryptionPluginsGet", ) 289 return self._callback("encryptionPluginsGet", )
290 290
291 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 291 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
292 in_signature='sss', out_signature='s', 292 in_signature='sss', out_signature='s',
293 async_callbacks=('callback', 'errback')) 293 async_callbacks=('callback', 'errback'))
294 def encryptionTrustUIGet(self, namespace, arg_1, profile_key, callback=None, errback=None): 294 def encryptionTrustUIGet(self, to_jid, namespace, profile_key, callback=None, errback=None):
295 return self._callback("encryptionTrustUIGet", unicode(namespace), unicode(arg_1), unicode(profile_key), callback=callback, errback=errback) 295 return self._callback("encryptionTrustUIGet", str(to_jid), str(namespace), str(profile_key), callback=callback, errback=errback)
296 296
297 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 297 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
298 in_signature='ss', out_signature='s', 298 in_signature='ss', out_signature='s',
299 async_callbacks=None) 299 async_callbacks=None)
300 def getConfig(self, section, name): 300 def getConfig(self, section, name):
301 return self._callback("getConfig", unicode(section), unicode(name)) 301 return self._callback("getConfig", str(section), str(name))
302 302
303 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 303 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
304 in_signature='s', out_signature='a(sa{ss}as)', 304 in_signature='s', out_signature='a(sa{ss}as)',
305 async_callbacks=('callback', 'errback')) 305 async_callbacks=('callback', 'errback'))
306 def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None): 306 def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None):
307 return self._callback("getContacts", unicode(profile_key), callback=callback, errback=errback) 307 return self._callback("getContacts", str(profile_key), callback=callback, errback=errback)
308 308
309 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 309 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
310 in_signature='ss', out_signature='as', 310 in_signature='ss', out_signature='as',
311 async_callbacks=None) 311 async_callbacks=None)
312 def getContactsFromGroup(self, group, profile_key="@DEFAULT@"): 312 def getContactsFromGroup(self, group, profile_key="@DEFAULT@"):
313 return self._callback("getContactsFromGroup", unicode(group), unicode(profile_key)) 313 return self._callback("getContactsFromGroup", str(group), str(profile_key))
314 314
315 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 315 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
316 in_signature='asass', out_signature='a{sa{ss}}', 316 in_signature='asass', out_signature='a{sa{ss}}',
317 async_callbacks=None) 317 async_callbacks=None)
318 def getEntitiesData(self, jids, keys, profile): 318 def getEntitiesData(self, jids, keys, profile):
319 return self._callback("getEntitiesData", jids, keys, unicode(profile)) 319 return self._callback("getEntitiesData", jids, keys, str(profile))
320 320
321 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 321 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
322 in_signature='sass', out_signature='a{ss}', 322 in_signature='sass', out_signature='a{ss}',
323 async_callbacks=None) 323 async_callbacks=None)
324 def getEntityData(self, jid, keys, profile): 324 def getEntityData(self, jid, keys, profile):
325 return self._callback("getEntityData", unicode(jid), keys, unicode(profile)) 325 return self._callback("getEntityData", str(jid), keys, str(profile))
326 326
327 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 327 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
328 in_signature='s', out_signature='a{sa{ss}}', 328 in_signature='s', out_signature='a{sa{ss}}',
329 async_callbacks=('callback', 'errback')) 329 async_callbacks=('callback', 'errback'))
330 def getFeatures(self, profile_key, callback=None, errback=None): 330 def getFeatures(self, profile_key, callback=None, errback=None):
331 return self._callback("getFeatures", unicode(profile_key), callback=callback, errback=errback) 331 return self._callback("getFeatures", str(profile_key), callback=callback, errback=errback)
332 332
333 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 333 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
334 in_signature='ss', out_signature='s', 334 in_signature='ss', out_signature='s',
335 async_callbacks=None) 335 async_callbacks=None)
336 def getMainResource(self, contact_jid, profile_key="@DEFAULT@"): 336 def getMainResource(self, contact_jid, profile_key="@DEFAULT@"):
337 return self._callback("getMainResource", unicode(contact_jid), unicode(profile_key)) 337 return self._callback("getMainResource", str(contact_jid), str(profile_key))
338 338
339 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 339 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
340 in_signature='ssss', out_signature='s', 340 in_signature='ssss', out_signature='s',
341 async_callbacks=None) 341 async_callbacks=None)
342 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): 342 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
343 return self._callback("getParamA", unicode(name), unicode(category), unicode(attribute), unicode(profile_key)) 343 return self._callback("getParamA", str(name), str(category), str(attribute), str(profile_key))
344 344
345 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 345 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
346 in_signature='', out_signature='as', 346 in_signature='', out_signature='as',
347 async_callbacks=None) 347 async_callbacks=None)
348 def getParamsCategories(self, ): 348 def getParamsCategories(self, ):
350 350
351 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 351 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
352 in_signature='iss', out_signature='s', 352 in_signature='iss', out_signature='s',
353 async_callbacks=('callback', 'errback')) 353 async_callbacks=('callback', 'errback'))
354 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): 354 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None):
355 return self._callback("getParamsUI", security_limit, unicode(app), unicode(profile_key), callback=callback, errback=errback) 355 return self._callback("getParamsUI", security_limit, str(app), str(profile_key), callback=callback, errback=errback)
356 356
357 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 357 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
358 in_signature='s', out_signature='a{sa{s(sia{ss})}}', 358 in_signature='s', out_signature='a{sa{s(sia{ss})}}',
359 async_callbacks=None) 359 async_callbacks=None)
360 def getPresenceStatuses(self, profile_key="@DEFAULT@"): 360 def getPresenceStatuses(self, profile_key="@DEFAULT@"):
361 return self._callback("getPresenceStatuses", unicode(profile_key)) 361 return self._callback("getPresenceStatuses", str(profile_key))
362 362
363 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 363 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
364 in_signature='', out_signature='', 364 in_signature='', out_signature='',
365 async_callbacks=('callback', 'errback')) 365 async_callbacks=('callback', 'errback'))
366 def getReady(self, callback=None, errback=None): 366 def getReady(self, callback=None, errback=None):
374 374
375 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 375 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
376 in_signature='s', out_signature='a{ss}', 376 in_signature='s', out_signature='a{ss}',
377 async_callbacks=None) 377 async_callbacks=None)
378 def getWaitingSub(self, profile_key="@DEFAULT@"): 378 def getWaitingSub(self, profile_key="@DEFAULT@"):
379 return self._callback("getWaitingSub", unicode(profile_key)) 379 return self._callback("getWaitingSub", str(profile_key))
380 380
381 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 381 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
382 in_signature='ssiba{ss}s', out_signature='a(sdssa{ss}a{ss}sa{ss})', 382 in_signature='ssiba{ss}s', out_signature='a(sdssa{ss}a{ss}sa{ss})',
383 async_callbacks=('callback', 'errback')) 383 async_callbacks=('callback', 'errback'))
384 def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None): 384 def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None):
385 return self._callback("historyGet", unicode(from_jid), unicode(to_jid), limit, between, filters, unicode(profile), callback=callback, errback=errback) 385 return self._callback("historyGet", str(from_jid), str(to_jid), limit, between, filters, str(profile), callback=callback, errback=errback)
386 386
387 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 387 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
388 in_signature='s', out_signature='b', 388 in_signature='s', out_signature='b',
389 async_callbacks=None) 389 async_callbacks=None)
390 def isConnected(self, profile_key="@DEFAULT@"): 390 def isConnected(self, profile_key="@DEFAULT@"):
391 return self._callback("isConnected", unicode(profile_key)) 391 return self._callback("isConnected", str(profile_key))
392 392
393 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 393 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
394 in_signature='sa{ss}s', out_signature='a{ss}', 394 in_signature='sa{ss}s', out_signature='a{ss}',
395 async_callbacks=('callback', 'errback')) 395 async_callbacks=('callback', 'errback'))
396 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None): 396 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None):
397 return self._callback("launchAction", unicode(callback_id), data, unicode(profile_key), callback=callback, errback=errback) 397 return self._callback("launchAction", str(callback_id), data, str(profile_key), callback=callback, errback=errback)
398 398
399 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 399 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
400 in_signature='s', out_signature='b', 400 in_signature='s', out_signature='b',
401 async_callbacks=None) 401 async_callbacks=None)
402 def loadParamsTemplate(self, filename): 402 def loadParamsTemplate(self, filename):
403 return self._callback("loadParamsTemplate", unicode(filename)) 403 return self._callback("loadParamsTemplate", str(filename))
404 404
405 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 405 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
406 in_signature='ss', out_signature='s', 406 in_signature='ss', out_signature='s',
407 async_callbacks=None) 407 async_callbacks=None)
408 def menuHelpGet(self, menu_id, language): 408 def menuHelpGet(self, menu_id, language):
409 return self._callback("menuHelpGet", unicode(menu_id), unicode(language)) 409 return self._callback("menuHelpGet", str(menu_id), str(language))
410 410
411 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 411 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
412 in_signature='sasa{ss}is', out_signature='a{ss}', 412 in_signature='sasa{ss}is', out_signature='a{ss}',
413 async_callbacks=('callback', 'errback')) 413 async_callbacks=('callback', 'errback'))
414 def menuLaunch(self, menu_type, path, data, security_limit, profile_key, callback=None, errback=None): 414 def menuLaunch(self, menu_type, path, data, security_limit, profile_key, callback=None, errback=None):
415 return self._callback("menuLaunch", unicode(menu_type), path, data, security_limit, unicode(profile_key), callback=callback, errback=errback) 415 return self._callback("menuLaunch", str(menu_type), path, data, security_limit, str(profile_key), callback=callback, errback=errback)
416 416
417 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 417 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
418 in_signature='si', out_signature='a(ssasasa{ss})', 418 in_signature='si', out_signature='a(ssasasa{ss})',
419 async_callbacks=None) 419 async_callbacks=None)
420 def menusGet(self, language, security_limit): 420 def menusGet(self, language, security_limit):
421 return self._callback("menusGet", unicode(language), security_limit) 421 return self._callback("menusGet", str(language), security_limit)
422 422
423 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 423 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
424 in_signature='ss', out_signature='s', 424 in_signature='ss', out_signature='s',
425 async_callbacks=None) 425 async_callbacks=None)
426 def messageEncryptionGet(self, to_jid, profile_key): 426 def messageEncryptionGet(self, to_jid, profile_key):
427 return self._callback("messageEncryptionGet", unicode(to_jid), unicode(profile_key)) 427 return self._callback("messageEncryptionGet", str(to_jid), str(profile_key))
428 428
429 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 429 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
430 in_signature='ssbs', out_signature='', 430 in_signature='ssbs', out_signature='',
431 async_callbacks=('callback', 'errback')) 431 async_callbacks=('callback', 'errback'))
432 def messageEncryptionStart(self, to_jid, namespace='', replace=False, profile_key="@NONE@", callback=None, errback=None): 432 def messageEncryptionStart(self, to_jid, namespace='', replace=False, profile_key="@NONE@", callback=None, errback=None):
433 return self._callback("messageEncryptionStart", unicode(to_jid), unicode(namespace), replace, unicode(profile_key), callback=callback, errback=errback) 433 return self._callback("messageEncryptionStart", str(to_jid), str(namespace), replace, str(profile_key), callback=callback, errback=errback)
434 434
435 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 435 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
436 in_signature='ss', out_signature='', 436 in_signature='ss', out_signature='',
437 async_callbacks=('callback', 'errback')) 437 async_callbacks=('callback', 'errback'))
438 def messageEncryptionStop(self, to_jid, profile_key, callback=None, errback=None): 438 def messageEncryptionStop(self, to_jid, profile_key, callback=None, errback=None):
439 return self._callback("messageEncryptionStop", unicode(to_jid), unicode(profile_key), callback=callback, errback=errback) 439 return self._callback("messageEncryptionStop", str(to_jid), str(profile_key), callback=callback, errback=errback)
440 440
441 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 441 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
442 in_signature='sa{ss}a{ss}sa{ss}s', out_signature='', 442 in_signature='sa{ss}a{ss}sa{ss}s', out_signature='',
443 async_callbacks=('callback', 'errback')) 443 async_callbacks=('callback', 'errback'))
444 def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None): 444 def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None):
445 return self._callback("messageSend", unicode(to_jid), message, subject, unicode(mess_type), extra, unicode(profile_key), callback=callback, errback=errback) 445 return self._callback("messageSend", str(to_jid), message, subject, str(mess_type), extra, str(profile_key), callback=callback, errback=errback)
446 446
447 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 447 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
448 in_signature='', out_signature='a{ss}', 448 in_signature='', out_signature='a{ss}',
449 async_callbacks=None) 449 async_callbacks=None)
450 def namespacesGet(self, ): 450 def namespacesGet(self, ):
452 452
453 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 453 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
454 in_signature='sis', out_signature='', 454 in_signature='sis', out_signature='',
455 async_callbacks=None) 455 async_callbacks=None)
456 def paramsRegisterApp(self, xml, security_limit=-1, app=''): 456 def paramsRegisterApp(self, xml, security_limit=-1, app=''):
457 return self._callback("paramsRegisterApp", unicode(xml), security_limit, unicode(app)) 457 return self._callback("paramsRegisterApp", str(xml), security_limit, str(app))
458 458
459 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 459 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
460 in_signature='sss', out_signature='', 460 in_signature='sss', out_signature='',
461 async_callbacks=('callback', 'errback')) 461 async_callbacks=('callback', 'errback'))
462 def profileCreate(self, profile, password='', component='', callback=None, errback=None): 462 def profileCreate(self, profile, password='', component='', callback=None, errback=None):
463 return self._callback("profileCreate", unicode(profile), unicode(password), unicode(component), callback=callback, errback=errback) 463 return self._callback("profileCreate", str(profile), str(password), str(component), callback=callback, errback=errback)
464 464
465 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 465 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
466 in_signature='s', out_signature='b', 466 in_signature='s', out_signature='b',
467 async_callbacks=None) 467 async_callbacks=None)
468 def profileIsSessionStarted(self, profile_key="@DEFAULT@"): 468 def profileIsSessionStarted(self, profile_key="@DEFAULT@"):
469 return self._callback("profileIsSessionStarted", unicode(profile_key)) 469 return self._callback("profileIsSessionStarted", str(profile_key))
470 470
471 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 471 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
472 in_signature='s', out_signature='s', 472 in_signature='s', out_signature='s',
473 async_callbacks=None) 473 async_callbacks=None)
474 def profileNameGet(self, profile_key="@DEFAULT@"): 474 def profileNameGet(self, profile_key="@DEFAULT@"):
475 return self._callback("profileNameGet", unicode(profile_key)) 475 return self._callback("profileNameGet", str(profile_key))
476 476
477 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 477 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
478 in_signature='s', out_signature='', 478 in_signature='s', out_signature='',
479 async_callbacks=None) 479 async_callbacks=None)
480 def profileSetDefault(self, profile): 480 def profileSetDefault(self, profile):
481 return self._callback("profileSetDefault", unicode(profile)) 481 return self._callback("profileSetDefault", str(profile))
482 482
483 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 483 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
484 in_signature='ss', out_signature='b', 484 in_signature='ss', out_signature='b',
485 async_callbacks=('callback', 'errback')) 485 async_callbacks=('callback', 'errback'))
486 def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None): 486 def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None):
487 return self._callback("profileStartSession", unicode(password), unicode(profile_key), callback=callback, errback=errback) 487 return self._callback("profileStartSession", str(password), str(profile_key), callback=callback, errback=errback)
488 488
489 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 489 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
490 in_signature='bb', out_signature='as', 490 in_signature='bb', out_signature='as',
491 async_callbacks=None) 491 async_callbacks=None)
492 def profilesListGet(self, clients=True, components=False): 492 def profilesListGet(self, clients=True, components=False):
494 494
495 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 495 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
496 in_signature='ss', out_signature='a{ss}', 496 in_signature='ss', out_signature='a{ss}',
497 async_callbacks=None) 497 async_callbacks=None)
498 def progressGet(self, id, profile): 498 def progressGet(self, id, profile):
499 return self._callback("progressGet", unicode(id), unicode(profile)) 499 return self._callback("progressGet", str(id), str(profile))
500 500
501 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 501 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
502 in_signature='s', out_signature='a{sa{sa{ss}}}', 502 in_signature='s', out_signature='a{sa{sa{ss}}}',
503 async_callbacks=None) 503 async_callbacks=None)
504 def progressGetAll(self, profile): 504 def progressGetAll(self, profile):
505 return self._callback("progressGetAll", unicode(profile)) 505 return self._callback("progressGetAll", str(profile))
506 506
507 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 507 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
508 in_signature='s', out_signature='a{sa{sa{ss}}}', 508 in_signature='s', out_signature='a{sa{sa{ss}}}',
509 async_callbacks=None) 509 async_callbacks=None)
510 def progressGetAllMetadata(self, profile): 510 def progressGetAllMetadata(self, profile):
511 return self._callback("progressGetAllMetadata", unicode(profile)) 511 return self._callback("progressGetAllMetadata", str(profile))
512 512
513 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 513 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
514 in_signature='s', out_signature='', 514 in_signature='s', out_signature='',
515 async_callbacks=('callback', 'errback')) 515 async_callbacks=('callback', 'errback'))
516 def rosterResync(self, profile_key="@DEFAULT@", callback=None, errback=None): 516 def rosterResync(self, profile_key="@DEFAULT@", callback=None, errback=None):
517 return self._callback("rosterResync", unicode(profile_key), callback=callback, errback=errback) 517 return self._callback("rosterResync", str(profile_key), callback=callback, errback=errback)
518 518
519 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 519 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
520 in_signature='s', out_signature='b', 520 in_signature='s', out_signature='b',
521 async_callbacks=None) 521 async_callbacks=None)
522 def saveParamsTemplate(self, filename): 522 def saveParamsTemplate(self, filename):
523 return self._callback("saveParamsTemplate", unicode(filename)) 523 return self._callback("saveParamsTemplate", str(filename))
524 524
525 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 525 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
526 in_signature='s', out_signature='a{ss}', 526 in_signature='s', out_signature='a{ss}',
527 async_callbacks=('callback', 'errback')) 527 async_callbacks=('callback', 'errback'))
528 def sessionInfosGet(self, profile_key, callback=None, errback=None): 528 def sessionInfosGet(self, profile_key, callback=None, errback=None):
529 return self._callback("sessionInfosGet", unicode(profile_key), callback=callback, errback=errback) 529 return self._callback("sessionInfosGet", str(profile_key), callback=callback, errback=errback)
530 530
531 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 531 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
532 in_signature='sssis', out_signature='', 532 in_signature='sssis', out_signature='',
533 async_callbacks=None) 533 async_callbacks=None)
534 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"): 534 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
535 return self._callback("setParam", unicode(name), unicode(value), unicode(category), security_limit, unicode(profile_key)) 535 return self._callback("setParam", str(name), str(value), str(category), security_limit, str(profile_key))
536 536
537 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 537 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
538 in_signature='ssa{ss}s', out_signature='', 538 in_signature='ssa{ss}s', out_signature='',
539 async_callbacks=None) 539 async_callbacks=None)
540 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"): 540 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"):
541 return self._callback("setPresence", unicode(to_jid), unicode(show), statuses, unicode(profile_key)) 541 return self._callback("setPresence", str(to_jid), str(show), statuses, str(profile_key))
542 542
543 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 543 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
544 in_signature='sss', out_signature='', 544 in_signature='sss', out_signature='',
545 async_callbacks=None) 545 async_callbacks=None)
546 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): 546 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"):
547 return self._callback("subscription", unicode(sub_type), unicode(entity), unicode(profile_key)) 547 return self._callback("subscription", str(sub_type), str(entity), str(profile_key))
548 548
549 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 549 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
550 in_signature='ssass', out_signature='', 550 in_signature='ssass', out_signature='',
551 async_callbacks=('callback', 'errback')) 551 async_callbacks=('callback', 'errback'))
552 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@", callback=None, errback=None): 552 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@", callback=None, errback=None):
553 return self._callback("updateContact", unicode(entity_jid), unicode(name), groups, unicode(profile_key), callback=callback, errback=errback) 553 return self._callback("updateContact", str(entity_jid), str(name), groups, str(profile_key), callback=callback, errback=errback)
554 554
555 def __attributes(self, in_sign): 555 def __attributes(self, in_sign):
556 """Return arguments to user given a in_sign 556 """Return arguments to user given a in_sign
557 @param in_sign: in_sign in the short form (using s,a,i,b etc) 557 @param in_sign: in_sign in the short form (using s,a,i,b etc)
558 @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")""" 558 @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")"""
588 if opening_count == 0: 588 if opening_count == 0:
589 break 589 break
590 i += 1 590 i += 1
591 return attr 591 return attr
592 592
593 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False): 593 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False):
594 """Dynamically add a method to Dbus Bridge""" 594 """Dynamically add a method to Dbus Bridge"""
595 inspect_args = inspect.getargspec(method) 595 inspect_args = inspect.getfullargspec(method)
596 596
597 _arguments = inspect_args.args 597 _arguments = inspect_args.args
598 _defaults = list(inspect_args.defaults or []) 598 _defaults = list(inspect_args.defaults or [])
599 599
600 if inspect.ismethod(method): 600 if inspect.ismethod(method):
604 # first arguments are for the _callback method 604 # first arguments are for the _callback method
605 arguments_callback = ", ".join( 605 arguments_callback = ", ".join(
606 [repr(name)] 606 [repr(name)]
607 + ( 607 + (
608 (_arguments + ["callback=callback", "errback=errback"]) 608 (_arguments + ["callback=callback", "errback=errback"])
609 if async 609 if async_
610 else _arguments 610 else _arguments
611 ) 611 )
612 ) 612 )
613 613
614 if async: 614 if async_:
615 _arguments.extend(["callback", "errback"]) 615 _arguments.extend(["callback", "errback"])
616 _defaults.extend([None, None]) 616 _defaults.extend([None, None])
617 617
618 # now we create a second list with default values 618 # now we create a second list with default values
619 for i in range(1, len(_defaults) + 1): 619 for i in range(1, len(_defaults) + 1):
631 "<DBus bridge>", 631 "<DBus bridge>",
632 "exec", 632 "exec",
633 ) 633 )
634 exec(code) # FIXME: to the same thing in a cleaner way, without compile/exec 634 exec(code) # FIXME: to the same thing in a cleaner way, without compile/exec
635 method = locals()[name] 635 method = locals()[name]
636 async_callbacks = ("callback", "errback") if async else None 636 async_callbacks = ("callback", "errback") if async_ else None
637 setattr( 637 setattr(
638 DbusObject, 638 DbusObject,
639 name, 639 name,
640 dbus.service.method( 640 dbus.service.method(
641 const_INT_PREFIX + int_suffix, 641 const_INT_PREFIX + int_suffix,
683 self.session_bus = dbus.SessionBus() 683 self.session_bus = dbus.SessionBus()
684 except dbus.DBusException as e: 684 except dbus.DBusException as e:
685 if e._dbus_error_name == "org.freedesktop.DBus.Error.NotSupported": 685 if e._dbus_error_name == "org.freedesktop.DBus.Error.NotSupported":
686 log.error( 686 log.error(
687 _( 687 _(
688 u"D-Bus is not launched, please see README to see instructions on how to launch it" 688 "D-Bus is not launched, please see README to see instructions on how to launch it"
689 ) 689 )
690 ) 690 )
691 raise BridgeInitError 691 raise BridgeInitError
692 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) 692 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
693 self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH) 693 self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH)
742 742
743 def register_method(self, name, callback): 743 def register_method(self, name, callback):
744 log.debug("registering DBus bridge method [%s]" % name) 744 log.debug("registering DBus bridge method [%s]" % name)
745 self.dbus_bridge.register_method(name, callback) 745 self.dbus_bridge.register_method(name, callback)
746 746
747 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): 747 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
748 """Dynamically add a method to Dbus Bridge""" 748 """Dynamically add a method to Dbus Bridge"""
749 # FIXME: doc parameter is kept only temporary, the time to remove it from calls 749 # FIXME: doc parameter is kept only temporary, the time to remove it from calls
750 log.debug("Adding method [%s] to DBus bridge" % name) 750 log.debug("Adding method [%s] to DBus bridge" % name)
751 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async) 751 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async_)
752 self.register_method(name, method) 752 self.register_method(name, method)
753 753
754 def addSignal(self, name, int_suffix, signature, doc={}): 754 def addSignal(self, name, int_suffix, signature, doc={}):
755 self.dbus_bridge.addSignal(name, int_suffix, signature, doc) 755 self.dbus_bridge.addSignal(name, int_suffix, signature, doc)
756 setattr(Bridge, name, getattr(self.dbus_bridge, name)) 756 setattr(Bridge, name, getattr(self.dbus_bridge, name))