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.

Author Bruce Merry
Recipients Bruce Merry, yselivanov
Date 2017-12-21.05:52:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1513835574.11.0.213398074469.issue32395@psf.upfronthosting.co.za>
In-reply-to
Content
I'd proposed one specific solution in Issue 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:
1. Specify multiple alternate separators.
2. Specify a regex for a separator.
3. Specify a regex for the line.
4. 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.


(*) 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.
History
Date User Action Args
2017-12-21 05:52:54Bruce Merrysetrecipients: + Bruce Merry, yselivanov
2017-12-21 05:52:54Bruce Merrysetmessageid: <1513835574.11.0.213398074469.issue32395@psf.upfronthosting.co.za>
2017-12-21 05:52:53Bruce Merrylinkissue32395 messages
2017-12-21 05:52:52Bruce Merrycreate