aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar
diff options
context:
space:
mode:
authorAymeric Augustin2013-10-17 09:42:19 +0200
committerAymeric Augustin2013-10-17 18:24:58 +0200
commit1bf828463dfc48ea09409ae2c91176d5fb0d38c7 (patch)
tree7ccda79ffdf518320547918ed851b9e5cee088bc /debug_toolbar
parentd851a3c8a6bb2b1e8c8cc4f8d6cba0f4a2abe216 (diff)
downloaddjango-debug-toolbar-1bf828463dfc48ea09409ae2c91176d5fb0d38c7.tar.bz2
Implement method replacement for Python 3.
Python 3 doesn't have unbound methods.
Diffstat (limited to 'debug_toolbar')
-rw-r--r--debug_toolbar/panels/sql.py9
-rw-r--r--debug_toolbar/utils/tracking/__init__.py11
2 files changed, 11 insertions, 9 deletions
diff --git a/debug_toolbar/panels/sql.py b/debug_toolbar/panels/sql.py
index bc70b97..709a5f5 100644
--- a/debug_toolbar/panels/sql.py
+++ b/debug_toolbar/panels/sql.py
@@ -13,13 +13,12 @@ from debug_toolbar.panels import DebugPanel
from debug_toolbar.utils import render_stacktrace
from debug_toolbar.utils.sql import reformat_sql
from debug_toolbar.utils.tracking.db import CursorWrapper
-from debug_toolbar.utils.tracking import replace_call
+from debug_toolbar.utils.tracking import replace_method
-# Inject our tracking cursor
-@replace_call(BaseDatabaseWrapper.cursor)
-def cursor(func, self):
- result = func(self)
+@replace_method(BaseDatabaseWrapper, 'cursor')
+def cursor(original, self):
+ result = original(self)
djdt = DebugToolbarMiddleware.get_current()
if not djdt:
diff --git a/debug_toolbar/utils/tracking/__init__.py b/debug_toolbar/utils/tracking/__init__.py
index 4fbefa5..166b1b5 100644
--- a/debug_toolbar/utils/tracking/__init__.py
+++ b/debug_toolbar/utils/tracking/__init__.py
@@ -20,18 +20,21 @@ def pre_dispatch(func):
return wrapped
-def replace_call(func):
+def replace_method(klass, method_name):
+ original = getattr(klass, method_name)
+
def inner(callback):
def wrapped(*args, **kwargs):
- return callback(func, *args, **kwargs)
+ return callback(original, *args, **kwargs)
- actual = getattr(func, '__wrapped__', func)
+ actual = getattr(original, '__wrapped__', original)
wrapped.__wrapped__ = actual
wrapped.__doc__ = getattr(actual, '__doc__', None)
wrapped.__name__ = actual.__name__
- _replace_function(func, wrapped)
+ setattr(klass, method_name, wrapped)
return wrapped
+
return inner