diff options
| author | David Cramer | 2011-05-10 00:20:25 -0700 |
|---|---|---|
| committer | David Cramer | 2011-05-10 00:20:25 -0700 |
| commit | 9514b001889e7331d80cc8c4f168b284a27825e0 (patch) | |
| tree | c9196663618a673cdfb7038ba921bc27d6da359f /debug_toolbar/utils | |
| parent | 3f98e826400f29da672e96c1b08dc4bf7287b5c2 (diff) | |
| download | django-debug-toolbar-9514b001889e7331d80cc8c4f168b284a27825e0.tar.bz2 | |
Add support for __traceback_hide__ (tidy_stacktrace now inspects inspect.stack() rather than traceback.extract_stack()) (fixes #160)
Diffstat (limited to 'debug_toolbar/utils')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 14 | ||||
| -rw-r--r-- | debug_toolbar/utils/tracking/db.py | 4 |
2 files changed, 12 insertions, 6 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index 61bb717..aa214c9 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -15,22 +15,28 @@ def ms_from_timedelta(td): """ return (td.seconds * 1000) + (td.microseconds / 1000.0) -def tidy_stacktrace(strace): +def tidy_stacktrace(stack): """ Clean up stacktrace and remove all entries that: 1. Are part of Django (except contrib apps) 2. Are part of SocketServer (used by Django's dev server) 3. Are the last entry (which is part of our stacktracing code) + + ``stack`` should be a list of frame tuples from ``inspect.stack()`` """ trace = [] - for s in strace[:-1]: - s_path = os.path.realpath(s[0]) + for frame, path, line_no, func_name, text in (f[:5] for f in stack): + s_path = os.path.realpath(path) + # Support hiding of frames -- used in various utilities that provide + # inspection. + if '__traceback_hide__' in frame.f_locals: + continue if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) \ and django_path in s_path and not 'django/contrib' in s_path: continue if socketserver_path in s_path: continue - trace.append((s[0], s[1], s[2], s[3])) + trace.append((path, line_no, func_name, text)) return trace def get_template_info(source, context_lines=3): diff --git a/debug_toolbar/utils/tracking/db.py b/debug_toolbar/utils/tracking/db.py index 87f4550..d1226e4 100644 --- a/debug_toolbar/utils/tracking/db.py +++ b/debug_toolbar/utils/tracking/db.py @@ -1,5 +1,5 @@ +import inspect import sys -import traceback from datetime import datetime @@ -35,7 +35,7 @@ class CursorWrapper(object): finally: stop = datetime.now() duration = ms_from_timedelta(stop - start) - stacktrace = tidy_stacktrace(traceback.extract_stack()) + stacktrace = tidy_stacktrace(inspect.stack()) _params = '' try: _params = simplejson.dumps([force_unicode(x, strings_only=True) for x in params]) |
