mirror of https://github.com/django/django.git
Fixed #5712 -- Added more robustness to source code display in the debug view. Our behaviour is a bit more PEP 263 compliant now, too. Thanks, Thomas Güttler.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6585 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a1496b054a
commit
fcbde3cbe5
|
@ -201,16 +201,15 @@ def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_na
|
||||||
if source is None:
|
if source is None:
|
||||||
return None, [], None, []
|
return None, [], None, []
|
||||||
|
|
||||||
encoding=None
|
encoding = 'ascii'
|
||||||
for line in source[:2]:
|
for line in source[:2]:
|
||||||
# File coding may be specified (and may not be UTF-8). Match
|
# File coding may be specified. Match pattern from PEP-263
|
||||||
# pattern from PEP-263 (http://www.python.org/dev/peps/pep-0263/)
|
# (http://www.python.org/dev/peps/pep-0263/)
|
||||||
match = re.search(r'coding[:=]\s*([-\w.]+)', line)
|
match = re.search(r'coding[:=]\s*([-\w.]+)', line)
|
||||||
if match:
|
if match:
|
||||||
encoding = match.group(1)
|
encoding = match.group(1)
|
||||||
break
|
break
|
||||||
if encoding:
|
source = [unicode(sline, encoding, 'replace') for sline in source]
|
||||||
source = [unicode(sline, encoding) for sline in source]
|
|
||||||
|
|
||||||
lower_bound = max(0, lineno - context_lines)
|
lower_bound = max(0, lineno - context_lines)
|
||||||
upper_bound = lineno + context_lines
|
upper_bound = lineno + context_lines
|
||||||
|
|
Loading…
Reference in New Issue