This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Addition of peek and peekexactly methods to asyncio.StreamReader
Type: enhancement Stage:
Components: asyncio Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, awalgarg, yselivanov
Priority: normal Keywords:

Created on 2021-03-16 23:51 by awalgarg, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg388895 - (view) Author: Awal Garg (awalgarg) Date: 2021-03-16 23:51
I propose the addition of the following methods to asyncio.StreamReader:

> coroutine peek(n=-1)
> Same as read, but does not remove the returned data from the internal buffer.
> coroutine peekexactly(n)
> Same as readexactly, but does not remove the returned data from the internal buffer.

My use case is to multiplex a few protocols over a single TCP socket, for which I need to non-destructively read a few bytes from the socket to decide which parser to hand the stream over to.

msg388898 - (view) Author: Awal Garg (awalgarg) Date: 2021-03-16 23:57
P.S., I've filed this issue after a brief discussion in #python and following this ticket which asks for exposing the internal buffer as is. Obviously, peek methods don't need to expose the buffer and only provide a readonly view.
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87690
2021-03-16 23:57:14awalgargsetmessages: + msg388898
2021-03-16 23:51:15awalgargcreate