88 """unregister a function to call when <event> occurs, or a Hook subclass. |
88 """unregister a function to call when <event> occurs, or a Hook subclass. |
89 In the later case, event/type information are extracted from the given |
89 In the later case, event/type information are extracted from the given |
90 class. |
90 class. |
91 """ |
91 """ |
92 if isinstance(function_or_cls, type) and issubclass(function_or_cls, Hook): |
92 if isinstance(function_or_cls, type) and issubclass(function_or_cls, Hook): |
93 for event, ertype in function_or_cls.register_to(): |
93 for event, ertype in function_or_cls.register_to(self.schema): |
94 for hook in self._hooks[event][ertype]: |
94 for hook in self._hooks[event][ertype]: |
95 if getattr(hook, 'im_self', None).__class__ is function_or_cls: |
95 if getattr(hook, 'im_self', None).__class__ is function_or_cls: |
96 self._hooks[event][ertype].remove(hook) |
96 self._hooks[event][ertype].remove(hook) |
97 self.info('unregister hook %s on %s (%s)', event, etype, |
97 self.info('unregister hook %s on %s (%s)', event, etype, |
98 function_or_cls.__name__) |
98 function_or_cls.__name__) |
220 def registered(cls, vreg): |
220 def registered(cls, vreg): |
221 super(Hook, cls).registered(vreg) |
221 super(Hook, cls).registered(vreg) |
222 return cls() |
222 return cls() |
223 |
223 |
224 @classmethod |
224 @classmethod |
225 def register_to(cls): |
225 def register_to(cls, schema): |
226 if not cls.enabled: |
226 if not cls.enabled: |
227 cls.warning('%s hook has been disabled', cls) |
227 cls.warning('%s hook has been disabled', cls) |
228 return |
228 return |
229 done = set() |
229 done = set() |
230 assert isinstance(cls.events, (tuple, list)), \ |
230 assert isinstance(cls.events, (tuple, list)), \ |