summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2015-05-22 23:18:14 (GMT)
committerGregory P. Smith <greg@krypto.org>2015-05-22 23:18:14 (GMT)
commitad577b938b367da53ee19d6d5021b19e50b92873 (patch)
tree814a45237ffda590168ac368a0a4e20c40fa4d0e /Doc
parent4a7fe7e3975062a939a4e7242f2a12b172befd8a (diff)
downloadcpython-ad577b938b367da53ee19d6d5021b19e50b92873.zip
cpython-ad577b938b367da53ee19d6d5021b19e50b92873.tar.gz
cpython-ad577b938b367da53ee19d6d5021b19e50b92873.tar.bz2
Issue 24230: The tempfile module now accepts bytes for prefix, suffix and dir
parameters and returns bytes in such situations (matching the os module APIs).
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/tempfile.rst37
-rw-r--r--Doc/whatsnew/3.5.rst7
2 files changed, 41 insertions, 3 deletions
diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst
index 2c68377..0387fb1 100644
--- a/Doc/library/tempfile.rst
+++ b/Doc/library/tempfile.rst
@@ -119,7 +119,7 @@ The module defines the following user-callable items:
.. versionadded:: 3.2
-.. function:: mkstemp(suffix='', prefix='tmp', dir=None, text=False)
+.. function:: mkstemp(suffix=None, prefix=None, dir=None, text=False)
Creates a temporary file in the most secure manner possible. There are
no race conditions in the file's creation, assuming that the platform
@@ -148,6 +148,16 @@ The module defines the following user-callable items:
filename will have any nice properties, such as not requiring quoting
when passed to external commands via ``os.popen()``.
+ *suffix*, *prefix*, and *dir* must all contain the same type, if specified.
+ If they are bytes, the returned name will be bytes instead of str.
+ If you want to force a bytes return value with otherwise default behavior,
+ pass ``suffix=b''``.
+
+ A *prefix* value of ``None`` means use the return value of
+ :func:`gettempprefix` or :func:`gettempprefixb` as appropriate.
+
+ A *suffix* value of ``None`` means use an appropriate empty value.
+
If *text* is specified, it indicates whether to open the file in binary
mode (the default) or text mode. On some platforms, this makes no
difference.
@@ -156,8 +166,14 @@ The module defines the following user-callable items:
file (as would be returned by :func:`os.open`) and the absolute pathname
of that file, in that order.
+ .. versionchanged:: 3.5
+ *suffix*, *prefix*, and *dir* may now be supplied in bytes in order to
+ obtain a bytes return value. Prior to this, only str was allowed.
+ *suffix* and *prefix* now accept and default to ``None`` to cause
+ an appropriate default value to be used.
+
-.. function:: mkdtemp(suffix='', prefix='tmp', dir=None)
+.. function:: mkdtemp(suffix=None, prefix=None, dir=None)
Creates a temporary directory in the most secure manner possible. There
are no race conditions in the directory's creation. The directory is
@@ -171,6 +187,12 @@ The module defines the following user-callable items:
:func:`mkdtemp` returns the absolute pathname of the new directory.
+ .. versionchanged:: 3.5
+ *suffix*, *prefix*, and *dir* may now be supplied in bytes in order to
+ obtain a bytes return value. Prior to this, only str was allowed.
+ *suffix* and *prefix* now accept and default to ``None`` to cause
+ an appropriate default value to be used.
+
.. function:: mktemp(suffix='', prefix='tmp', dir=None)
@@ -239,12 +261,23 @@ the appropriate function arguments, instead.
:data:`tempdir` is not ``None``, this simply returns its contents; otherwise,
the search described above is performed, and the result returned.
+.. function:: gettempdirb()
+
+ Same as :func:`gettempdir` but the return value is in bytes.
+
+ .. versionadded:: 3.5
.. function:: gettempprefix()
Return the filename prefix used to create temporary files. This does not
contain the directory component.
+.. function:: gettempprefixb()
+
+ Same as :func:`gettempprefixb` but the return value is in bytes.
+
+ .. versionadded:: 3.5
+
Examples
--------
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst
index 0a17969..c0f9346 100644
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -96,7 +96,12 @@ Implementation improvements:
Significantly Improved Library Modules:
-* None yet.
+* You may now pass bytes to the :mod:`tempfile` module's APIs and it will
+ return the temporary pathname as bytes instead of str. It also accepts
+ a value of ``None`` on parameters where only str was accepted in the past to
+ do the right thing based on the types of the other inputs. Two functions,
+ :func:`gettempdirb` and :func:`gettempprefixb`, have been added to go along
+ with this. This behavior matches that of the :mod:`os` APIs.
Security improvements: