comparison sat/bridge/dbus_bridge.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 973d4551ffae
children 779351da2c13
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
1 #!/usr/bin/env python2 1 #!/usr/bin/env python2
2 #-*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT: a jabber client 4 # SAT: a jabber client
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
6 6
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
21 import dbus 21 import dbus
22 import dbus.service 22 import dbus.service
23 import dbus.mainloop.glib 23 import dbus.mainloop.glib
24 import inspect 24 import inspect
25 from sat.core.log import getLogger 25 from sat.core.log import getLogger
26
26 log = getLogger(__name__) 27 log = getLogger(__name__)
27 from twisted.internet.defer import Deferred 28 from twisted.internet.defer import Deferred
28 from sat.core.exceptions import BridgeInitError 29 from sat.core.exceptions import BridgeInitError
29 30
30 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix 31 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix
31 const_ERROR_PREFIX = const_INT_PREFIX + ".error" 32 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
32 const_OBJ_PATH = '/org/goffi/SAT/bridge' 33 const_OBJ_PATH = "/org/goffi/SAT/bridge"
33 const_CORE_SUFFIX = ".core" 34 const_CORE_SUFFIX = ".core"
34 const_PLUGIN_SUFFIX = ".plugin" 35 const_PLUGIN_SUFFIX = ".plugin"
35 36
36 37
37 class ParseError(Exception): 38 class ParseError(Exception):
71 message = twisted_error.getErrorMessage() 72 message = twisted_error.getErrorMessage()
72 try: 73 try:
73 self.args = (message, twisted_error.value.condition) 74 self.args = (message, twisted_error.value.condition)
74 except AttributeError: 75 except AttributeError:
75 self.args = (message,) 76 self.args = (message,)
76 self._dbus_error_name = '.'.join([const_ERROR_PREFIX, class_.__module__, class_.__name__]) 77 self._dbus_error_name = ".".join(
78 [const_ERROR_PREFIX, class_.__module__, class_.__name__]
79 )
77 80
78 81
79 class DbusObject(dbus.service.Object): 82 class DbusObject(dbus.service.Object):
80
81 def __init__(self, bus, path): 83 def __init__(self, bus, path):
82 dbus.service.Object.__init__(self, bus, path) 84 dbus.service.Object.__init__(self, bus, path)
83 log.debug("Init DbusObject...") 85 log.debug("Init DbusObject...")
84 self.cb = {} 86 self.cb = {}
85 87
91 if the callback return a deferred, use async methods""" 93 if the callback return a deferred, use async methods"""
92 if not name in self.cb: 94 if not name in self.cb:
93 raise MethodNotRegistered 95 raise MethodNotRegistered
94 96
95 if "callback" in kwargs: 97 if "callback" in kwargs:
96 #we must have errback too 98 # we must have errback too
97 if not "errback" in kwargs: 99 if not "errback" in kwargs:
98 log.error("errback is missing in method call [%s]" % name) 100 log.error("errback is missing in method call [%s]" % name)
99 raise InternalError 101 raise InternalError
100 callback = kwargs.pop("callback") 102 callback = kwargs.pop("callback")
101 errback = kwargs.pop("errback") 103 errback = kwargs.pop("errback")
105 result = self.cb[name](*args, **kwargs) 107 result = self.cb[name](*args, **kwargs)
106 if async: 108 if async:
107 if not isinstance(result, Deferred): 109 if not isinstance(result, Deferred):
108 log.error("Asynchronous method [%s] does not return a Deferred." % name) 110 log.error("Asynchronous method [%s] does not return a Deferred." % name)
109 raise AsyncNotDeferred 111 raise AsyncNotDeferred
110 result.addCallback(lambda result: callback() if result is None else callback(result)) 112 result.addCallback(
113 lambda result: callback() if result is None else callback(result)
114 )
111 result.addErrback(lambda err: errback(GenericException(err))) 115 result.addErrback(lambda err: errback(GenericException(err)))
112 else: 116 else:
113 if isinstance(result, Deferred): 117 if isinstance(result, Deferred):
114 log.error("Synchronous method [%s] return a Deferred." % name) 118 log.error("Synchronous method [%s] return a Deferred." % name)
115 raise DeferredNotAsync 119 raise DeferredNotAsync
116 return result 120 return result
121
117 ### signals ### 122 ### signals ###
118 123
119 @dbus.service.signal(const_INT_PREFIX + const_PLUGIN_SUFFIX, 124 @dbus.service.signal(const_INT_PREFIX + const_PLUGIN_SUFFIX, signature="")
120 signature='')
121 def dummySignal(self): 125 def dummySignal(self):
122 #FIXME: workaround for addSignal (doesn't work if one method doensn't 126 # FIXME: workaround for addSignal (doesn't work if one method doensn't
123 # already exist for plugins), probably missing some initialisation, need 127 # already exist for plugins), probably missing some initialisation, need
124 # further investigations 128 # further investigations
125 pass 129 pass
126 130
127 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 131 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="a{ss}sis")
128 signature='a{ss}sis')
129 def actionNew(self, action_data, id, security_limit, profile): 132 def actionNew(self, action_data, id, security_limit, profile):
130 pass 133 pass
131 134
132 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 135 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="ss")
133 signature='ss')
134 def connected(self, profile, jid_s): 136 def connected(self, profile, jid_s):
135 pass 137 pass
136 138
137 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 139 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="ss")
138 signature='ss')
139 def contactDeleted(self, entity_jid, profile): 140 def contactDeleted(self, entity_jid, profile):
140 pass 141 pass
141 142
142 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 143 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="s")
143 signature='s')
144 def disconnected(self, profile): 144 def disconnected(self, profile):
145 pass 145 pass
146 146
147 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 147 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="ssss")
148 signature='ssss')
149 def entityDataUpdated(self, jid, name, value, profile): 148 def entityDataUpdated(self, jid, name, value, profile):
150 pass 149 pass
151 150
152 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 151 @dbus.service.signal(
153 signature='sdssa{ss}a{ss}sa{ss}s') 152 const_INT_PREFIX + const_CORE_SUFFIX, signature="sdssa{ss}a{ss}sa{ss}s"
154 def messageNew(self, uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile): 153 )
155 pass 154 def messageNew(
156 155 self,
157 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 156 uid,
158 signature='sa{ss}ass') 157 timestamp,
158 from_jid,
159 to_jid,
160 message,
161 subject,
162 mess_type,
163 extra,
164 profile,
165 ):
166 pass
167
168 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="sa{ss}ass")
159 def newContact(self, contact_jid, attributes, groups, profile): 169 def newContact(self, contact_jid, attributes, groups, profile):
160 pass 170 pass
161 171
162 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 172 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="ssss")
163 signature='ssss')
164 def paramUpdate(self, name, value, category, profile): 173 def paramUpdate(self, name, value, category, profile):
165 pass 174 pass
166 175
167 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 176 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="ssia{ss}s")
168 signature='ssia{ss}s')
169 def presenceUpdate(self, entity_jid, show, priority, statuses, profile): 177 def presenceUpdate(self, entity_jid, show, priority, statuses, profile):
170 pass 178 pass
171 179
172 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 180 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="sss")
173 signature='sss')
174 def progressError(self, id, error, profile): 181 def progressError(self, id, error, profile):
175 pass 182 pass
176 183
177 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 184 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="sa{ss}s")
178 signature='sa{ss}s')
179 def progressFinished(self, id, metadata, profile): 185 def progressFinished(self, id, metadata, profile):
180 pass 186 pass
181 187
182 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 188 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="sa{ss}s")
183 signature='sa{ss}s')
184 def progressStarted(self, id, metadata, profile): 189 def progressStarted(self, id, metadata, profile):
185 pass 190 pass
186 191
187 @dbus.service.signal(const_INT_PREFIX+const_CORE_SUFFIX, 192 @dbus.service.signal(const_INT_PREFIX + const_CORE_SUFFIX, signature="sss")
188 signature='sss')
189 def subscribe(self, sub_type, entity_jid, profile): 193 def subscribe(self, sub_type, entity_jid, profile):
190 pass 194 pass
191 195
192 ### methods ### 196 ### methods ###
193 197
194 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 198 @dbus.service.method(
195 in_signature='s', out_signature='a(a{ss}si)', 199 const_INT_PREFIX + const_CORE_SUFFIX,
196 async_callbacks=None) 200 in_signature="s",
201 out_signature="a(a{ss}si)",
202 async_callbacks=None,
203 )
197 def actionsGet(self, profile_key="@DEFAULT@"): 204 def actionsGet(self, profile_key="@DEFAULT@"):
198 return self._callback("actionsGet", unicode(profile_key)) 205 return self._callback("actionsGet", unicode(profile_key))
199 206
200 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 207 @dbus.service.method(
201 in_signature='ss', out_signature='', 208 const_INT_PREFIX + const_CORE_SUFFIX,
202 async_callbacks=None) 209 in_signature="ss",
210 out_signature="",
211 async_callbacks=None,
212 )
203 def addContact(self, entity_jid, profile_key="@DEFAULT@"): 213 def addContact(self, entity_jid, profile_key="@DEFAULT@"):
204 return self._callback("addContact", unicode(entity_jid), unicode(profile_key)) 214 return self._callback("addContact", unicode(entity_jid), unicode(profile_key))
205 215
206 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 216 @dbus.service.method(
207 in_signature='s', out_signature='', 217 const_INT_PREFIX + const_CORE_SUFFIX,
208 async_callbacks=('callback', 'errback')) 218 in_signature="s",
219 out_signature="",
220 async_callbacks=("callback", "errback"),
221 )
209 def asyncDeleteProfile(self, profile, callback=None, errback=None): 222 def asyncDeleteProfile(self, profile, callback=None, errback=None):
210 return self._callback("asyncDeleteProfile", unicode(profile), callback=callback, errback=errback) 223 return self._callback(
211 224 "asyncDeleteProfile", unicode(profile), callback=callback, errback=errback
212 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 225 )
213 in_signature='sssis', out_signature='s', 226
214 async_callbacks=('callback', 'errback')) 227 @dbus.service.method(
215 def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): 228 const_INT_PREFIX + const_CORE_SUFFIX,
216 return self._callback("asyncGetParamA", unicode(name), unicode(category), unicode(attribute), security_limit, unicode(profile_key), callback=callback, errback=errback) 229 in_signature="sssis",
217 230 out_signature="s",
218 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 231 async_callbacks=("callback", "errback"),
219 in_signature='sis', out_signature='a{ss}', 232 )
220 async_callbacks=('callback', 'errback')) 233 def asyncGetParamA(
221 def asyncGetParamsValuesFromCategory(self, category, security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None): 234 self,
222 return self._callback("asyncGetParamsValuesFromCategory", unicode(category), security_limit, unicode(profile_key), callback=callback, errback=errback) 235 name,
223 236 category,
224 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 237 attribute="value",
225 in_signature='ssa{ss}', out_signature='b', 238 security_limit=-1,
226 async_callbacks=('callback', 'errback')) 239 profile_key="@DEFAULT@",
227 def connect(self, profile_key="@DEFAULT@", password='', options={}, callback=None, errback=None): 240 callback=None,
228 return self._callback("connect", unicode(profile_key), unicode(password), options, callback=callback, errback=errback) 241 errback=None,
229 242 ):
230 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 243 return self._callback(
231 in_signature='ss', out_signature='', 244 "asyncGetParamA",
232 async_callbacks=('callback', 'errback')) 245 unicode(name),
233 def delContact(self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None): 246 unicode(category),
234 return self._callback("delContact", unicode(entity_jid), unicode(profile_key), callback=callback, errback=errback) 247 unicode(attribute),
235 248 security_limit,
236 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 249 unicode(profile_key),
237 in_signature='asa(ss)bbbbbs', out_signature='(a{sa(sss)}a{sa(sss)}a{sa(sss)})', 250 callback=callback,
238 async_callbacks=('callback', 'errback')) 251 errback=errback,
239 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): 252 )
240 return self._callback("discoFindByFeatures", namespaces, identities, bare_jid, service, roster, own_jid, local_device, unicode(profile_key), callback=callback, errback=errback) 253
241 254 @dbus.service.method(
242 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 255 const_INT_PREFIX + const_CORE_SUFFIX,
243 in_signature='ssbs', out_signature='(asa(sss)a{sa(a{ss}as)})', 256 in_signature="sis",
244 async_callbacks=('callback', 'errback')) 257 out_signature="a{ss}",
245 def discoInfos(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None): 258 async_callbacks=("callback", "errback"),
246 return self._callback("discoInfos", unicode(entity_jid), unicode(node), use_cache, unicode(profile_key), callback=callback, errback=errback) 259 )
247 260 def asyncGetParamsValuesFromCategory(
248 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 261 self,
249 in_signature='ssbs', out_signature='a(sss)', 262 category,
250 async_callbacks=('callback', 'errback')) 263 security_limit=-1,
251 def discoItems(self, entity_jid, node=u'', use_cache=True, profile_key=u"@DEFAULT@", callback=None, errback=None): 264 profile_key="@DEFAULT@",
252 return self._callback("discoItems", unicode(entity_jid), unicode(node), use_cache, unicode(profile_key), callback=callback, errback=errback) 265 callback=None,
253 266 errback=None,
254 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 267 ):
255 in_signature='s', out_signature='', 268 return self._callback(
256 async_callbacks=('callback', 'errback')) 269 "asyncGetParamsValuesFromCategory",
270 unicode(category),
271 security_limit,
272 unicode(profile_key),
273 callback=callback,
274 errback=errback,
275 )
276
277 @dbus.service.method(
278 const_INT_PREFIX + const_CORE_SUFFIX,
279 in_signature="ssa{ss}",
280 out_signature="b",
281 async_callbacks=("callback", "errback"),
282 )
283 def connect(
284 self,
285 profile_key="@DEFAULT@",
286 password="",
287 options={},
288 callback=None,
289 errback=None,
290 ):
291 return self._callback(
292 "connect",
293 unicode(profile_key),
294 unicode(password),
295 options,
296 callback=callback,
297 errback=errback,
298 )
299
300 @dbus.service.method(
301 const_INT_PREFIX + const_CORE_SUFFIX,
302 in_signature="ss",
303 out_signature="",
304 async_callbacks=("callback", "errback"),
305 )
306 def delContact(
307 self, entity_jid, profile_key="@DEFAULT@", callback=None, errback=None
308 ):
309 return self._callback(
310 "delContact",
311 unicode(entity_jid),
312 unicode(profile_key),
313 callback=callback,
314 errback=errback,
315 )
316
317 @dbus.service.method(
318 const_INT_PREFIX + const_CORE_SUFFIX,
319 in_signature="asa(ss)bbbbbs",
320 out_signature="(a{sa(sss)}a{sa(sss)}a{sa(sss)})",
321 async_callbacks=("callback", "errback"),
322 )
323 def discoFindByFeatures(
324 self,
325 namespaces,
326 identities,
327 bare_jid=False,
328 service=True,
329 roster=True,
330 own_jid=True,
331 local_device=False,
332 profile_key=u"@DEFAULT@",
333 callback=None,
334 errback=None,
335 ):
336 return self._callback(
337 "discoFindByFeatures",
338 namespaces,
339 identities,
340 bare_jid,
341 service,
342 roster,
343 own_jid,
344 local_device,
345 unicode(profile_key),
346 callback=callback,
347 errback=errback,
348 )
349
350 @dbus.service.method(
351 const_INT_PREFIX + const_CORE_SUFFIX,
352 in_signature="ssbs",
353 out_signature="(asa(sss)a{sa(a{ss}as)})",
354 async_callbacks=("callback", "errback"),
355 )
356 def discoInfos(
357 self,
358 entity_jid,
359 node=u"",
360 use_cache=True,
361 profile_key=u"@DEFAULT@",
362 callback=None,
363 errback=None,
364 ):
365 return self._callback(
366 "discoInfos",
367 unicode(entity_jid),
368 unicode(node),
369 use_cache,
370 unicode(profile_key),
371 callback=callback,
372 errback=errback,
373 )
374
375 @dbus.service.method(
376 const_INT_PREFIX + const_CORE_SUFFIX,
377 in_signature="ssbs",
378 out_signature="a(sss)",
379 async_callbacks=("callback", "errback"),
380 )
381 def discoItems(
382 self,
383 entity_jid,
384 node=u"",
385 use_cache=True,
386 profile_key=u"@DEFAULT@",
387 callback=None,
388 errback=None,
389 ):
390 return self._callback(
391 "discoItems",
392 unicode(entity_jid),
393 unicode(node),
394 use_cache,
395 unicode(profile_key),
396 callback=callback,
397 errback=errback,
398 )
399
400 @dbus.service.method(
401 const_INT_PREFIX + const_CORE_SUFFIX,
402 in_signature="s",
403 out_signature="",
404 async_callbacks=("callback", "errback"),
405 )
257 def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None): 406 def disconnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
258 return self._callback("disconnect", unicode(profile_key), callback=callback, errback=errback) 407 return self._callback(
259 408 "disconnect", unicode(profile_key), callback=callback, errback=errback
260 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 409 )
261 in_signature='ss', out_signature='s', 410
262 async_callbacks=None) 411 @dbus.service.method(
412 const_INT_PREFIX + const_CORE_SUFFIX,
413 in_signature="ss",
414 out_signature="s",
415 async_callbacks=None,
416 )
263 def getConfig(self, section, name): 417 def getConfig(self, section, name):
264 return self._callback("getConfig", unicode(section), unicode(name)) 418 return self._callback("getConfig", unicode(section), unicode(name))
265 419
266 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 420 @dbus.service.method(
267 in_signature='s', out_signature='a(sa{ss}as)', 421 const_INT_PREFIX + const_CORE_SUFFIX,
268 async_callbacks=('callback', 'errback')) 422 in_signature="s",
423 out_signature="a(sa{ss}as)",
424 async_callbacks=("callback", "errback"),
425 )
269 def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None): 426 def getContacts(self, profile_key="@DEFAULT@", callback=None, errback=None):
270 return self._callback("getContacts", unicode(profile_key), callback=callback, errback=errback) 427 return self._callback(
271 428 "getContacts", unicode(profile_key), callback=callback, errback=errback
272 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 429 )
273 in_signature='ss', out_signature='as', 430
274 async_callbacks=None) 431 @dbus.service.method(
432 const_INT_PREFIX + const_CORE_SUFFIX,
433 in_signature="ss",
434 out_signature="as",
435 async_callbacks=None,
436 )
275 def getContactsFromGroup(self, group, profile_key="@DEFAULT@"): 437 def getContactsFromGroup(self, group, profile_key="@DEFAULT@"):
276 return self._callback("getContactsFromGroup", unicode(group), unicode(profile_key)) 438 return self._callback(
277 439 "getContactsFromGroup", unicode(group), unicode(profile_key)
278 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 440 )
279 in_signature='asass', out_signature='a{sa{ss}}', 441
280 async_callbacks=None) 442 @dbus.service.method(
443 const_INT_PREFIX + const_CORE_SUFFIX,
444 in_signature="asass",
445 out_signature="a{sa{ss}}",
446 async_callbacks=None,
447 )
281 def getEntitiesData(self, jids, keys, profile): 448 def getEntitiesData(self, jids, keys, profile):
282 return self._callback("getEntitiesData", jids, keys, unicode(profile)) 449 return self._callback("getEntitiesData", jids, keys, unicode(profile))
283 450
284 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 451 @dbus.service.method(
285 in_signature='sass', out_signature='a{ss}', 452 const_INT_PREFIX + const_CORE_SUFFIX,
286 async_callbacks=None) 453 in_signature="sass",
454 out_signature="a{ss}",
455 async_callbacks=None,
456 )
287 def getEntityData(self, jid, keys, profile): 457 def getEntityData(self, jid, keys, profile):
288 return self._callback("getEntityData", unicode(jid), keys, unicode(profile)) 458 return self._callback("getEntityData", unicode(jid), keys, unicode(profile))
289 459
290 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 460 @dbus.service.method(
291 in_signature='s', out_signature='a{sa{ss}}', 461 const_INT_PREFIX + const_CORE_SUFFIX,
292 async_callbacks=('callback', 'errback')) 462 in_signature="s",
463 out_signature="a{sa{ss}}",
464 async_callbacks=("callback", "errback"),
465 )
293 def getFeatures(self, profile_key, callback=None, errback=None): 466 def getFeatures(self, profile_key, callback=None, errback=None):
294 return self._callback("getFeatures", unicode(profile_key), callback=callback, errback=errback) 467 return self._callback(
295 468 "getFeatures", unicode(profile_key), callback=callback, errback=errback
296 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 469 )
297 in_signature='ss', out_signature='s', 470
298 async_callbacks=None) 471 @dbus.service.method(
472 const_INT_PREFIX + const_CORE_SUFFIX,
473 in_signature="ss",
474 out_signature="s",
475 async_callbacks=None,
476 )
299 def getMainResource(self, contact_jid, profile_key="@DEFAULT@"): 477 def getMainResource(self, contact_jid, profile_key="@DEFAULT@"):
300 return self._callback("getMainResource", unicode(contact_jid), unicode(profile_key)) 478 return self._callback(
301 479 "getMainResource", unicode(contact_jid), unicode(profile_key)
302 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 480 )
303 in_signature='ssss', out_signature='s', 481
304 async_callbacks=None) 482 @dbus.service.method(
483 const_INT_PREFIX + const_CORE_SUFFIX,
484 in_signature="ssss",
485 out_signature="s",
486 async_callbacks=None,
487 )
305 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): 488 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
306 return self._callback("getParamA", unicode(name), unicode(category), unicode(attribute), unicode(profile_key)) 489 return self._callback(
307 490 "getParamA",
308 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 491 unicode(name),
309 in_signature='', out_signature='as', 492 unicode(category),
310 async_callbacks=None) 493 unicode(attribute),
311 def getParamsCategories(self, ): 494 unicode(profile_key),
312 return self._callback("getParamsCategories", ) 495 )
313 496
314 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 497 @dbus.service.method(
315 in_signature='iss', out_signature='s', 498 const_INT_PREFIX + const_CORE_SUFFIX,
316 async_callbacks=('callback', 'errback')) 499 in_signature="",
317 def getParamsUI(self, security_limit=-1, app='', profile_key="@DEFAULT@", callback=None, errback=None): 500 out_signature="as",
318 return self._callback("getParamsUI", security_limit, unicode(app), unicode(profile_key), callback=callback, errback=errback) 501 async_callbacks=None,
319 502 )
320 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 503 def getParamsCategories(self,):
321 in_signature='s', out_signature='a{sa{s(sia{ss})}}', 504 return self._callback("getParamsCategories")
322 async_callbacks=None) 505
506 @dbus.service.method(
507 const_INT_PREFIX + const_CORE_SUFFIX,
508 in_signature="iss",
509 out_signature="s",
510 async_callbacks=("callback", "errback"),
511 )
512 def getParamsUI(
513 self,
514 security_limit=-1,
515 app="",
516 profile_key="@DEFAULT@",
517 callback=None,
518 errback=None,
519 ):
520 return self._callback(
521 "getParamsUI",
522 security_limit,
523 unicode(app),
524 unicode(profile_key),
525 callback=callback,
526 errback=errback,
527 )
528
529 @dbus.service.method(
530 const_INT_PREFIX + const_CORE_SUFFIX,
531 in_signature="s",
532 out_signature="a{sa{s(sia{ss})}}",
533 async_callbacks=None,
534 )
323 def getPresenceStatuses(self, profile_key="@DEFAULT@"): 535 def getPresenceStatuses(self, profile_key="@DEFAULT@"):
324 return self._callback("getPresenceStatuses", unicode(profile_key)) 536 return self._callback("getPresenceStatuses", unicode(profile_key))
325 537
326 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 538 @dbus.service.method(
327 in_signature='', out_signature='', 539 const_INT_PREFIX + const_CORE_SUFFIX,
328 async_callbacks=('callback', 'errback')) 540 in_signature="",
541 out_signature="",
542 async_callbacks=("callback", "errback"),
543 )
329 def getReady(self, callback=None, errback=None): 544 def getReady(self, callback=None, errback=None):
330 return self._callback("getReady", callback=callback, errback=errback) 545 return self._callback("getReady", callback=callback, errback=errback)
331 546
332 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 547 @dbus.service.method(
333 in_signature='', out_signature='s', 548 const_INT_PREFIX + const_CORE_SUFFIX,
334 async_callbacks=None) 549 in_signature="",
335 def getVersion(self, ): 550 out_signature="s",
336 return self._callback("getVersion", ) 551 async_callbacks=None,
337 552 )
338 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 553 def getVersion(self,):
339 in_signature='s', out_signature='a{ss}', 554 return self._callback("getVersion")
340 async_callbacks=None) 555
556 @dbus.service.method(
557 const_INT_PREFIX + const_CORE_SUFFIX,
558 in_signature="s",
559 out_signature="a{ss}",
560 async_callbacks=None,
561 )
341 def getWaitingSub(self, profile_key="@DEFAULT@"): 562 def getWaitingSub(self, profile_key="@DEFAULT@"):
342 return self._callback("getWaitingSub", unicode(profile_key)) 563 return self._callback("getWaitingSub", unicode(profile_key))
343 564
344 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 565 @dbus.service.method(
345 in_signature='ssiba{ss}s', out_signature='a(sdssa{ss}a{ss}sa{ss})', 566 const_INT_PREFIX + const_CORE_SUFFIX,
346 async_callbacks=('callback', 'errback')) 567 in_signature="ssiba{ss}s",
347 def historyGet(self, from_jid, to_jid, limit, between=True, filters='', profile="@NONE@", callback=None, errback=None): 568 out_signature="a(sdssa{ss}a{ss}sa{ss})",
348 return self._callback("historyGet", unicode(from_jid), unicode(to_jid), limit, between, filters, unicode(profile), callback=callback, errback=errback) 569 async_callbacks=("callback", "errback"),
349 570 )
350 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 571 def historyGet(
351 in_signature='s', out_signature='b', 572 self,
352 async_callbacks=None) 573 from_jid,
574 to_jid,
575 limit,
576 between=True,
577 filters="",
578 profile="@NONE@",
579 callback=None,
580 errback=None,
581 ):
582 return self._callback(
583 "historyGet",
584 unicode(from_jid),
585 unicode(to_jid),
586 limit,
587 between,
588 filters,
589 unicode(profile),
590 callback=callback,
591 errback=errback,
592 )
593
594 @dbus.service.method(
595 const_INT_PREFIX + const_CORE_SUFFIX,
596 in_signature="s",
597 out_signature="b",
598 async_callbacks=None,
599 )
353 def isConnected(self, profile_key="@DEFAULT@"): 600 def isConnected(self, profile_key="@DEFAULT@"):
354 return self._callback("isConnected", unicode(profile_key)) 601 return self._callback("isConnected", unicode(profile_key))
355 602
356 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 603 @dbus.service.method(
357 in_signature='sa{ss}s', out_signature='a{ss}', 604 const_INT_PREFIX + const_CORE_SUFFIX,
358 async_callbacks=('callback', 'errback')) 605 in_signature="sa{ss}s",
359 def launchAction(self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None): 606 out_signature="a{ss}",
360 return self._callback("launchAction", unicode(callback_id), data, unicode(profile_key), callback=callback, errback=errback) 607 async_callbacks=("callback", "errback"),
361 608 )
362 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 609 def launchAction(
363 in_signature='s', out_signature='b', 610 self, callback_id, data, profile_key="@DEFAULT@", callback=None, errback=None
364 async_callbacks=None) 611 ):
612 return self._callback(
613 "launchAction",
614 unicode(callback_id),
615 data,
616 unicode(profile_key),
617 callback=callback,
618 errback=errback,
619 )
620
621 @dbus.service.method(
622 const_INT_PREFIX + const_CORE_SUFFIX,
623 in_signature="s",
624 out_signature="b",
625 async_callbacks=None,
626 )
365 def loadParamsTemplate(self, filename): 627 def loadParamsTemplate(self, filename):
366 return self._callback("loadParamsTemplate", unicode(filename)) 628 return self._callback("loadParamsTemplate", unicode(filename))
367 629
368 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 630 @dbus.service.method(
369 in_signature='ss', out_signature='s', 631 const_INT_PREFIX + const_CORE_SUFFIX,
370 async_callbacks=None) 632 in_signature="ss",
633 out_signature="s",
634 async_callbacks=None,
635 )
371 def menuHelpGet(self, menu_id, language): 636 def menuHelpGet(self, menu_id, language):
372 return self._callback("menuHelpGet", unicode(menu_id), unicode(language)) 637 return self._callback("menuHelpGet", unicode(menu_id), unicode(language))
373 638
374 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 639 @dbus.service.method(
375 in_signature='sasa{ss}is', out_signature='a{ss}', 640 const_INT_PREFIX + const_CORE_SUFFIX,
376 async_callbacks=('callback', 'errback')) 641 in_signature="sasa{ss}is",
377 def menuLaunch(self, menu_type, path, data, security_limit, profile_key, callback=None, errback=None): 642 out_signature="a{ss}",
378 return self._callback("menuLaunch", unicode(menu_type), path, data, security_limit, unicode(profile_key), callback=callback, errback=errback) 643 async_callbacks=("callback", "errback"),
379 644 )
380 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 645 def menuLaunch(
381 in_signature='si', out_signature='a(ssasasa{ss})', 646 self,
382 async_callbacks=None) 647 menu_type,
648 path,
649 data,
650 security_limit,
651 profile_key,
652 callback=None,
653 errback=None,
654 ):
655 return self._callback(
656 "menuLaunch",
657 unicode(menu_type),
658 path,
659 data,
660 security_limit,
661 unicode(profile_key),
662 callback=callback,
663 errback=errback,
664 )
665
666 @dbus.service.method(
667 const_INT_PREFIX + const_CORE_SUFFIX,
668 in_signature="si",
669 out_signature="a(ssasasa{ss})",
670 async_callbacks=None,
671 )
383 def menusGet(self, language, security_limit): 672 def menusGet(self, language, security_limit):
384 return self._callback("menusGet", unicode(language), security_limit) 673 return self._callback("menusGet", unicode(language), security_limit)
385 674
386 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 675 @dbus.service.method(
387 in_signature='sa{ss}a{ss}sa{ss}s', out_signature='', 676 const_INT_PREFIX + const_CORE_SUFFIX,
388 async_callbacks=('callback', 'errback')) 677 in_signature="sa{ss}a{ss}sa{ss}s",
389 def messageSend(self, to_jid, message, subject={}, mess_type="auto", extra={}, profile_key="@NONE@", callback=None, errback=None): 678 out_signature="",
390 return self._callback("messageSend", unicode(to_jid), message, subject, unicode(mess_type), extra, unicode(profile_key), callback=callback, errback=errback) 679 async_callbacks=("callback", "errback"),
391 680 )
392 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 681 def messageSend(
393 in_signature='', out_signature='a{ss}', 682 self,
394 async_callbacks=None) 683 to_jid,
395 def namespacesGet(self, ): 684 message,
396 return self._callback("namespacesGet", ) 685 subject={},
397 686 mess_type="auto",
398 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 687 extra={},
399 in_signature='sis', out_signature='', 688 profile_key="@NONE@",
400 async_callbacks=None) 689 callback=None,
401 def paramsRegisterApp(self, xml, security_limit=-1, app=''): 690 errback=None,
402 return self._callback("paramsRegisterApp", unicode(xml), security_limit, unicode(app)) 691 ):
403 692 return self._callback(
404 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 693 "messageSend",
405 in_signature='sss', out_signature='', 694 unicode(to_jid),
406 async_callbacks=('callback', 'errback')) 695 message,
407 def profileCreate(self, profile, password='', component='', callback=None, errback=None): 696 subject,
408 return self._callback("profileCreate", unicode(profile), unicode(password), unicode(component), callback=callback, errback=errback) 697 unicode(mess_type),
409 698 extra,
410 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 699 unicode(profile_key),
411 in_signature='s', out_signature='b', 700 callback=callback,
412 async_callbacks=None) 701 errback=errback,
702 )
703
704 @dbus.service.method(
705 const_INT_PREFIX + const_CORE_SUFFIX,
706 in_signature="",
707 out_signature="a{ss}",
708 async_callbacks=None,
709 )
710 def namespacesGet(self,):
711 return self._callback("namespacesGet")
712
713 @dbus.service.method(
714 const_INT_PREFIX + const_CORE_SUFFIX,
715 in_signature="sis",
716 out_signature="",
717 async_callbacks=None,
718 )
719 def paramsRegisterApp(self, xml, security_limit=-1, app=""):
720 return self._callback(
721 "paramsRegisterApp", unicode(xml), security_limit, unicode(app)
722 )
723
724 @dbus.service.method(
725 const_INT_PREFIX + const_CORE_SUFFIX,
726 in_signature="sss",
727 out_signature="",
728 async_callbacks=("callback", "errback"),
729 )
730 def profileCreate(
731 self, profile, password="", component="", callback=None, errback=None
732 ):
733 return self._callback(
734 "profileCreate",
735 unicode(profile),
736 unicode(password),
737 unicode(component),
738 callback=callback,
739 errback=errback,
740 )
741
742 @dbus.service.method(
743 const_INT_PREFIX + const_CORE_SUFFIX,
744 in_signature="s",
745 out_signature="b",
746 async_callbacks=None,
747 )
413 def profileIsSessionStarted(self, profile_key="@DEFAULT@"): 748 def profileIsSessionStarted(self, profile_key="@DEFAULT@"):
414 return self._callback("profileIsSessionStarted", unicode(profile_key)) 749 return self._callback("profileIsSessionStarted", unicode(profile_key))
415 750
416 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 751 @dbus.service.method(
417 in_signature='s', out_signature='s', 752 const_INT_PREFIX + const_CORE_SUFFIX,
418 async_callbacks=None) 753 in_signature="s",
754 out_signature="s",
755 async_callbacks=None,
756 )
419 def profileNameGet(self, profile_key="@DEFAULT@"): 757 def profileNameGet(self, profile_key="@DEFAULT@"):
420 return self._callback("profileNameGet", unicode(profile_key)) 758 return self._callback("profileNameGet", unicode(profile_key))
421 759
422 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 760 @dbus.service.method(
423 in_signature='s', out_signature='', 761 const_INT_PREFIX + const_CORE_SUFFIX,
424 async_callbacks=None) 762 in_signature="s",
763 out_signature="",
764 async_callbacks=None,
765 )
425 def profileSetDefault(self, profile): 766 def profileSetDefault(self, profile):
426 return self._callback("profileSetDefault", unicode(profile)) 767 return self._callback("profileSetDefault", unicode(profile))
427 768
428 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 769 @dbus.service.method(
429 in_signature='ss', out_signature='b', 770 const_INT_PREFIX + const_CORE_SUFFIX,
430 async_callbacks=('callback', 'errback')) 771 in_signature="ss",
431 def profileStartSession(self, password='', profile_key="@DEFAULT@", callback=None, errback=None): 772 out_signature="b",
432 return self._callback("profileStartSession", unicode(password), unicode(profile_key), callback=callback, errback=errback) 773 async_callbacks=("callback", "errback"),
433 774 )
434 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 775 def profileStartSession(
435 in_signature='bb', out_signature='as', 776 self, password="", profile_key="@DEFAULT@", callback=None, errback=None
436 async_callbacks=None) 777 ):
778 return self._callback(
779 "profileStartSession",
780 unicode(password),
781 unicode(profile_key),
782 callback=callback,
783 errback=errback,
784 )
785
786 @dbus.service.method(
787 const_INT_PREFIX + const_CORE_SUFFIX,
788 in_signature="bb",
789 out_signature="as",
790 async_callbacks=None,
791 )
437 def profilesListGet(self, clients=True, components=False): 792 def profilesListGet(self, clients=True, components=False):
438 return self._callback("profilesListGet", clients, components) 793 return self._callback("profilesListGet", clients, components)
439 794
440 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 795 @dbus.service.method(
441 in_signature='ss', out_signature='a{ss}', 796 const_INT_PREFIX + const_CORE_SUFFIX,
442 async_callbacks=None) 797 in_signature="ss",
798 out_signature="a{ss}",
799 async_callbacks=None,
800 )
443 def progressGet(self, id, profile): 801 def progressGet(self, id, profile):
444 return self._callback("progressGet", unicode(id), unicode(profile)) 802 return self._callback("progressGet", unicode(id), unicode(profile))
445 803
446 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 804 @dbus.service.method(
447 in_signature='s', out_signature='a{sa{sa{ss}}}', 805 const_INT_PREFIX + const_CORE_SUFFIX,
448 async_callbacks=None) 806 in_signature="s",
807 out_signature="a{sa{sa{ss}}}",
808 async_callbacks=None,
809 )
449 def progressGetAll(self, profile): 810 def progressGetAll(self, profile):
450 return self._callback("progressGetAll", unicode(profile)) 811 return self._callback("progressGetAll", unicode(profile))
451 812
452 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 813 @dbus.service.method(
453 in_signature='s', out_signature='a{sa{sa{ss}}}', 814 const_INT_PREFIX + const_CORE_SUFFIX,
454 async_callbacks=None) 815 in_signature="s",
816 out_signature="a{sa{sa{ss}}}",
817 async_callbacks=None,
818 )
455 def progressGetAllMetadata(self, profile): 819 def progressGetAllMetadata(self, profile):
456 return self._callback("progressGetAllMetadata", unicode(profile)) 820 return self._callback("progressGetAllMetadata", unicode(profile))
457 821
458 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 822 @dbus.service.method(
459 in_signature='s', out_signature='b', 823 const_INT_PREFIX + const_CORE_SUFFIX,
460 async_callbacks=None) 824 in_signature="s",
825 out_signature="b",
826 async_callbacks=None,
827 )
461 def saveParamsTemplate(self, filename): 828 def saveParamsTemplate(self, filename):
462 return self._callback("saveParamsTemplate", unicode(filename)) 829 return self._callback("saveParamsTemplate", unicode(filename))
463 830
464 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 831 @dbus.service.method(
465 in_signature='s', out_signature='a{ss}', 832 const_INT_PREFIX + const_CORE_SUFFIX,
466 async_callbacks=('callback', 'errback')) 833 in_signature="s",
834 out_signature="a{ss}",
835 async_callbacks=("callback", "errback"),
836 )
467 def sessionInfosGet(self, profile_key, callback=None, errback=None): 837 def sessionInfosGet(self, profile_key, callback=None, errback=None):
468 return self._callback("sessionInfosGet", unicode(profile_key), callback=callback, errback=errback) 838 return self._callback(
469 839 "sessionInfosGet", unicode(profile_key), callback=callback, errback=errback
470 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 840 )
471 in_signature='sssis', out_signature='', 841
472 async_callbacks=None) 842 @dbus.service.method(
843 const_INT_PREFIX + const_CORE_SUFFIX,
844 in_signature="sssis",
845 out_signature="",
846 async_callbacks=None,
847 )
473 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"): 848 def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
474 return self._callback("setParam", unicode(name), unicode(value), unicode(category), security_limit, unicode(profile_key)) 849 return self._callback(
475 850 "setParam",
476 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 851 unicode(name),
477 in_signature='ssa{ss}s', out_signature='', 852 unicode(value),
478 async_callbacks=None) 853 unicode(category),
479 def setPresence(self, to_jid='', show='', statuses={}, profile_key="@DEFAULT@"): 854 security_limit,
480 return self._callback("setPresence", unicode(to_jid), unicode(show), statuses, unicode(profile_key)) 855 unicode(profile_key),
481 856 )
482 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 857
483 in_signature='sss', out_signature='', 858 @dbus.service.method(
484 async_callbacks=None) 859 const_INT_PREFIX + const_CORE_SUFFIX,
860 in_signature="ssa{ss}s",
861 out_signature="",
862 async_callbacks=None,
863 )
864 def setPresence(self, to_jid="", show="", statuses={}, profile_key="@DEFAULT@"):
865 return self._callback(
866 "setPresence", unicode(to_jid), unicode(show), statuses, unicode(profile_key)
867 )
868
869 @dbus.service.method(
870 const_INT_PREFIX + const_CORE_SUFFIX,
871 in_signature="sss",
872 out_signature="",
873 async_callbacks=None,
874 )
485 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): 875 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"):
486 return self._callback("subscription", unicode(sub_type), unicode(entity), unicode(profile_key)) 876 return self._callback(
487 877 "subscription", unicode(sub_type), unicode(entity), unicode(profile_key)
488 @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX, 878 )
489 in_signature='ssass', out_signature='', 879
490 async_callbacks=('callback', 'errback')) 880 @dbus.service.method(
491 def updateContact(self, entity_jid, name, groups, profile_key="@DEFAULT@", callback=None, errback=None): 881 const_INT_PREFIX + const_CORE_SUFFIX,
492 return self._callback("updateContact", unicode(entity_jid), unicode(name), groups, unicode(profile_key), callback=callback, errback=errback) 882 in_signature="ssass",
883 out_signature="",
884 async_callbacks=("callback", "errback"),
885 )
886 def updateContact(
887 self,
888 entity_jid,
889 name,
890 groups,
891 profile_key="@DEFAULT@",
892 callback=None,
893 errback=None,
894 ):
895 return self._callback(
896 "updateContact",
897 unicode(entity_jid),
898 unicode(name),
899 groups,
900 unicode(profile_key),
901 callback=callback,
902 errback=errback,
903 )
493 904
494 def __attributes(self, in_sign): 905 def __attributes(self, in_sign):
495 """Return arguments to user given a in_sign 906 """Return arguments to user given a in_sign
496 @param in_sign: in_sign in the short form (using s,a,i,b etc) 907 @param in_sign: in_sign in the short form (using s,a,i,b etc)
497 @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")""" 908 @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")"""
498 i = 0 909 i = 0
499 idx = 0 910 idx = 0
500 attr = [] 911 attr = []
501 while i < len(in_sign): 912 while i < len(in_sign):
502 if in_sign[i] not in ['b', 'y', 'n', 'i', 'x', 'q', 'u', 't', 'd', 's', 'a']: 913 if in_sign[i] not in ["b", "y", "n", "i", "x", "q", "u", "t", "d", "s", "a"]:
503 raise ParseError("Unmanaged attribute type [%c]" % in_sign[i]) 914 raise ParseError("Unmanaged attribute type [%c]" % in_sign[i])
504 915
505 attr.append("arg_%i" % idx) 916 attr.append("arg_%i" % idx)
506 idx += 1 917 idx += 1
507 918
508 if in_sign[i] == 'a': 919 if in_sign[i] == "a":
509 i += 1 920 i += 1
510 if in_sign[i] != '{' and in_sign[i] != '(': # FIXME: must manage tuples out of arrays 921 if (
922 in_sign[i] != "{" and in_sign[i] != "("
923 ): # FIXME: must manage tuples out of arrays
511 i += 1 924 i += 1
512 continue # we have a simple type for the array 925 continue # we have a simple type for the array
513 opening_car = in_sign[i] 926 opening_car = in_sign[i]
514 assert(opening_car in ['{', '(']) 927 assert opening_car in ["{", "("]
515 closing_car = '}' if opening_car == '{' else ')' 928 closing_car = "}" if opening_car == "{" else ")"
516 opening_count = 1 929 opening_count = 1
517 while (True): # we have a dict or a list of tuples 930 while True: # we have a dict or a list of tuples
518 i += 1 931 i += 1
519 if i >= len(in_sign): 932 if i >= len(in_sign):
520 raise ParseError("missing }") 933 raise ParseError("missing }")
521 if in_sign[i] == opening_car: 934 if in_sign[i] == opening_car:
522 opening_count += 1 935 opening_count += 1
533 946
534 _arguments = inspect_args.args 947 _arguments = inspect_args.args
535 _defaults = list(inspect_args.defaults or []) 948 _defaults = list(inspect_args.defaults or [])
536 949
537 if inspect.ismethod(method): 950 if inspect.ismethod(method):
538 #if we have a method, we don't want the first argument (usually 'self') 951 # if we have a method, we don't want the first argument (usually 'self')
539 del(_arguments[0]) 952 del (_arguments[0])
540 953
541 #first arguments are for the _callback method 954 # first arguments are for the _callback method
542 arguments_callback = ', '.join([repr(name)] + ((_arguments + ['callback=callback', 'errback=errback']) if async else _arguments)) 955 arguments_callback = ", ".join(
956 [repr(name)]
957 + (
958 (_arguments + ["callback=callback", "errback=errback"])
959 if async
960 else _arguments
961 )
962 )
543 963
544 if async: 964 if async:
545 _arguments.extend(['callback', 'errback']) 965 _arguments.extend(["callback", "errback"])
546 _defaults.extend([None, None]) 966 _defaults.extend([None, None])
547 967
548 #now we create a second list with default values 968 # now we create a second list with default values
549 for i in range(1, len(_defaults) + 1): 969 for i in range(1, len(_defaults) + 1):
550 _arguments[-i] = "%s = %s" % (_arguments[-i], repr(_defaults[-i])) 970 _arguments[-i] = "%s = %s" % (_arguments[-i], repr(_defaults[-i]))
551 971
552 arguments_defaults = ', '.join(_arguments) 972 arguments_defaults = ", ".join(_arguments)
553 973
554 code = compile('def %(name)s (self,%(arguments_defaults)s): return self._callback(%(arguments_callback)s)' % 974 code = compile(
555 {'name': name, 'arguments_defaults': arguments_defaults, 'arguments_callback': arguments_callback}, '<DBus bridge>', 'exec') 975 "def %(name)s (self,%(arguments_defaults)s): return self._callback(%(arguments_callback)s)"
556 exec (code) # FIXME: to the same thing in a cleaner way, without compile/exec 976 % {
977 "name": name,
978 "arguments_defaults": arguments_defaults,
979 "arguments_callback": arguments_callback,
980 },
981 "<DBus bridge>",
982 "exec",
983 )
984 exec(code) # FIXME: to the same thing in a cleaner way, without compile/exec
557 method = locals()[name] 985 method = locals()[name]
558 async_callbacks = ('callback', 'errback') if async else None 986 async_callbacks = ("callback", "errback") if async else None
559 setattr(DbusObject, name, dbus.service.method( 987 setattr(
560 const_INT_PREFIX + int_suffix, in_signature=in_sign, out_signature=out_sign, 988 DbusObject,
561 async_callbacks=async_callbacks)(method)) 989 name,
990 dbus.service.method(
991 const_INT_PREFIX + int_suffix,
992 in_signature=in_sign,
993 out_signature=out_sign,
994 async_callbacks=async_callbacks,
995 )(method),
996 )
562 function = getattr(self, name) 997 function = getattr(self, name)
563 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface] 998 func_table = self._dbus_class_table[
999 self.__class__.__module__ + "." + self.__class__.__name__
1000 ][function._dbus_interface]
564 func_table[function.__name__] = function # Needed for introspection 1001 func_table[function.__name__] = function # Needed for introspection
565 1002
566 def addSignal(self, name, int_suffix, signature, doc={}): 1003 def addSignal(self, name, int_suffix, signature, doc={}):
567 """Dynamically add a signal to Dbus Bridge""" 1004 """Dynamically add a signal to Dbus Bridge"""
568 attributes = ', '.join(self.__attributes(signature)) 1005 attributes = ", ".join(self.__attributes(signature))
569 #TODO: use doc parameter to name attributes 1006 # TODO: use doc parameter to name attributes
570 1007
571 #code = compile ('def '+name+' (self,'+attributes+'): log.debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the log.debug is too annoying with xmllog 1008 # code = compile ('def '+name+' (self,'+attributes+'): log.debug ("'+name+' signal")', '<DBus bridge>','exec') #XXX: the log.debug is too annoying with xmllog
572 code = compile('def ' + name + ' (self,' + attributes + '): pass', '<DBus bridge>', 'exec') 1009 code = compile(
573 exec (code) 1010 "def " + name + " (self," + attributes + "): pass", "<DBus bridge>", "exec"
1011 )
1012 exec(code)
574 signal = locals()[name] 1013 signal = locals()[name]
575 setattr(DbusObject, name, dbus.service.signal( 1014 setattr(
576 const_INT_PREFIX + int_suffix, signature=signature)(signal)) 1015 DbusObject,
1016 name,
1017 dbus.service.signal(const_INT_PREFIX + int_suffix, signature=signature)(
1018 signal
1019 ),
1020 )
577 function = getattr(self, name) 1021 function = getattr(self, name)
578 func_table = self._dbus_class_table[self.__class__.__module__ + '.' + self.__class__.__name__][function._dbus_interface] 1022 func_table = self._dbus_class_table[
1023 self.__class__.__module__ + "." + self.__class__.__name__
1024 ][function._dbus_interface]
579 func_table[function.__name__] = function # Needed for introspection 1025 func_table[function.__name__] = function # Needed for introspection
580 1026
581 1027
582 class Bridge(object): 1028 class Bridge(object):
583 def __init__(self): 1029 def __init__(self):
584 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 1030 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
585 log.info("Init DBus...") 1031 log.info("Init DBus...")
586 try: 1032 try:
587 self.session_bus = dbus.SessionBus() 1033 self.session_bus = dbus.SessionBus()
588 except dbus.DBusException as e: 1034 except dbus.DBusException as e:
589 if e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported': 1035 if e._dbus_error_name == "org.freedesktop.DBus.Error.NotSupported":
590 log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it")) 1036 log.error(
1037 _(
1038 u"D-Bus is not launched, please see README to see instructions on how to launch it"
1039 )
1040 )
591 raise BridgeInitError 1041 raise BridgeInitError
592 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) 1042 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
593 self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH) 1043 self.dbus_bridge = DbusObject(self.session_bus, const_OBJ_PATH)
594 1044
595 def actionNew(self, action_data, id, security_limit, profile): 1045 def actionNew(self, action_data, id, security_limit, profile):
605 self.dbus_bridge.disconnected(profile) 1055 self.dbus_bridge.disconnected(profile)
606 1056
607 def entityDataUpdated(self, jid, name, value, profile): 1057 def entityDataUpdated(self, jid, name, value, profile):
608 self.dbus_bridge.entityDataUpdated(jid, name, value, profile) 1058 self.dbus_bridge.entityDataUpdated(jid, name, value, profile)
609 1059
610 def messageNew(self, uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile): 1060 def messageNew(
611 self.dbus_bridge.messageNew(uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile) 1061 self,
1062 uid,
1063 timestamp,
1064 from_jid,
1065 to_jid,
1066 message,
1067 subject,
1068 mess_type,
1069 extra,
1070 profile,
1071 ):
1072 self.dbus_bridge.messageNew(
1073 uid, timestamp, from_jid, to_jid, message, subject, mess_type, extra, profile
1074 )
612 1075
613 def newContact(self, contact_jid, attributes, groups, profile): 1076 def newContact(self, contact_jid, attributes, groups, profile):
614 self.dbus_bridge.newContact(contact_jid, attributes, groups, profile) 1077 self.dbus_bridge.newContact(contact_jid, attributes, groups, profile)
615 1078
616 def paramUpdate(self, name, value, category, profile): 1079 def paramUpdate(self, name, value, category, profile):
635 log.debug("registering DBus bridge method [%s]" % name) 1098 log.debug("registering DBus bridge method [%s]" % name)
636 self.dbus_bridge.register_method(name, callback) 1099 self.dbus_bridge.register_method(name, callback)
637 1100
638 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}): 1101 def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
639 """Dynamically add a method to Dbus Bridge""" 1102 """Dynamically add a method to Dbus Bridge"""
640 #FIXME: doc parameter is kept only temporary, the time to remove it from calls 1103 # FIXME: doc parameter is kept only temporary, the time to remove it from calls
641 log.debug("Adding method [%s] to DBus bridge" % name) 1104 log.debug("Adding method [%s] to DBus bridge" % name)
642 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async) 1105 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async)
643 self.register_method(name, method) 1106 self.register_method(name, method)
644 1107
645 def addSignal(self, name, int_suffix, signature, doc={}): 1108 def addSignal(self, name, int_suffix, signature, doc={}):