diff options
| author | Simon Meers | 2013-06-24 20:47:18 +1000 |
|---|---|---|
| committer | Aymeric Augustin | 2013-10-21 15:39:25 +0200 |
| commit | 5b1fd5a96eca2522b173ea6266ecef026fab78c6 (patch) | |
| tree | c5c42ea16f2e46aa9e5610f041efd41760adf867 /debug_toolbar/utils/__init__.py | |
| parent | a705563dddb14bd0de2a904d5aca492274229942 (diff) | |
| download | django-debug-toolbar-5b1fd5a96eca2522b173ea6266ecef026fab78c6.tar.bz2 | |
Added configurable HIDDEN_STACKTRACE_MODULES.
Diffstat (limited to 'debug_toolbar/utils/__init__.py')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index 75f3024..31641e6 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -6,18 +6,53 @@ import django import sys from django.conf import settings -from django.views.debug import linebreak_iter +from django.core.exceptions import ImproperlyConfigured from django.utils.encoding import force_text from django.utils.html import escape +from django.utils.importlib import import_module from django.utils.safestring import mark_safe from django.utils import six -from django.utils.six.moves import socketserver +from django.views.debug import linebreak_iter + # Figure out some paths django_path = os.path.realpath(os.path.dirname(django.__file__)) -socketserver_path = os.path.realpath(os.path.dirname(socketserver.__file__)) -hide_django_sql = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('HIDE_DJANGO_SQL', True) +config = getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}) +hide_django_sql = config.get('HIDE_DJANGO_SQL', True) + + +def get_module_path(module_string): + try: + module = import_module(module_string) + except ImportError as e: + raise ImproperlyConfigured( + 'Error importing HIDDEN_STACKTRACE_MODULES: %s' % (e,)) + else: + source_path = inspect.getsourcefile(module) + if source_path.endswith('__init__.py'): + source_path = os.path.dirname(source_path) + return os.path.realpath(source_path) + + +hidden_paths = [ + get_module_path(module_name) + for module_name in config.get( + 'HIDDEN_STACKTRACE_MODULES', ( + 'socketserver' if six.PY3 else 'SocketServer', + 'threading', + 'wsgiref', + 'debug_toolbar', + ) + ) +] + + +def omit_path(path): + for hidden_path in hidden_paths: + if hidden_path in path: + return True + return False def tidy_stacktrace(stack): @@ -38,7 +73,7 @@ def tidy_stacktrace(stack): continue if hide_django_sql and django_path in s_path and not 'django/contrib' in s_path: continue - if socketserver_path in s_path: + if omit_path(s_path): continue text = (''.join(force_text(t) for t in text)).strip() if text else '' trace.append((path, line_no, func_name, text)) |
