[hook] proper bad .events detection. Fix unittest_hook
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 06 Apr 2010 19:58:04 +0200
changeset 5160 27d4cab5db03
parent 5159 2543cfa5d54a
child 5161 a19f22bacedc
[hook] proper bad .events detection. Fix unittest_hook
server/hook.py
--- a/server/hook.py	Tue Apr 06 19:08:07 2010 +0200
+++ b/server/hook.py	Tue Apr 06 19:58:04 2010 +0200
@@ -75,10 +75,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):
@@ -199,10 +196,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, obj.__module__, obj.__name__))
         except AttributeError:
             raise
         except TypeError:
@@ -210,6 +210,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)