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