Skip to content

Commit 3cb0a65

Browse files
gh-148467: Move BufferedIOBase close to concrete implementations
This reverts commit b6c7beb.
1 parent 494f2e3 commit 3cb0a65

1 file changed

Lines changed: 67 additions & 67 deletions

File tree

Doc/library/io.rst

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,73 @@ I/O Base Classes
514514
during the method call.
515515

516516

517+
Raw File I/O
518+
^^^^^^^^^^^^
519+
520+
.. class:: FileIO(name, mode='r', closefd=True, opener=None)
521+
522+
A raw binary stream representing an OS-level file containing bytes data. It
523+
inherits from :class:`RawIOBase`.
524+
525+
The *name* can be one of two things:
526+
527+
* a character string or :class:`bytes` object representing the path to the
528+
file which will be opened. In this case closefd must be ``True`` (the default)
529+
otherwise an error will be raised.
530+
* an integer representing the number of an existing OS-level file descriptor
531+
to which the resulting :class:`FileIO` object will give access. When the
532+
FileIO object is closed this fd will be closed as well, unless *closefd*
533+
is set to ``False``.
534+
535+
The *mode* can be ``'r'``, ``'w'``, ``'x'`` or ``'a'`` for reading
536+
(default), writing, exclusive creation or appending. The file will be
537+
created if it doesn't exist when opened for writing or appending; it will be
538+
truncated when opened for writing. :exc:`FileExistsError` will be raised if
539+
it already exists when opened for creating. Opening a file for creating
540+
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
541+
``'+'`` to the mode to allow simultaneous reading and writing.
542+
543+
The :meth:`~RawIOBase.read` (when called with a positive argument),
544+
:meth:`~RawIOBase.readinto` and :meth:`~RawIOBase.write` methods on this
545+
class will only make one system call.
546+
547+
A custom opener can be used by passing a callable as *opener*. The underlying
548+
file descriptor for the file object is then obtained by calling *opener* with
549+
(*name*, *flags*). *opener* must return an open file descriptor (passing
550+
:mod:`os.open` as *opener* results in functionality similar to passing
551+
``None``).
552+
553+
The newly created file is :ref:`non-inheritable <fd_inheritance>`.
554+
555+
See the :func:`open` built-in function for examples on using the *opener*
556+
parameter.
557+
558+
.. versionchanged:: 3.3
559+
The *opener* parameter was added.
560+
The ``'x'`` mode was added.
561+
562+
.. versionchanged:: 3.4
563+
The file is now non-inheritable.
564+
565+
:class:`FileIO` provides these data attributes in addition to those from
566+
:class:`RawIOBase` and :class:`IOBase`:
567+
568+
.. attribute:: mode
569+
570+
The mode as given in the constructor.
571+
572+
.. attribute:: name
573+
574+
The file name. This is the file descriptor of the file when no name is
575+
given in the constructor.
576+
577+
578+
Buffered Streams
579+
^^^^^^^^^^^^^^^^
580+
581+
Buffered I/O streams provide a higher-level interface to an I/O device
582+
than raw I/O does.
583+
517584
.. class:: BufferedIOBase
518585

519586
Base class for binary streams that support some kind of buffering.
@@ -635,73 +702,6 @@ I/O Base Classes
635702
so the implementation should only access *b* during the method call.
636703

637704

638-
Raw File I/O
639-
^^^^^^^^^^^^
640-
641-
.. class:: FileIO(name, mode='r', closefd=True, opener=None)
642-
643-
A raw binary stream representing an OS-level file containing bytes data. It
644-
inherits from :class:`RawIOBase`.
645-
646-
The *name* can be one of two things:
647-
648-
* a character string or :class:`bytes` object representing the path to the
649-
file which will be opened. In this case closefd must be ``True`` (the default)
650-
otherwise an error will be raised.
651-
* an integer representing the number of an existing OS-level file descriptor
652-
to which the resulting :class:`FileIO` object will give access. When the
653-
FileIO object is closed this fd will be closed as well, unless *closefd*
654-
is set to ``False``.
655-
656-
The *mode* can be ``'r'``, ``'w'``, ``'x'`` or ``'a'`` for reading
657-
(default), writing, exclusive creation or appending. The file will be
658-
created if it doesn't exist when opened for writing or appending; it will be
659-
truncated when opened for writing. :exc:`FileExistsError` will be raised if
660-
it already exists when opened for creating. Opening a file for creating
661-
implies writing, so this mode behaves in a similar way to ``'w'``. Add a
662-
``'+'`` to the mode to allow simultaneous reading and writing.
663-
664-
The :meth:`~RawIOBase.read` (when called with a positive argument),
665-
:meth:`~RawIOBase.readinto` and :meth:`~RawIOBase.write` methods on this
666-
class will only make one system call.
667-
668-
A custom opener can be used by passing a callable as *opener*. The underlying
669-
file descriptor for the file object is then obtained by calling *opener* with
670-
(*name*, *flags*). *opener* must return an open file descriptor (passing
671-
:mod:`os.open` as *opener* results in functionality similar to passing
672-
``None``).
673-
674-
The newly created file is :ref:`non-inheritable <fd_inheritance>`.
675-
676-
See the :func:`open` built-in function for examples on using the *opener*
677-
parameter.
678-
679-
.. versionchanged:: 3.3
680-
The *opener* parameter was added.
681-
The ``'x'`` mode was added.
682-
683-
.. versionchanged:: 3.4
684-
The file is now non-inheritable.
685-
686-
:class:`FileIO` provides these data attributes in addition to those from
687-
:class:`RawIOBase` and :class:`IOBase`:
688-
689-
.. attribute:: mode
690-
691-
The mode as given in the constructor.
692-
693-
.. attribute:: name
694-
695-
The file name. This is the file descriptor of the file when no name is
696-
given in the constructor.
697-
698-
699-
Buffered Streams
700-
^^^^^^^^^^^^^^^^
701-
702-
Buffered I/O streams provide a higher-level interface to an I/O device
703-
than raw I/O does.
704-
705705
.. class:: BytesIO(initial_bytes=b'')
706706

707707
A binary stream using an in-memory bytes buffer. It inherits from

0 commit comments

Comments
 (0)