def test_multi_part_line_breaks(self): data = 'abcdef\r\nghijkl\r\nmnopqrstuvwxyz\r\nABCDEFGHIJK' test_stream = StringIO(data) lines = list(wsgi.make_line_iter( test_stream, limit=len(data), buffer_size=16, )) self.assertEqual( lines, [ 'abcdef\r\n', 'ghijkl\r\n', 'mnopqrstuvwxyz\r\n', 'ABCDEFGHIJK' ] ) data = ( 'abc\r\nThis line is broken by the buffer length.' '\r\nFoo bar baz' ) test_stream = StringIO(data) lines = list(wsgi.make_line_iter( test_stream, limit=len(data), buffer_size=24, )) self.assertEqual( lines, [ 'abc\r\n', 'This line is broken by the buffer length.\r\n', 'Foo bar baz', ] )
def test_multi_part_line_breaks_bytes(self): data = b'abcdef\r\nghijkl\r\nmnopqrstuvwxyz\r\nABCDEFGHIJK' test_stream = BytesIO(data) lines = list(wsgi.make_line_iter(test_stream, limit=len(data), buffer_size=16)) self.assertEqual( lines, [ b'abcdef\r\n', b'ghijkl\r\n', b'mnopqrstuvwxyz\r\n', b'ABCDEFGHIJK' ] ) data = ( b'abc\r\nThis line is broken by the buffer length.' b'\r\nFoo bar baz' ) test_stream = BytesIO(data) lines = list(wsgi.make_line_iter(test_stream, limit=len(data), buffer_size=24)) self.assertEqual( lines, [ b'abc\r\n', b'This line is broken by the buffer length.\r\n', b'Foo bar baz', ] )
def test_lines_longer_buffer_size(self): data = '1234567890\n1234567890\n' for bufsize in range(1, 15): lines = list(wsgi.make_line_iter( StringIO(data), limit=len(data), buffer_size=4 )) self.assertEqual(lines, ['1234567890\n', '1234567890\n'])
def test_multi_part_line_breaks_problematic(self): data = 'abc\rdef\r\nghi' for x in range(1, 10): test_stream = StringIO(data) lines = list(wsgi.make_line_iter(test_stream, limit=len(data), buffer_size=4)) self.assertEqual(lines, ['abc\r', 'def\r\n', 'ghi'])
def test_iter_functions_support_iterators(self): data = ['abcdef\r\nghi', 'jkl\r\nmnopqrstuvwxyz\r', '\nABCDEFGHIJK'] lines = list(wsgi.make_line_iter(data)) self.assertEqual( lines, [ 'abcdef\r\n', 'ghijkl\r\n', 'mnopqrstuvwxyz\r\n', 'ABCDEFGHIJK' ] )
def test_multi_part_line_breaks_problematic(self): data = 'abc\rdef\r\nghi' for x in range(1, 10): test_stream = StringIO(data) lines = list(wsgi.make_line_iter( test_stream, limit=len(data), buffer_size=4 )) self.assertEqual(lines, ['abc\r', 'def\r\n', 'ghi'])