-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes problems with iter_lines when the delimiter is split #2431
Conversation
The specific issue happens when attempting to retrieve lines with a multi-byte delimiter. Very occasionally, the delimiter ends up split between data chunks. This results in the yielding of an additional null string. For reading an MJPEG data stream with |
I see you've marked it with the Breaking API Change. I suppose that's correct, as it was previously inconsistent. If a null-string chunk were received then the port closed, |
Please define historically. In the context of the project, empty strings are historically the normal, intentionally or not. For what it's worth, this can still be merged before 3.0 but I wanted to ensure no one merged this accidentally before we had a chance to discuss it. |
Sure. Prior to the change that added the ability to define the delimiter, empty strings would not have been emitted as that only came about as a result of using Behavior prior to October 2014:
After October 2014:
Side-effect of proposed fix:
All this is an aside from my proposed fix, which essentially yielding if and only if there's a full line of content. If I'm expecting a string that looks like this:
But once in a while, the delimiter is split across chunks internally, and without any change to the source content, I occasionally get an extra
The proposed change fixes the routine so that it behaves more consistently with null-string input and does not yield when there's not a line of data** in the input stream. **Okay, there's one additional issue that's been in there since at least October 2014 that I didn't address: if using |
Here's a breakdown as I understand it. Prior to October 2014:
After October 2014:
Proposed Change:
Since |
This PR hasn't seen any love in a long time. @ianepperson, would mind performing a rebase to make this once-again mergable? @sigmavirus24 @Lukasa +1? -1? I want to get this merged or closed out. |
I'm generally +1 on this, though it needs to be merged into 3.0.0 rather than the master branch. |
Closing in favour of #3745. |
Write a list of different chunk splits and their expected results to test against, using ianepperson's breakdown as specification: https://github.com/kennethreitz/requests/pull/2431#issuecomment-72333964
Write a list of different chunk splits and their expected results to test against, using ianepperson's breakdown as specification: https://github.com/kennethreitz/requests/pull/2431#issuecomment-72333964
I ran into this problem today where my data would randomly have additional null strings from iter_lines. I added a test to show the issue, then fixed it.
The only weirdness might be when no data comes back, how should iter_lines behave? Should there be a single yield of a null string, or should it just return without yielding anything? This edit performs the latter.