comparison src/bridge/bridge_constructor/dbus_frontend_template.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 ##METHODS_PART## 99 ##METHODS_PART##
99 100
100 #methods from plugins 101 #methods from plugins
101 102
102 def joinMUC(self, room_jid, nick, options, profile_key): 103 def joinMUC(self, room_jid, nick, options, profile_key):
103 if options == None: 104 if options is None:
104 options = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 105 options = [('', '')] # XXX: we have to do this awful hack because python dbus need to guess the signature
105 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key) 106 return self.db_plugin_iface.joinMUC(room_jid, nick, options, profile_key)
106 107
107 def gatewayRegister(self, action, target, data, profile_key): 108 def gatewayRegister(self, action, target, data, profile_key):
108 if data == None: 109 if data is None:
109 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 110 data = [('', '')] # XXX: we have to do this awful hack because python dbus need to guess the signature
110 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key) 111 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)