comparison frontends/src/bridge/DBus.py @ 595:1f160467f5de

Fix pep8 support in src/bridge.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:35 +0100
parents 952322b1d490
children 84a6e83157c2
comparison
equal deleted inserted replaced
594:e629371a28d3 595:1f160467f5de
24 from logging import debug, error 24 from logging import debug, error
25 25
26 from dbus.mainloop.glib import DBusGMainLoop 26 from dbus.mainloop.glib import DBusGMainLoop
27 DBusGMainLoop(set_as_default=True) 27 DBusGMainLoop(set_as_default=True)
28 28
29 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix 29 const_INT_PREFIX = "org.goffi.SAT" # Interface prefix
30 const_ERROR_PREFIX = const_INT_PREFIX+".error" 30 const_ERROR_PREFIX = const_INT_PREFIX + ".error"
31 const_OBJ_PATH = '/org/goffi/SAT/bridge' 31 const_OBJ_PATH = '/org/goffi/SAT/bridge'
32 const_CORE_SUFFIX = ".core" 32 const_CORE_SUFFIX = ".core"
33 const_PLUGIN_SUFFIX = ".plugin" 33 const_PLUGIN_SUFFIX = ".plugin"
34 34
35
35 class BridgeExceptionNoService(Exception): 36 class BridgeExceptionNoService(Exception):
36 pass 37 pass
38
37 39
38 class DBusBridgeFrontend(BridgeFrontend): 40 class DBusBridgeFrontend(BridgeFrontend):
39 def __init__(self): 41 def __init__(self):
40 try: 42 try:
41 self.sessions_bus = dbus.SessionBus() 43 self.sessions_bus = dbus.SessionBus()
42 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, 44 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX,
43 const_OBJ_PATH) 45 const_OBJ_PATH)
44 self.db_core_iface = dbus.Interface(self.db_object, 46 self.db_core_iface = dbus.Interface(self.db_object,
45 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX) 47 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX)
46 self.db_plugin_iface = dbus.Interface(self.db_object, 48 self.db_plugin_iface = dbus.Interface(self.db_object,
47 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX) 49 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX)
48 except dbus.exceptions.DBusException,e: 50 except dbus.exceptions.DBusException, e:
49 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': 51 if e._dbus_error_name == 'org.freedesktop.DBus.Error.ServiceUnknown':
50 raise BridgeExceptionNoService 52 raise BridgeExceptionNoService
51 else: 53 else:
52 raise e 54 raise e
53 #props = self.db_core_iface.getProperties() 55 #props = self.db_core_iface.getProperties()
54 56
77 if kwargs: 79 if kwargs:
78 if 'callback' in kwargs and 'errback' in kwargs: 80 if 'callback' in kwargs and 'errback' in kwargs:
79 async = True 81 async = True
80 _callback = kwargs.pop('callback') 82 _callback = kwargs.pop('callback')
81 _errback = kwargs.pop('errback') 83 _errback = kwargs.pop('errback')
82 elif len(args)>=2 and callable(args[-1]) and callable(args[-2]): 84 elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
83 async = True 85 async = True
84 args = list(args) 86 args = list(args)
85 _errback = args.pop() 87 _errback = args.pop()
86 _callback = args.pop() 88 _callback = args.pop()
87 89
88 method = getattr(self.db_plugin_iface, name) 90 method = getattr(self.db_plugin_iface, name)
89 91
90 if async: 92 if async:
91 kwargs['reply_handler'] = _callback 93 kwargs['reply_handler'] = _callback
92 kwargs['error_handler'] = lambda err:_errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]) 94 kwargs['error_handler'] = lambda err: _errback(err._dbus_error_name[len(const_ERROR_PREFIX) + 1:])
93 95
94 return method(*args, **kwargs) 96 return method(*args, **kwargs)
95 97
96 return getPluginMethod 98 return getPluginMethod
97
98 def addContact(self, entity_jid, profile_key="@DEFAULT@"): 99 def addContact(self, entity_jid, profile_key="@DEFAULT@"):
99 return self.db_core_iface.addContact(entity_jid, profile_key) 100 return self.db_core_iface.addContact(entity_jid, profile_key)
100 101
101 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None): 102 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
102 return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])) 103 return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
214 215
215 216
216 #methods from plugins 217 #methods from plugins
217 218
218 def joinMUC(self, room_jid, nick, options, profile_key): 219 def joinMUC(self, room_jid, nick, options, profile_key):
219 if options == None: 220 if options is None:
220 options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 221 options = [('', '')] # XXX: we have to do this awful hack because python dbus need to guess the signature
221 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key) 222 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
222 223
223 def gatewayRegister(self, action, target, data, profile_key): 224 def gatewayRegister(self, action, target, data, profile_key):
224 if data == None: 225 if data is None:
225 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 226 data = [('', '')] # XXX: we have to do this awful hack because python dbus need to guess the signature
226 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key) 227 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)