@@ -33,7 +33,7 @@ is recommended to use keyword arguments for clarity.
33
33
34
34
The module defines the following user-callable items:
35
35
36
- .. function :: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='' , prefix='tmp' , dir=None)
36
+ .. function :: TemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix=None , prefix=None , dir=None)
37
37
38
38
Return a :term: `file-like object ` that can be used as a temporary storage area.
39
39
The file is created securely, using the same rules as :func: `mkstemp `. It will be destroyed as soon
@@ -54,8 +54,8 @@ The module defines the following user-callable items:
54
54
stored. *buffering *, *encoding * and *newline * are interpreted as for
55
55
:func: `open `.
56
56
57
- The *dir *, *prefix * and *suffix * parameters have the same meaning
58
- as with :func: `mkstemp `.
57
+ The *dir *, *prefix * and *suffix * parameters have the same meaning and
58
+ defaults as with :func: `mkstemp `.
59
59
60
60
The returned object is a true file object on POSIX platforms. On other
61
61
platforms, it is a file-like object whose :attr: `!file ` attribute is the
@@ -69,7 +69,7 @@ The module defines the following user-callable items:
69
69
The :py:data: `os.O_TMPFILE ` flag is now used if available.
70
70
71
71
72
- .. function :: NamedTemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix='' , prefix='tmp' , dir=None, delete=True)
72
+ .. function :: NamedTemporaryFile(mode='w+b', buffering=None, encoding=None, newline=None, suffix=None , prefix=None , dir=None, delete=True)
73
73
74
74
This function operates exactly as :func: `TemporaryFile ` does, except that
75
75
the file is guaranteed to have a visible name in the file system (on
@@ -84,7 +84,7 @@ The module defines the following user-callable items:
84
84
be used in a :keyword: `with ` statement, just like a normal file.
85
85
86
86
87
- .. function :: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=None, encoding=None, newline=None, suffix='' , prefix='tmp' , dir=None)
87
+ .. function :: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=None, encoding=None, newline=None, suffix=None , prefix=None , dir=None)
88
88
89
89
This function operates exactly as :func: `TemporaryFile ` does, except that
90
90
data is spooled in memory until the file size exceeds *max_size *, or
@@ -106,7 +106,7 @@ The module defines the following user-callable items:
106
106
the truncate method now accepts a ``size `` argument.
107
107
108
108
109
- .. function :: TemporaryDirectory(suffix='' , prefix='tmp' , dir=None)
109
+ .. function :: TemporaryDirectory(suffix=None , prefix=None , dir=None)
110
110
111
111
This function securely creates a temporary directory using the same rules as :func: `mkdtemp `.
112
112
The resulting object can be used as a context manager (see
@@ -138,32 +138,29 @@ The module defines the following user-callable items:
138
138
Unlike :func: `TemporaryFile `, the user of :func: `mkstemp ` is responsible
139
139
for deleting the temporary file when done with it.
140
140
141
- If *suffix * is specified , the file name will end with that suffix,
141
+ If *suffix * is not `` None `` , the file name will end with that suffix,
142
142
otherwise there will be no suffix. :func: `mkstemp ` does not put a dot
143
143
between the file name and the suffix; if you need one, put it at the
144
144
beginning of *suffix *.
145
145
146
- If *prefix * is specified, the file name will begin with that prefix;
147
- otherwise, a default prefix is used.
146
+ If *prefix * is not ``None ``, the file name will begin with that prefix;
147
+ otherwise, a default prefix is used. The default is the return value of
148
+ :func: `gettempprefix ` or :func: `gettempprefixb `, as appropriate.
148
149
149
- If *dir * is specified , the file will be created in that directory;
150
+ If *dir * is not `` None `` , the file will be created in that directory;
150
151
otherwise, a default directory is used. The default directory is chosen
151
152
from a platform-dependent list, but the user of the application can
152
153
control the directory location by setting the *TMPDIR *, *TEMP * or *TMP *
153
154
environment variables. There is thus no guarantee that the generated
154
155
filename will have any nice properties, such as not requiring quoting
155
156
when passed to external commands via ``os.popen() ``.
156
157
157
- *suffix *, *prefix *, and *dir * must all contain the same type, if specified.
158
+ If any of *suffix *, *prefix *, and *dir * are not
159
+ ``None ``, they must be the same type.
158
160
If they are bytes, the returned name will be bytes instead of str.
159
161
If you want to force a bytes return value with otherwise default behavior,
160
162
pass ``suffix=b'' ``.
161
163
162
- A *prefix * value of ``None `` means use the return value of
163
- :func: `gettempprefix ` or :func: `gettempprefixb ` as appropriate.
164
-
165
- A *suffix * value of ``None `` means use an appropriate empty value.
166
-
167
164
If *text * is specified, it indicates whether to open the file in binary
168
165
mode (the default) or text mode. On some platforms, this makes no
169
166
difference.
@@ -241,7 +238,7 @@ The module defines the following user-callable items:
241
238
242
239
.. function :: gettempprefixb()
243
240
244
- Same as :func: `gettempprefixb ` but the return value is in bytes.
241
+ Same as :func: `gettempprefix ` but the return value is in bytes.
245
242
246
243
.. versionadded :: 3.5
247
244
@@ -314,8 +311,9 @@ other functions described above.
314
311
Use :func: `mkstemp ` instead.
315
312
316
313
Return an absolute pathname of a file that did not exist at the time the
317
- call is made. The *prefix *, *suffix *, and *dir * arguments are the same
318
- as for :func: `mkstemp `.
314
+ call is made. The *prefix *, *suffix *, and *dir * arguments are similar
315
+ to those of :func: `mkstemp `, except that bytes file names, ``suffix=None ``
316
+ and ``prefix=None `` are not supported.
319
317
320
318
.. warning ::
321
319
0 commit comments