class LimitedStream(io.IOBase):
Wraps a stream so that it doesn't read more than n bytes. If the
stream is exhausted and the caller tries to get more bytes from it
on_exhausted
is called which by default returns an empty
string. The return value of that function is forwarded
to the reader function. So if it returns an empty string
read
will return an empty string as well.
The limit however must never be higher than what the stream can
output. Otherwise readlines
will try to read past the
limit.
Note on WSGI compliance
calls to readline
and readlines
are not
WSGI compliant because it passes a size argument to the
readline methods. Unfortunately the WSGI PEP is not safely
implementable without a size argument to readline
because there is no EOF marker in the stream. As a result
of that the use of readline
is discouraged.
For the same reason iterating over the LimitedStream
is not portable. It internally calls readline
.
We strongly suggest using read
only or using the
make_line_iter
which safely iterates line-based
over a WSGI input stream.
Parameters | |
stream | the stream to wrap. |
limit | the limit for the stream, must not be longer than
what the string can provide if the stream does not
end with EOF (like wsgi.input ) |
Method | __init__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __next__ |
Undocumented |
Method | exhaust |
Exhaust the stream. This consumes all the data left until the limit is reached. |
Method | on_disconnect |
No summary |
Method | on_exhausted |
This is called when the stream tries to read past the limit. The return value of this function is returned from the reading function. |
Method | read |
Read size bytes or if size is not provided everything is read. |
Method | readable |
Undocumented |
Method | readline |
Reads one line from the stream. |
Method | readlines |
No summary |
Method | tell |
Returns the position of the stream. |
Instance Variable | limit |
Undocumented |
Property | is_exhausted |
If the stream is exhausted this attribute is True . |
Instance Variable | _pos |
Undocumented |
Instance Variable | _read |
Undocumented |
Instance Variable | _readline |
Undocumented |
Undocumented
Parameters | |
stream:t.IO[ | Undocumented |
limit:int | Undocumented |
Parameters | |
chunk_size:int | the size for a chunk. It will read the chunk until the stream is exhausted and throw away the results. |
~werkzeug.exceptions.ClientDisconnected
exception is raised.Returns | |
bytes | Undocumented |
Returns | |
bytes | Undocumented |
size
bytes or if size is not provided everything is read.Parameters | |
size:t.Optional[ | the number of bytes read. |
Returns | |
bytes | Undocumented |
Parameters | |
size:t.Optional[ | Undocumented |
Returns | |
bytes | Undocumented |