21 lines
480 B
Python
21 lines
480 B
Python
_hook_dict = {}
|
|
|
|
|
|
class Hook(object):
|
|
def __init__(self, function):
|
|
self.function = function
|
|
|
|
def __call__(self, *args, **kwargs):
|
|
if self.function.__name__ in _hook_dict:
|
|
_hook_dict[self.function.__name__](*args, **kwargs)
|
|
self.function(*args, **kwargs)
|
|
|
|
|
|
class HookCall(object):
|
|
def __init__(self, name):
|
|
self.name = name
|
|
|
|
def __call__(self, function):
|
|
_hook_dict[self.name] = function
|
|
return function
|