mirror of https://github.com/python/cpython
gh-100226: Clarify StreamReader.read behavior (#101807)
This commit is contained in:
parent
a1723caabf
commit
77d95c8373
|
@ -206,12 +206,20 @@ StreamReader
|
||||||
|
|
||||||
.. coroutinemethod:: read(n=-1)
|
.. coroutinemethod:: read(n=-1)
|
||||||
|
|
||||||
Read up to *n* bytes. If *n* is not provided, or set to ``-1``,
|
Read up to *n* bytes from the stream.
|
||||||
read until EOF and return all read bytes.
|
|
||||||
|
|
||||||
|
If *n* is not provided or set to ``-1``,
|
||||||
|
read until EOF, then return all read :class:`bytes`.
|
||||||
If EOF was received and the internal buffer is empty,
|
If EOF was received and the internal buffer is empty,
|
||||||
return an empty ``bytes`` object.
|
return an empty ``bytes`` object.
|
||||||
|
|
||||||
|
If *n* is ``0``, return an empty ``bytes`` object immediately.
|
||||||
|
|
||||||
|
If *n* is positive, return at most *n* available ``bytes``
|
||||||
|
as soon as at least 1 byte is available in the internal buffer.
|
||||||
|
If EOF is received before any byte is read, return an empty
|
||||||
|
``bytes`` object.
|
||||||
|
|
||||||
.. coroutinemethod:: readline()
|
.. coroutinemethod:: readline()
|
||||||
|
|
||||||
Read one line, where "line" is a sequence of bytes
|
Read one line, where "line" is a sequence of bytes
|
||||||
|
|
|
@ -649,16 +649,17 @@ class StreamReader:
|
||||||
async def read(self, n=-1):
|
async def read(self, n=-1):
|
||||||
"""Read up to `n` bytes from the stream.
|
"""Read up to `n` bytes from the stream.
|
||||||
|
|
||||||
If n is not provided, or set to -1, read until EOF and return all read
|
If `n` is not provided or set to -1,
|
||||||
bytes. If the EOF was received and the internal buffer is empty, return
|
read until EOF, then return all read bytes.
|
||||||
an empty bytes object.
|
If EOF was received and the internal buffer is empty,
|
||||||
|
return an empty bytes object.
|
||||||
|
|
||||||
If n is zero, return empty bytes object immediately.
|
If `n` is 0, return an empty bytes object immediately.
|
||||||
|
|
||||||
If n is positive, this function try to read `n` bytes, and may return
|
If `n` is positive, return at most `n` available bytes
|
||||||
less or equal bytes than requested, but at least one byte. If EOF was
|
as soon as at least 1 byte is available in the internal buffer.
|
||||||
received before any byte is read, this function returns empty byte
|
If EOF is received before any byte is read, return an empty
|
||||||
object.
|
bytes object.
|
||||||
|
|
||||||
Returned value is not limited with limit, configured at stream
|
Returned value is not limited with limit, configured at stream
|
||||||
creation.
|
creation.
|
||||||
|
|
Loading…
Reference in New Issue