You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
asyncio.StreamReader.readuntil is not general enough #76576
bpo-37141: Allow multiple separators in Stream.readuntil
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-09-12.09:39:28.389>created_at=<Date2017-12-21.05:52:54.042>labels= ['type-feature', '3.7', 'expert-asyncio']
title='asyncio.StreamReader.readuntil is not general enough'updated_at=<Date2019-09-12.09:39:28.388>user='https://bugs.python.org/BruceMerry'
I'd proposed one specific solution in bpo-32052 which asvetlov didn't like, so as requested I'm filing a bug about the problem rather than the solution.
The specific case I have is reading a protocol in which either \r or \n can be used to terminate lines. With StreamReader.readuntil, it's only possible to specify one separator, so it can't easily be used (*).
Some nice-to-have features, from specific to general:
Specify multiple alternate separators.
Specify a regex for a separator.
Specify a regex for the line.
Specify a callback that takes a string and returns the position of the end of the line, if any.
Of course, some of these risk quadratic-time behaviour if they have to check the whole buffer every time the buffer is extended, so that would need to be considered in the design. In the last case, the callback could take care of it itself by maintaining internal state.
Activity
BruceMerry commentedon Dec 21, 2017
I'd proposed one specific solution in bpo-32052 which asvetlov didn't like, so as requested I'm filing a bug about the problem rather than the solution.
The specific case I have is reading a protocol in which either \r or \n can be used to terminate lines. With StreamReader.readuntil, it's only possible to specify one separator, so it can't easily be used (*).
Some nice-to-have features, from specific to general:
Of course, some of these risk quadratic-time behaviour if they have to check the whole buffer every time the buffer is extended, so that would need to be considered in the design. In the last case, the callback could take care of it itself by maintaining internal state.
(*) I actually have a solution for this case (https://github.com/ska-sa/aiokatcp/blob/bd8263cefe213003a218fac0dd8c5207cc76aeef/aiokatcp/connection.py#L44-L52), but it only works because \r and \n are semantically equivalent in the particular protocol I'm parsing.
asvetlov commentedon Dec 21, 2017
Support multiple separators looks easy, I don't expect any performance impact.
Like we already have it for strings: s.startswith(('\n', '\r'))
Regexps are more expensive thing, callbacks are kind of evil.
Let's add a patch for multiple separators first, maybe it covers 99.9% use cases.
tirkarthi commentedon Sep 12, 2019
I think this is a duplicate of bpo-37141 where multiple separators are requested for readuntil. I guess we can close one of them as duplicates.
asvetlov commentedon Sep 12, 2019
Agree