Django

Code

Changeset 6585

Show
Ignore:
Timestamp:
10/21/07 13:15:01 (1 year ago)
Author:
mtredinnick
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/debug.py

    r5862 r6585  
    202202        return None, [], None, [] 
    203203 
    204     encoding=None 
     204    encoding = 'ascii' 
    205205    for line in source[:2]: 
    206         # File coding may be specified (and may not be UTF-8). Match 
    207         # pattern from PEP-263 (http://www.python.org/dev/peps/pep-0263/) 
     206        # File coding may be specified. Match pattern from PEP-263 
     207        # (http://www.python.org/dev/peps/pep-0263/) 
    208208        match = re.search(r'coding[:=]\s*([-\w.]+)', line) 
    209209        if match: 
    210210            encoding = match.group(1) 
    211211            break 
    212     if encoding: 
    213         source = [unicode(sline, encoding) for sline in source] 
     212    source = [unicode(sline, encoding, 'replace') for sline in source] 
    214213 
    215214    lower_bound = max(0, lineno - context_lines)