summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorÉric Araujo <merwok@netwok.org>2012-11-03 21:07:40 (GMT)
committerÉric Araujo <merwok@netwok.org>2012-11-03 21:07:40 (GMT)
commit8c997fa8bf5970eee0762664f598d13d5c5a48a8 (patch)
tree2946ba096350c9c45cf05b9aa61027c69bfee504
parent51f61b93db406a5d65ab964f0a6c0c0e8e8e7515 (diff)
parent8f423c9359f75d26ee20c1e18f002743046abd72 (diff)
downloadcpython-8c997fa8bf5970eee0762664f598d13d5c5a48a8.zip
cpython-8c997fa8bf5970eee0762664f598d13d5c5a48a8.tar.gz
cpython-8c997fa8bf5970eee0762664f598d13d5c5a48a8.tar.bz2
Merge 3.3
-rw-r--r--Doc/library/functions.rst30
-rw-r--r--Doc/library/io.rst3
-rw-r--r--Misc/ACKS1
3 files changed, 34 insertions, 0 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 0fb48f4..5df7b67 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -935,6 +935,36 @@ are always available. They are listed here in alphabetical order.
:mod:`os.open` as *opener* results in functionality similar to passing
``None``).
+ The following example is an alternative implementation for opening files
+ for exclusive writing. If we did not have support for the ``'x'`` mode,
+ we could implement it with this opener::
+
+ >>> import os
+ >>> def open_exclusive(path, mode):
+ ... return os.open(path, mode | os.O_CREAT | os.O_EXCL)
+ ...
+ >>> filename = 'spam.txt'
+ >>> fp = open(filename, 'w', opener=open_exclusive)
+ >>> fp2 = open(filename, 'w', opener=open_exclusive)
+ Traceback (most recent call last):
+ ...
+ FileExistsError: [Errno 17] File exists: 'spam.txt'
+
+ This other example uses the :ref:`dir_fd` parameter of the
+ :func:`os.open` function to open a file relative to a given directory::
+
+ >>> import os
+ >>> def open_relative(dirname):
+ ... dir_fd = os.open(dirname, os.O_RDONLY)
+ ... def opener(path, flags):
+ ... return os.open(path, flags, dir_fd=dir_fd)
+ ... return opener
+ ...
+ >>> opener = open_relative('somedir')
+ >>> with open('spamspam.txt', 'w', opener=opener) as f:
+ ... print('This will be written to somedir/spamspam.txt', file=f)
+ ...
+
.. versionchanged:: 3.3
The *opener* parameter was added.
The ``'x'`` mode was added.
diff --git a/Doc/library/io.rst b/Doc/library/io.rst
index e83e55c..44e663d 100644
--- a/Doc/library/io.rst
+++ b/Doc/library/io.rst
@@ -498,6 +498,9 @@ Raw File I/O
:mod:`os.open` as *opener* results in functionality similar to passing
``None``).
+ See the :func:`open` built-in function for examples on using the *opener*
+ parameter.
+
.. versionchanged:: 3.3
The *opener* parameter was added.
The ``'x'`` mode was added.
diff --git a/Misc/ACKS b/Misc/ACKS
index 7f29033..49081e8 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -931,6 +931,7 @@ Michael Pomraning
Iustin Pop
Claudiu Popa
John Popplewell
+Guillaume Pratte
Amrit Prem
Paul Prescod
Donovan Preston