[hook] backport bad .events fix from default stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 15 Apr 2010 16:46:43 +0200
branchstable
changeset 5287 6346f1fd0a50
parent 5286 43d7044f8d0b
child 5288 92e9efc8cad5
[hook] backport bad .events fix from default
server/hook.py
--- a/server/hook.py	Thu Apr 15 16:20:53 2010 +0200
+++ b/server/hook.py	Thu Apr 15 16:46:43 2010 +0200
@@ -74,10 +74,7 @@
                     self.unregister(cls)
 
     def register(self, obj, **kwargs):
-        for event in obj.events:
-            if event not in ALL_HOOKS:
-                raise Exception('bad event %s on %s.%s' % (
-                    event, obj.__module__, obj.__name__))
+        obj.check_events()
         super(HooksRegistry, self).register(obj, **kwargs)
 
     def call_hooks(self, event, session=None, **kwargs):
@@ -198,10 +195,13 @@
     # XXX deprecated
     enabled = True
 
-    @classproperty
-    def __registries__(cls):
+    @classmethod
+    def check_events(cls):
         try:
-            return ['%s_hooks' % ev for ev in cls.events]
+            for event in cls.events:
+                if event not in ALL_HOOKS:
+                    raise Exception('bad event %s on %s.%s' % (
+                        event, cls.__module__, cls.__name__))
         except AttributeError:
             raise
         except TypeError:
@@ -209,6 +209,11 @@
                 cls.events, cls.__module__, cls.__name__))
 
     @classproperty
+    def __registries__(cls):
+        cls.check_events()
+        return ['%s_hooks' % ev for ev in cls.events]
+
+    @classproperty
     def __regid__(cls):
         warn('[3.6] %s.%s: please specify an id for your hook'
              % (cls.__module__, cls.__name__), DeprecationWarning)