From fcbde3cbe5bcfcb88825f28629709b60035d9c9f Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 21 Oct 2007 18:15:01 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20#5712=20--=20Added=20more=20robustness?= =?UTF-8?q?=20to=20source=20code=20display=20in=20the=20debug=20view.=20?= =?UTF-8?q?=20Our=20behaviour=20is=20a=20bit=20more=20PEP=20263=20complian?= =?UTF-8?q?t=20now,=20too.=20Thanks,=20Thomas=20G=C3=BCttler.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@6585 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/debug.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/django/views/debug.py b/django/views/debug.py index cf0b6b5a0b..717de1eb34 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -201,16 +201,15 @@ def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_na if source is None: return None, [], None, [] - encoding=None + encoding = 'ascii' for line in source[:2]: - # File coding may be specified (and may not be UTF-8). Match - # pattern from PEP-263 (http://www.python.org/dev/peps/pep-0263/) + # File coding may be specified. Match pattern from PEP-263 + # (http://www.python.org/dev/peps/pep-0263/) match = re.search(r'coding[:=]\s*([-\w.]+)', line) if match: encoding = match.group(1) break - if encoding: - source = [unicode(sline, encoding) for sline in source] + source = [unicode(sline, encoding, 'replace') for sline in source] lower_bound = max(0, lineno - context_lines) upper_bound = lineno + context_lines