aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar/utils/tracking/__init__.py
diff options
context:
space:
mode:
authorAymeric Augustin2013-10-17 10:22:32 +0200
committerAymeric Augustin2013-10-17 18:24:58 +0200
commitafe4b10accc92672a7ea01ab4a04e602fd7f8566 (patch)
tree0dc6b03ddf3904800f34d4c9a222b330f86e843c /debug_toolbar/utils/tracking/__init__.py
parent1bf828463dfc48ea09409ae2c91176d5fb0d38c7 (diff)
downloaddjango-debug-toolbar-afe4b10accc92672a7ea01ab4a04e602fd7f8566.tar.bz2
Remove dead code.
These features were still tested, but they weren't used anywhere.
Diffstat (limited to 'debug_toolbar/utils/tracking/__init__.py')
-rw-r--r--debug_toolbar/utils/tracking/__init__.py77
1 files changed, 0 insertions, 77 deletions
diff --git a/debug_toolbar/utils/tracking/__init__.py b/debug_toolbar/utils/tracking/__init__.py
index 166b1b5..420de1e 100644
--- a/debug_toolbar/utils/tracking/__init__.py
+++ b/debug_toolbar/utils/tracking/__init__.py
@@ -6,20 +6,6 @@ import types
from django.utils.importlib import import_module
-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_method(klass, method_name):
original = getattr(klass, method_name)
@@ -36,66 +22,3 @@ def replace_method(klass, method_name):
return wrapped
return inner
-
-
-def fire_hook(hook, sender, **kwargs):
- try:
- for callback in callbacks[hook].get(id(sender), []):
- callback(sender=sender, **kwargs)
- except Exception as e:
- # 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__':
- # oh shit
- __builtins__[func] = wrapped
- else:
- module = import_module(func.__module__)
- setattr(module, func.__name__, wrapped)
- elif getattr(func, '__self__', None):
- setattr(func.__self__, func.__name__, classmethod(wrapped))
- elif hasattr(func, 'im_class'):
- # for unbound methods - Python 2 only
- setattr(func.im_class, func.__name__, wrapped)
- else:
- raise NotImplementedError
-
-callbacks = {
- 'before': {},
- 'after': {},
-}
-
-
-def register_hook(func, hook, callback):
- """
- def myhook(sender, args, kwargs):
- print func, "executed
- print "args:", args
- print "kwargs:", kwargs
- register_hook(BaseDatabaseWrapper.cursor, 'before', myhook)
- """
-
- assert hook in ('before', 'after')
-
- def wrapped(*args, **kwargs):
- start = time.time()
- fire_hook('before', sender=wrapped.__wrapped__, args=args, kwargs=kwargs,
- start=start)
- result = wrapped.__wrapped__(*args, **kwargs)
- stop = time.time()
- fire_hook('after', sender=wrapped.__wrapped__, args=args, kwargs=kwargs,
- result=result, start=start, stop=stop)
- actual = getattr(func, '__wrapped__', func)
- 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)