From 7225efba5006256915ca5e56889e2a35bc10a26a Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Fri, 11 May 2007 14:49:43 +0000 Subject: [PATCH] =?UTF-8?q?unicode:=20Fixed=20#4249=20--=20Decode=20source?= =?UTF-8?q?=20files=20correctly=20in=20the=20debug=20view.=20Thanks,=20Tho?= =?UTF-8?q?mas=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/branches/unicode@5193 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/views/debug.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/AUTHORS b/AUTHORS index 855717ea64..d6aa7fb2a1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -107,6 +107,7 @@ answer newbie questions, and generally made Django that much better: Simon Greenhill Owen Griffiths Espen Grindhaug + Thomas Güttler Brian Harring Brant Harris Hawkeye diff --git a/django/views/debug.py b/django/views/debug.py index 2530350e26..352b4c880b 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -188,6 +188,17 @@ def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_na if source is None: return None, [], None, [] + encoding=None + 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/) + 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] + lower_bound = max(0, lineno - context_lines) upper_bound = lineno + context_lines