make_line_iter(stream, limit=None, buffer_size=10240, cap_at_buffer=False)[source]¶
Safely iterates line-based over an input stream. If the input stream is not a
LimitedStreamthe limit parameter is mandatory.
This uses the stream’s
read()method internally as opposite to the
readline()method that is unsafe and can only be used in violation of the WSGI specification. The same problem applies to the __iter__ function of the input stream which calls
If you need line-by-line processing it’s strongly recommended to iterate over the input stream using this helper function.
Changed in version 0.8: This function now ensures that the limit was reached.
New in version 0.9: added support for iterators as input stream.
- stream – the stream or iterate to iterate over.
- limit – the limit in bytes for the stream. (Usually
content length. Not necessary if the stream
- buffer_size – The optional buffer size.
- cap_at_buffer – if this is set chunks are split if they are longer than the buffer size. Internally this is implemented that the buffer size might be exhausted by a factor of two however.
New in version 0.11.10: added support for the cap_at_buffer parameter.