summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2011-10-31 18:34:46 (GMT)
committerRoss Lagerwall <rosslagerwall@gmail.com>2011-10-31 18:34:46 (GMT)
commit59142db6d35f00142cd9982878e75d43cbda7a68 (patch)
treecf1d1ca5ffda256d0b9fe259c7c5726d3e897482 /Doc/library
parentab06e3f285ae61e5abc48b350034c94b7d624fda (diff)
downloadcpython-59142db6d35f00142cd9982878e75d43cbda7a68.zip
cpython-59142db6d35f00142cd9982878e75d43cbda7a68.tar.gz
cpython-59142db6d35f00142cd9982878e75d43cbda7a68.tar.bz2
Issue #12797: Added custom opener parameter to builtin open() and FileIO.open().
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/functions.rst11
-rw-r--r--Doc/library/io.rst11
2 files changed, 20 insertions, 2 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index f63cea4..f9af3d8 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -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
diff --git a/Doc/library/io.rst b/Doc/library/io.rst
index 0bcf687..1da7e4c 100644
--- a/Doc/library/io.rst
+++ b/Doc/library/io.rst
@@ -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: