diff --git a/django/views/debug.py b/django/views/debug.py
index 9b95b52..10c07e8 100644
a
|
b
|
class ExceptionReporter(object):
|
347 | 347 | if source is None: |
348 | 348 | try: |
349 | 349 | with open(filename, 'rb') as fp: |
350 | | source = fp.readlines() |
| 350 | source = fp.read().splitlines() |
351 | 351 | except (OSError, IOError): |
352 | 352 | pass |
353 | 353 | if source is None: |
… |
… |
class ExceptionReporter(object):
|
370 | 370 | lower_bound = max(0, lineno - context_lines) |
371 | 371 | upper_bound = lineno + context_lines |
372 | 372 | |
373 | | pre_context = [line.strip('\n') for line in source[lower_bound:lineno]] |
374 | | context_line = source[lineno].strip('\n') |
375 | | post_context = [line.strip('\n') for line in source[lineno+1:upper_bound]] |
| 373 | pre_context = source[lower_bound:lineno] |
| 374 | context_line = source[lineno] |
| 375 | post_context = source[lineno+1:upper_bound] |
376 | 376 | |
377 | 377 | return lower_bound, pre_context, context_line, post_context |
378 | 378 | |
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index b44cd88..a10b3e0 100644
a
|
b
|
from __future__ import absolute_import, unicode_literals
|
6 | 6 | import inspect |
7 | 7 | import os |
8 | 8 | import sys |
| 9 | import tempfile |
9 | 10 | |
10 | 11 | from django.core import mail |
11 | 12 | from django.core.files.uploadedfile import SimpleUploadedFile |
… |
… |
class ExceptionReporterTests(TestCase):
|
122 | 123 | self.assertIn('<h2>Request information</h2>', html) |
123 | 124 | self.assertIn('<p>Request data not supplied</p>', html) |
124 | 125 | |
| 126 | def test_eol_support(self): |
| 127 | """Test that the ExceptionReporter supports Unix, Windows and Macintosh EOL markers""" |
| 128 | LINES = list(u'print %d' % i for i in range(1,6)) |
| 129 | reporter = ExceptionReporter(None, None, None, None) |
| 130 | |
| 131 | for newline in ['\n','\r\n','\r']: |
| 132 | fd,filename = tempfile.mkstemp(text = False) |
| 133 | os.write(fd, newline.join(LINES)+newline) |
| 134 | os.close(fd) |
| 135 | |
| 136 | try: |
| 137 | self.assertEqual( |
| 138 | reporter._get_lines_from_file(filename, 3, 2), |
| 139 | (1, LINES[1:3], LINES[3], LINES[4:]) |
| 140 | ) |
| 141 | finally: |
| 142 | os.unlink(filename) |
| 143 | |
125 | 144 | def test_no_exception(self): |
126 | 145 | "An exception report can be generated for just a request" |
127 | 146 | request = self.rf.get('/test_view/') |