diff --git a/debug_toolbar/utils.py b/debug_toolbar/utils.py index cc90cf4db..13f7472ad 100644 --- a/debug_toolbar/utils.py +++ b/debug_toolbar/utils.py @@ -1,6 +1,5 @@ import inspect import os.path -import re import sys from importlib import import_module from pprint import pformat @@ -47,12 +46,11 @@ def omit_path(path): 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) + Clean up stacktrace and remove all entries that are excluded by the + HIDE_IN_STACKTRACES setting. - ``stack`` should be a list of frame tuples from ``inspect.stack()`` + ``stack`` should be a list of frame tuples from ``inspect.stack()`` or + ``debug_toolbar.utils.get_stack()``. """ trace = [] for frame, path, line_no, func_name, text in (f[:5] for f in stack): @@ -201,32 +199,16 @@ def getframeinfo(frame, context=1): try: lines, lnum = inspect.findsource(frame) except Exception: # findsource raises platform-dependant exceptions - first_lines = lines = index = None + lines = index = None else: start = max(start, 1) start = max(0, min(start, len(lines) - context)) - first_lines = lines[:2] lines = lines[start : (start + context)] index = lineno - 1 - start else: - first_lines = lines = index = None - - # Code taken from Django's ExceptionReporter._get_lines_from_file - if first_lines and isinstance(first_lines[0], bytes): - encoding = "ascii" - for line in first_lines[:2]: - # File coding may be specified. Match pattern from PEP-263 - # (https://www.python.org/dev/peps/pep-0263/) - match = re.search(rb"coding[:=]\s*([-\w.]+)", line) - if match: - encoding = match.group(1).decode("ascii") - break - lines = [line.decode(encoding, "replace") for line in lines] + lines = index = None - if hasattr(inspect, "Traceback"): - return inspect.Traceback(filename, lineno, frame.f_code.co_name, lines, index) - else: - return (filename, lineno, frame.f_code.co_name, lines, index) + return inspect.Traceback(filename, lineno, frame.f_code.co_name, lines, index) def get_sorted_request_variable(variable): diff --git a/docs/changes.rst b/docs/changes.rst index 019a6eac3..7a7cc48fd 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -10,6 +10,7 @@ Change log * Added pyflame (for flame graphs) to the list of third-party panels. * Fixed the cache panel to correctly count cache misses from the get_many() cache method. +* Removed some obsolete compatibility code from the stack trace recording code. 3.4.0 (2022-05-03) ------------------