Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5712 -- Added more robustness to source code display in the de…

…bug 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
  • Loading branch information...
commit fcbde3cbe5bcfcb88825f28629709b60035d9c9f 1 parent a1496b0
Malcolm Tredinnick authored

Showing 1 changed file with 4 additions and 5 deletions. Show diff stats Hide diff stats

  1. 9  django/views/debug.py
9  django/views/debug.py
@@ -201,16 +201,15 @@ def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_na
201 201
     if source is None:
202 202
         return None, [], None, []
203 203
 
204  
-    encoding=None
  204
+    encoding = 'ascii'
205 205
     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/)
208 208
         match = re.search(r'coding[:=]\s*([-\w.]+)', line)
209 209
         if match:
210 210
             encoding = match.group(1)
211 211
             break
212  
-    if encoding:
213  
-        source = [unicode(sline, encoding) for sline in source]
  212
+    source = [unicode(sline, encoding, 'replace') for sline in source]
214 213
 
215 214
     lower_bound = max(0, lineno - context_lines)
216 215
     upper_bound = lineno + context_lines

0 notes on commit fcbde3c

Please sign in to comment.
Something went wrong with that request. Please try again.