Ticket #13958: 13958_fixed.diff

File 13958_fixed.diff, 2.5 KB (added by Steffen Zieger, 11 years ago)

This patch is working for the current Django master

  • django/views/debug.py

    diff --git a/django/views/debug.py b/django/views/debug.py
    index 9b95b52..10c07e8 100644
    a b class ExceptionReporter(object):  
    347347        if source is None:
    348348            try:
    349349                with open(filename, 'rb') as fp:
    350                     source = fp.readlines()
     350                    source = fp.read().splitlines()
    351351            except (OSError, IOError):
    352352                pass
    353353        if source is None:
    class ExceptionReporter(object):  
    370370        lower_bound = max(0, lineno - context_lines)
    371371        upper_bound = lineno + context_lines
    372372
    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]
    376376
    377377        return lower_bound, pre_context, context_line, post_context
    378378
  • tests/view_tests/tests/test_debug.py

    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  
    66import inspect
    77import os
    88import sys
     9import tempfile
    910
    1011from django.core import mail
    1112from django.core.files.uploadedfile import SimpleUploadedFile
    class ExceptionReporterTests(TestCase):  
    122123        self.assertIn('<h2>Request information</h2>', html)
    123124        self.assertIn('<p>Request data not supplied</p>', html)
    124125
     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
    125144    def test_no_exception(self):
    126145        "An exception report can be generated for just a request"
    127146        request = self.rf.get('/test_view/')
Back to Top