mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Issue #12797: Added custom opener parameter to builtin open() and FileIO.open().
This commit is contained in:
parent
ab06e3f285
commit
59142db6d3
7 changed files with 89 additions and 22 deletions
|
|
@ -776,7 +776,7 @@ are always available. They are listed here in alphabetical order.
|
|||
:meth:`__index__` method that returns an integer.
|
||||
|
||||
|
||||
.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)
|
||||
.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
|
||||
|
||||
Open *file* and return a corresponding stream. If the file cannot be opened,
|
||||
an :exc:`OSError` is raised.
|
||||
|
|
@ -883,6 +883,15 @@ are always available. They are listed here in alphabetical order.
|
|||
closed. If a filename is given *closefd* has no effect and must be ``True``
|
||||
(the default).
|
||||
|
||||
A custom opener can be used by passing a callable as *opener*. The underlying
|
||||
file descriptor for the file object is then obtained by calling *opener* with
|
||||
(*file*, *flags*). *opener* must return an open file descriptor (passing
|
||||
:mod:`os.open` as *opener* results in functionality similar to passing
|
||||
``None``).
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
The *opener* parameter was added.
|
||||
|
||||
The type of file object returned by the :func:`open` function depends on the
|
||||
mode. When :func:`open` is used to open a file in a text mode (``'w'``,
|
||||
``'r'``, ``'wt'``, ``'rt'``, etc.), it returns a subclass of
|
||||
|
|
|
|||
|
|
@ -458,7 +458,7 @@ I/O Base Classes
|
|||
Raw File I/O
|
||||
^^^^^^^^^^^^
|
||||
|
||||
.. class:: FileIO(name, mode='r', closefd=True)
|
||||
.. class:: FileIO(name, mode='r', closefd=True, opener=None)
|
||||
|
||||
:class:`FileIO` represents an OS-level file containing bytes data.
|
||||
It implements the :class:`RawIOBase` interface (and therefore the
|
||||
|
|
@ -479,6 +479,15 @@ Raw File I/O
|
|||
The :meth:`read` (when called with a positive argument), :meth:`readinto`
|
||||
and :meth:`write` methods on this class will only make one system call.
|
||||
|
||||
A custom opener can be used by passing a callable as *opener*. The underlying
|
||||
file descriptor for the file object is then obtained by calling *opener* with
|
||||
(*name*, *flags*). *opener* must return an open file descriptor (passing
|
||||
:mod:`os.open` as *opener* results in functionality similar to passing
|
||||
``None``).
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
The *opener* parameter was added.
|
||||
|
||||
In addition to the attributes and methods from :class:`IOBase` and
|
||||
:class:`RawIOBase`, :class:`FileIO` provides the following data
|
||||
attributes and methods:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue