Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Consider adding limit parameters to StreamReader.readline and .readuntil. #304

Description

@1st1

This topic was originally brought up in PR #297.

StreamReader class allows to implement protocols parsers in a very convenient way already. Instead of managing buffers and callbacks, one can layout even complex protocols as a series of await read(..), await readline(..) (and soon await readuntil(..)) calls.

I think that adding an ability to adjust the buffer limit per operation is a great idea. We just need to come up with a good API design for it.

One example of where custom read limits would be useful is a MIME parser. It makes sense to set the default StreamReader's limit to a few megabytes, and then use readline(limit=8*1024) for reading headers, and readuntil(separator=boundary) for reading attachments.

@gvanrossum also suggested to add a StreamReader.set_buffer_limit method. Which actually sounds like a better option. For MIME parser, for example, we could initialize StreamReader with its default limit, read headers, and then increase the limit to make it possible to use readuntil for parsing attachments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions