[issue32052] Provide access to buffer of asyncio.StreamReader

Bruce Merry report at bugs.python.org
Thu Nov 16 14:09:48 EST 2017


New submission from Bruce Merry <bmerry at gmail.com>:

While asyncio.StreamReader.readuntil is an improvement on only having readline, it is still quite limited e.g. you cannot have multiple possible terminators. The real problem is that it's not possible to roll your own without accessing _underscore fields (other than by reading one byte at a time, which I'm guessing would be bad for performance). I'm not sure exactly what a public API to assist would look like, but I think the following would be a good start:

1. A get_buffer method, that returns (self._buffer, self._eof); the caller must treat the buffer as readonly.
2. A wait_for_data method to wait for the return value of get_buffer to change (basically like current _wait_for_data)
3. Access to the _limit attribute.

With that available, I think readuntil or more complex variants of it could be implemented externally using only the public interface (consumption of data from the buffer would be via readexactly rather than by messing with the buffer array directly).

----------
components: asyncio
messages: 306397
nosy: Bruce Merry, yselivanov
priority: normal
severity: normal
status: open
title: Provide access to buffer of asyncio.StreamReader
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32052>
_______________________________________


More information about the Python-bugs-list mailing list