server/hook.py
changeset 5160 27d4cab5db03
parent 5116 a2ce436e00ad
child 5162 6340ed9f8caf
equal deleted inserted replaced
5159:2543cfa5d54a 5160:27d4cab5db03
    73                 if not cls.enabled:
    73                 if not cls.enabled:
    74                     warn('[3.6] %s: enabled is deprecated' % cls)
    74                     warn('[3.6] %s: enabled is deprecated' % cls)
    75                     self.unregister(cls)
    75                     self.unregister(cls)
    76 
    76 
    77     def register(self, obj, **kwargs):
    77     def register(self, obj, **kwargs):
    78         for event in obj.events:
    78         obj.check_events()
    79             if event not in ALL_HOOKS:
       
    80                 raise Exception('bad event %s on %s.%s' % (
       
    81                     event, obj.__module__, obj.__name__))
       
    82         super(HooksRegistry, self).register(obj, **kwargs)
    79         super(HooksRegistry, self).register(obj, **kwargs)
    83 
    80 
    84     def call_hooks(self, event, session=None, **kwargs):
    81     def call_hooks(self, event, session=None, **kwargs):
    85         kwargs['event'] = event
    82         kwargs['event'] = event
    86         if session is None:
    83         if session is None:
   197     category = None
   194     category = None
   198     order = 0
   195     order = 0
   199     # XXX deprecated
   196     # XXX deprecated
   200     enabled = True
   197     enabled = True
   201 
   198 
   202     @classproperty
   199     @classmethod
   203     def __registries__(cls):
   200     def check_events(cls):
   204         try:
   201         try:
   205             return ['%s_hooks' % ev for ev in cls.events]
   202             for event in cls.events:
       
   203                 if event not in ALL_HOOKS:
       
   204                     raise Exception('bad event %s on %s.%s' % (
       
   205                         event, obj.__module__, obj.__name__))
   206         except AttributeError:
   206         except AttributeError:
   207             raise
   207             raise
   208         except TypeError:
   208         except TypeError:
   209             raise Exception('bad .events attribute %s on %s.%s' % (
   209             raise Exception('bad .events attribute %s on %s.%s' % (
   210                 cls.events, cls.__module__, cls.__name__))
   210                 cls.events, cls.__module__, cls.__name__))
       
   211 
       
   212     @classproperty
       
   213     def __registries__(cls):
       
   214         cls.check_events()
       
   215         return ['%s_hooks' % ev for ev in cls.events]
   211 
   216 
   212     @classproperty
   217     @classproperty
   213     def __regid__(cls):
   218     def __regid__(cls):
   214         warn('[3.6] %s.%s: please specify an id for your hook'
   219         warn('[3.6] %s.%s: please specify an id for your hook'
   215              % (cls.__module__, cls.__name__), DeprecationWarning)
   220              % (cls.__module__, cls.__name__), DeprecationWarning)