Ticket #22107: file-iteration.diff

File file-iteration.diff, 989 bytes (added by Peter De Wachter, 11 years ago)
  • django/core/files/base.py

    diff --git a/django/core/files/base.py b/django/core/files/base.py
    index b132529..641ff92 100644
    a b class File(FileProxyMixin):  
    104104
    105105                # If this is the end of a line, yield
    106106                # otherwise, wait for the next round
    107                 if line[-1] in ('\n', '\r'):
     107                if line[-1:] in (b'\n', b'\r'):
    108108                    yield line
    109109                else:
    110110                    buffer_ = line
  • tests/files/tests.py

    diff --git a/tests/files/tests.py b/tests/files/tests.py
    index f562b57..58a11ec 100644
    a b class FileTests(unittest.TestCase):  
    6464        self.assertFalse(hasattr(file, 'mode'))
    6565        gzip.GzipFile(fileobj=file)
    6666
     67    def test_file_iteration(self):
     68        file = File(BytesIO(b'1\n2\n3'))
     69        self.assertEqual(list(file), [b'1\n', b'2\n', b'3'])
     70
    6771
    6872class NoNameFileTestCase(unittest.TestCase):
    6973    """
Back to Top