summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
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 /Lib/_pyio.py
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 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 3bd35d2..39c1717 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -27,7 +27,7 @@ BlockingIOError = BlockingIOError
def open(file, mode="r", buffering=-1, encoding=None, errors=None,
- newline=None, closefd=True):
+ newline=None, closefd=True, opener=None):
r"""Open file and return a stream. Raise IOError upon failure.
@@ -122,6 +122,12 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
be kept open when the file is closed. This does not work when a file name is
given and must be True in that case.
+ 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 os.open as *opener* results in functionality similar to
+ passing None).
+
open() returns a file object whose type depends on the mode, and
through which the standard file operations such as reading and writing
are performed. When open() is used to open a file in a text mode ('w',
@@ -176,7 +182,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
(writing and "w" or "") +
(appending and "a" or "") +
(updating and "+" or ""),
- closefd)
+ closefd, opener=opener)
line_buffering = False
if buffering == 1 or buffering < 0 and raw.isatty():
buffering = -1