aiohttp.parsers.EofStream

Here are the examples of the python api aiohttp.parsers.EofStream taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

Example 1

Project: aiohttp Source File: test_stream_parser.py
Function: call
    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

Example 2

Project: aiohttp Source File: test_stream_parser.py
def test_set_parser_feed_existing_eof_exc(loop):
    def p(out, buf):
        try:
            while True:
                yield  # read chunk
        except parsers.EofStream:
            raise ValueError()

    stream = parsers.StreamParser(loop=loop)
    stream.feed_data(b'line1')
    stream.feed_eof()
    s = stream.set_parser(p)
    assert isinstance(s.exception(), ValueError)

Example 3

Project: aiohttp Source File: test_stream_parser.py
def test_feed_eof_exc(loop):
    def p(out, buf):
        try:
            while True:
                yield  # read chunk
        except parsers.EofStream:
            raise ValueError()

    stream = parsers.StreamParser(loop=loop)
    s = stream.set_parser(p)

    stream.feed_data(b'line1')
    assert s.exception() is None

    stream.feed_eof()
    assert isinstance(s.exception(), ValueError)

Example 4

Project: aiohttp Source File: test_stream_parser.py
def test_feed_eof_stop(loop):
    def p(out, buf):
        try:
            while True:
                yield  # read chunk
        except parsers.EofStream:
            out.feed_eof()

    stream = parsers.StreamParser(loop=loop)
    s = stream.set_parser(p)

    stream.feed_data(b'line1')
    stream.feed_eof()
    assert s._eof

Example 5

Project: aiohttp Source File: test_stream_parser.py
def test_unset_parser_eof_exc(loop):
    def p(out, buf):
        try:
            while True:
                yield  # read chunk
        except parsers.EofStream:
            raise ValueError()

    stream = parsers.StreamParser(loop=loop)
    s = stream.set_parser(p)

    stream.feed_data(b'line1')
    stream.unset_parser()
    assert isinstance(s.exception(), ValueError)
    assert stream._parser is None

Example 6

Project: aiohttp Source File: test_stream_parser.py
def test_unset_parser_stop(loop):
    def p(out, buf):
        try:
            while True:
                yield  # read chunk
        except parsers.EofStream:
            out.feed_eof()

    stream = parsers.StreamParser(loop=loop)
    s = stream.set_parser(p)

    stream.feed_data(b'line1')
    stream.unset_parser()
    assert s._eof