@@ -568,15 +568,19 @@ I/O Base Classes
568
568
569
569
.. method :: read(size=-1, /)
570
570
571
- Read and return up to *size * bytes. If the argument is omitted, ``None ``,
572
- or negative, data is read and returned until EOF is reached. An empty
573
- :class: `bytes ` object is returned if the stream is already at EOF.
571
+ Read and return up to *size * bytes. If the argument is omitted, ``None ``,
572
+ or negative read as much as possible.
574
573
575
- If the argument is positive, and the underlying raw stream is not
576
- interactive, multiple raw reads may be issued to satisfy the byte count
577
- (unless EOF is reached first). But for interactive raw streams, at most
578
- one raw read will be issued, and a short result does not imply that EOF is
579
- imminent.
574
+ Reading as much as possible will use :meth: `~raw.readall ` if available,
575
+ otherwise will read in a loop until read returns ``None ``, a size-zero
576
+ ``bytes ``, or a non-retryable error. For most streams this is to EOF, but
577
+ for non-blocking streams more data may become available.
578
+
579
+ Less bytes may be returned than requested. An empty :class: `bytes ` object
580
+ is returned if the stream is already at EOF. More than one read may be
581
+ made, and calls may be retried if specific errors (ex. :py:const: `errno.EINTR `).
582
+ See :meth: `os.read ` and :pep: `475 ` for more details. Less than size bytes
583
+ being returned does not imply that EOF is imminent.
580
584
581
585
A :exc: `BlockingIOError ` is raised if the underlying raw stream is in
582
586
non blocking-mode, and has no data available at the moment.
@@ -592,6 +596,11 @@ I/O Base Classes
592
596
If *size * is ``-1 `` (the default), an arbitrary number of bytes are
593
597
returned (more than zero unless EOF is reached).
594
598
599
+ .. note ::
600
+
601
+ When the underlying raw stream is non-blocking, a :exc: `BlockingIOError `
602
+ may be raised if a read operation cannot be completed immediately.
603
+
595
604
.. method :: readinto(b, /)
596
605
597
606
Read bytes into a pre-allocated, writable
@@ -737,14 +746,14 @@ than raw I/O does.
737
746
738
747
.. method :: read1(size=-1, /)
739
748
740
- In :class: `BytesIO `, this is the same as :meth: `~ BufferedIOBase.read `.
749
+ In :class: `BytesIO `, this is the same as :meth: `io. BufferedIOBase.read `.
741
750
742
751
.. versionchanged :: 3.7
743
752
The *size * argument is now optional.
744
753
745
754
.. method :: readinto1(b, /)
746
755
747
- In :class: `BytesIO `, this is the same as :meth: `~ BufferedIOBase.readinto `.
756
+ In :class: `BytesIO `, this is the same as :meth: `io. BufferedIOBase.readinto `.
748
757
749
758
.. versionadded :: 3.5
750
759
@@ -767,34 +776,21 @@ than raw I/O does.
767
776
768
777
.. method :: peek(size=0, /)
769
778
770
- Return bytes from the stream without advancing the position. At most one
771
- single read on the raw stream is done to satisfy the call. The number of
772
- bytes returned may be less or more than requested .
779
+ Return bytes from the stream without advancing the position. The number of
780
+ bytes returned may be less or more than requested. If the underlying raw
781
+ stream is non-blocking and the operation would block, returns empty bytes .
773
782
774
783
.. method :: read(size=-1, /)
775
784
776
- Read and return *size * bytes, or if *size * is not given or negative, until
777
- EOF or if the read call would block in non-blocking mode.
778
-
779
- .. note ::
780
-
781
- When the underlying raw stream is non-blocking, a :exc: `BlockingIOError `
782
- may be raised if a read operation cannot be completed immediately.
785
+ In :class: `BufferedReader ` this is the same as :meth: `io.BufferedIOBase.read `
783
786
784
787
.. method :: read1(size=-1, /)
785
788
786
- Read and return up to *size * bytes with only one call on the raw stream.
787
- If at least one byte is buffered, only buffered bytes are returned.
788
- Otherwise, one raw stream read call is made.
789
+ In :class: `BufferedReader ` this is the same as :meth: `io.BufferedIOBase.read1 `
789
790
790
791
.. versionchanged :: 3.7
791
792
The *size * argument is now optional.
792
793
793
- .. note ::
794
-
795
- When the underlying raw stream is non-blocking, a :exc: `BlockingIOError `
796
- may be raised if a read operation cannot be completed immediately.
797
-
798
794
.. class :: BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)
799
795
800
796
A buffered binary stream providing higher-level access to a writeable, non
@@ -856,7 +852,7 @@ than raw I/O does.
856
852
:data: `DEFAULT_BUFFER_SIZE `.
857
853
858
854
:class: `BufferedRWPair ` implements all of :class: `BufferedIOBase `\' s methods
859
- except for :meth: `~ BufferedIOBase.detach `, which raises
855
+ except for :meth: `io. BufferedIOBase.detach `, which raises
860
856
:exc: `UnsupportedOperation `.
861
857
862
858
.. warning ::
@@ -1006,8 +1002,8 @@ Text I/O
1006
1002
If *line_buffering * is ``True ``, :meth: `~IOBase.flush ` is implied when a call to
1007
1003
write contains a newline character or a carriage return.
1008
1004
1009
- If *write_through * is ``True ``, calls to :meth: `~ BufferedIOBase.write ` are guaranteed
1010
- not to be buffered: any data written on the :class: `TextIOWrapper `
1005
+ If *write_through * is ``True ``, calls to :meth: `io. BufferedIOBase.write ` are
1006
+ guaranteed not to be buffered: any data written on the :class: `TextIOWrapper `
1011
1007
object is immediately handled to its underlying binary *buffer *.
1012
1008
1013
1009
.. versionchanged :: 3.3
0 commit comments