From e8de188c06823ed5c574778dc1e47f035d7d0bf9 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 8 Oct 2019 23:52:00 +0200 Subject: [PATCH] Refs #30405 -- Added ExceptionReporter._get_source(). --- django/views/debug.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/django/views/debug.py b/django/views/debug.py index 98b29c2cc5..58dc4de967 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -341,11 +341,7 @@ class ExceptionReporter: c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False) return t.render(c) - def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, module_name=None): - """ - Return context_lines before and after lineno from file. - Return (pre_context_lineno, pre_context, context_line, post_context). - """ + def _get_source(self, filename, loader, module_name): source = None if hasattr(loader, 'get_source'): try: @@ -360,6 +356,14 @@ class ExceptionReporter: source = fp.read().splitlines() except OSError: pass + return source + + def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, module_name=None): + """ + Return context_lines before and after lineno from file. + Return (pre_context_lineno, pre_context, context_line, post_context). + """ + source = self._get_source(filename, loader, module_name) if source is None: return None, [], None, []