From 4766304df0dcff59010658a83db9e1dc9480cb79 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 24 Aug 2016 07:06:32 +0300 Subject: [PATCH] Drop ChunkedParser and LinesParser (#1111) --- aiohttp/parsers.py | 38 +------------------------------------ tests/test_parser_buffer.py | 36 ----------------------------------- tests/test_stream_parser.py | 21 +++++++++++++++++++- 3 files changed, 21 insertions(+), 74 deletions(-) diff --git a/aiohttp/parsers.py b/aiohttp/parsers.py index 01b6f8bfd55..3168cdaf8a0 100644 --- a/aiohttp/parsers.py +++ b/aiohttp/parsers.py @@ -65,7 +65,7 @@ def set_parser(self, parser): from .streams import EofStream, FlowControlDataQueue __all__ = ('EofStream', 'StreamParser', 'StreamProtocol', - 'ParserBuffer', 'LinesParser', 'ChunksParser') + 'ParserBuffer', 'StreamWriter') DEFAULT_LIMIT = 2 ** 16 @@ -493,39 +493,3 @@ def __len__(self): def __bytes__(self): return bytes(self._data) - - -class LinesParser: - """Lines parser. - - Lines parser splits a bytes stream into a chunks of data, each chunk ends - with \\n symbol.""" - - def __init__(self, limit=DEFAULT_LIMIT): - self._limit = limit - - def __call__(self, out, buf): - try: - while True: - chunk = yield from buf.readuntil(b'\n', self._limit) - out.feed_data(chunk, len(chunk)) - except EofStream: - pass - - -class ChunksParser: - """Chunks parser. - - Chunks parser splits a bytes stream into a specified - size chunks of data.""" - - def __init__(self, size=8192): - self._size = size - - def __call__(self, out, buf): - try: - while True: - chunk = yield from buf.read(self._size) - out.feed_data(chunk, len(chunk)) - except EofStream: - pass diff --git a/tests/test_parser_buffer.py b/tests/test_parser_buffer.py index 687aaa9cdfb..cbff6df6c8b 100644 --- a/tests/test_parser_buffer.py +++ b/tests/test_parser_buffer.py @@ -250,39 +250,3 @@ def test_skipuntil_exc(buf): p = buf.skipuntil(b'\n') with pytest.raises(ValueError): next(p) - - -def test_lines_parser(buf, stream, loop): - out = parsers.FlowControlDataQueue(stream, loop=loop) - - p = parsers.LinesParser()(out, buf) - next(p) - for d in (b'line1', b'\r\n', b'lin', b'e2\r', b'\ndata'): - p.send(d) - - assert ([(bytearray(b'line1\r\n'), 7), (bytearray(b'line2\r\n'), 7)] == - list(out._buffer)) - try: - p.throw(parsers.EofStream()) - except StopIteration: - pass - - assert bytes(buf) == b'data' - - -def test_chunks_parser(stream, loop, buf): - out = parsers.FlowControlDataQueue(stream, loop=loop) - - p = parsers.ChunksParser(5)(out, buf) - next(p) - for d in (b'line1', b'lin', b'e2d', b'ata'): - p.send(d) - - assert ([(bytearray(b'line1'), 5), (bytearray(b'line2'), 5)] == - list(out._buffer)) - try: - p.throw(parsers.EofStream()) - except StopIteration: - pass - - assert bytes(buf) == b'data' diff --git a/tests/test_stream_parser.py b/tests/test_stream_parser.py index 1484959119e..0b8e589a6ac 100644 --- a/tests/test_stream_parser.py +++ b/tests/test_stream_parser.py @@ -9,9 +9,27 @@ DATA = b'line1\nline2\nline3\n' + +class LinesParser: + """Lines parser. + Lines parser splits a bytes stream into a chunks of data, each chunk ends + with \\n symbol.""" + + def __init__(self): + pass + + def __call__(self, out, buf): + try: + while True: + chunk = yield from buf.readuntil(b'\n', 0xffff) + out.feed_data(chunk, len(chunk)) + except parsers.EofStream: + pass + + @pytest.fixture def lines_parser(): - return parsers.LinesParser() + return LinesParser() def test_at_eof(loop): @@ -44,6 +62,7 @@ def test_exception_connection_error(loop): def test_exception_waiter(loop, lines_parser): + stream = parsers.StreamParser(loop=loop) stream._parser = lines_parser