changeset 424:72c13313b6d6

bridge: added check that synchronous method does not return a deferred
author Goffi <goffi@goffi.org>
date Mon, 07 Nov 2011 22:27:07 +0100
parents 6c20c76abdcc
children e4e9187e3b5b
files src/bridge/DBus.py src/bridge/bridge_constructor/dbus_core_template.py
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/bridge/DBus.py	Mon Nov 07 00:09:22 2011 +0100
+++ b/src/bridge/DBus.py	Mon Nov 07 22:27:07 2011 +0100
@@ -42,6 +42,9 @@
 class AsyncNotDeferred(dbus.DBusException):
     _dbus_error_name = const_ERROR_PREFIX + ".AsyncNotDeferred"
 
+class DeferredNotAsync(dbus.DBusException):
+    _dbus_error_name = const_ERROR_PREFIX + ".DeferredNotAsync"
+
 class GenericException(dbus.DBusException):
     def __init__(self, twisted_error):
         super(GenericException,self).__init__()
@@ -82,6 +85,9 @@
             result.addCallback(callback)
             result.addErrback(lambda err:errback(GenericException(err)))
         else:
+            if isinstance(result, Deferred):
+                error("Synchrone method [%s] return a Deferred." % name)
+                raise DeferredNotAsync
             return result
 
     ### signals ###    
--- a/src/bridge/bridge_constructor/dbus_core_template.py	Mon Nov 07 00:09:22 2011 +0100
+++ b/src/bridge/bridge_constructor/dbus_core_template.py	Mon Nov 07 22:27:07 2011 +0100
@@ -42,6 +42,9 @@
 class AsyncNotDeferred(dbus.DBusException):
     _dbus_error_name = const_ERROR_PREFIX + ".AsyncNotDeferred"
 
+class DeferredNotAsync(dbus.DBusException):
+    _dbus_error_name = const_ERROR_PREFIX + ".DeferredNotAsync"
+
 class GenericException(dbus.DBusException):
     def __init__(self, twisted_error):
         super(GenericException,self).__init__()
@@ -82,6 +85,9 @@
             result.addCallback(callback)
             result.addErrback(lambda err:errback(GenericException(err)))
         else:
+            if isinstance(result, Deferred):
+                error("Synchrone method [%s] return a Deferred." % name)
+                raise DeferredNotAsync
             return result
 
     ### signals ###