Skip to content

Commit

Permalink
Drop ChunkedParser and LinesParser (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Aug 24, 2016
1 parent 72bba0d commit 4766304
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 74 deletions.
38 changes: 1 addition & 37 deletions aiohttp/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
36 changes: 0 additions & 36 deletions tests/test_parser_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
21 changes: 20 additions & 1 deletion tests/test_stream_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4766304

Please sign in to comment.