aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/utils/tracking/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'debug_toolbar/utils/tracking/__init__.py')
-rw-r--r--debug_toolbar/utils/tracking/__init__.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/debug_toolbar/utils/tracking/__init__.py b/debug_toolbar/utils/tracking/__init__.py
index db8ff18..9c72803 100644
--- a/debug_toolbar/utils/tracking/__init__.py
+++ b/debug_toolbar/utils/tracking/__init__.py
@@ -2,18 +2,21 @@ import logging
import time
import types
+
def post_dispatch(func):
def wrapped(callback):
register_hook(func, 'after', callback)
return callback
return wrapped
+
def pre_dispatch(func):
def wrapped(callback):
register_hook(func, 'before', callback)
return callback
return wrapped
+
def replace_call(func):
def inner(callback):
def wrapped(*args, **kwargs):
@@ -28,6 +31,7 @@ def replace_call(func):
return wrapped
return inner
+
def fire_hook(hook, sender, **kwargs):
try:
for callback in callbacks[hook].get(id(sender), []):
@@ -36,6 +40,7 @@ def fire_hook(hook, sender, **kwargs):
# Log the exception, dont mess w/ the underlying function
logging.exception(e)
+
def _replace_function(func, wrapped):
if isinstance(func, types.FunctionType):
if func.__module__ == '__builtin__':
@@ -58,6 +63,7 @@ callbacks = {
'after': {},
}
+
def register_hook(func, hook, callback):
"""
def myhook(sender, args, kwargs):
@@ -81,10 +87,10 @@ def register_hook(func, hook, callback):
wrapped.__wrapped__ = actual
wrapped.__doc__ = getattr(actual, '__doc__', None)
wrapped.__name__ = actual.__name__
-
+
id_ = id(actual)
if id_ not in callbacks[hook]:
callbacks[hook][id_] = []
callbacks[hook][id_].append(callback)
- _replace_function(func, wrapped) \ No newline at end of file
+ _replace_function(func, wrapped)