Skip to content

Commit 6b9fbea

Browse files
living180matthiask
authored andcommitted
Remove unnecessary decoding from getframeinfo()
linecache uses tokenize.open() to detect and use the encoding of the file since Python 3.4.
1 parent 927819d commit 6b9fbea

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

debug_toolbar/utils.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import inspect
22
import os.path
3-
import re
43
import sys
54
from importlib import import_module
65
from pprint import pformat
@@ -200,27 +199,14 @@ def getframeinfo(frame, context=1):
200199
try:
201200
lines, lnum = inspect.findsource(frame)
202201
except Exception: # findsource raises platform-dependant exceptions
203-
first_lines = lines = index = None
202+
lines = index = None
204203
else:
205204
start = max(start, 1)
206205
start = max(0, min(start, len(lines) - context))
207-
first_lines = lines[:2]
208206
lines = lines[start : (start + context)]
209207
index = lineno - 1 - start
210208
else:
211-
first_lines = lines = index = None
212-
213-
# Code taken from Django's ExceptionReporter._get_lines_from_file
214-
if first_lines and isinstance(first_lines[0], bytes):
215-
encoding = "ascii"
216-
for line in first_lines[:2]:
217-
# File coding may be specified. Match pattern from PEP-263
218-
# (https://www.python.org/dev/peps/pep-0263/)
219-
match = re.search(rb"coding[:=]\s*([-\w.]+)", line)
220-
if match:
221-
encoding = match.group(1).decode("ascii")
222-
break
223-
lines = [line.decode(encoding, "replace") for line in lines]
209+
lines = index = None
224210

225211
return inspect.Traceback(filename, lineno, frame.f_code.co_name, lines, index)
226212

0 commit comments

Comments
 (0)