@@ -18,7 +18,7 @@ This module creates temporary files and directories. It works on all
18
18
supported platforms. :class: `TemporaryFile `, :class: `NamedTemporaryFile `,
19
19
:class: `TemporaryDirectory `, and :class: `SpooledTemporaryFile ` are high-level
20
20
interfaces which provide automatic cleanup and can be used as
21
- context managers. :func: `mkstemp ` and
21
+ :term: ` context managers <context manager> ` . :func: `mkstemp ` and
22
22
:func: `mkdtemp ` are lower-level functions which require manual cleanup.
23
23
24
24
All the user-callable functions and constructors take additional arguments which
@@ -41,7 +41,7 @@ The module defines the following user-callable items:
41
41
this; your code should not rely on a temporary file created using this
42
42
function having or not having a visible name in the file system.
43
43
44
- The resulting object can be used as a context manager (see
44
+ The resulting object can be used as a :term: ` context manager ` (see
45
45
:ref: `tempfile-examples `). On completion of the context or
46
46
destruction of the file object the temporary file will be removed
47
47
from the filesystem.
@@ -107,18 +107,20 @@ The module defines the following user-callable items:
107
107
contents are written to disk and operation proceeds as with
108
108
:func: `TemporaryFile `.
109
109
110
- The resulting file has one additional method, :func: `rollover `, which
111
- causes the file to roll over to an on-disk file regardless of its size.
110
+ .. method :: SpooledTemporaryFile.rollover
112
111
113
- The returned object is a file-like object whose :attr: `_file ` attribute
112
+ The resulting file has one additional method, :meth: `!rollover `, which
113
+ causes the file to roll over to an on-disk file regardless of its size.
114
+
115
+ The returned object is a file-like object whose :attr: `!_file ` attribute
114
116
is either an :class: `io.BytesIO ` or :class: `io.TextIOWrapper ` object
115
117
(depending on whether binary or text *mode * was specified) or a true file
116
- object, depending on whether :func : `rollover ` has been called. This
118
+ object, depending on whether :meth : `rollover ` has been called. This
117
119
file-like object can be used in a :keyword: `with ` statement, just like
118
120
a normal file.
119
121
120
122
.. versionchanged :: 3.3
121
- the truncate method now accepts a `` size `` argument.
123
+ the truncate method now accepts a * size * argument.
122
124
123
125
.. versionchanged :: 3.8
124
126
Added *errors * parameter.
@@ -132,24 +134,28 @@ The module defines the following user-callable items:
132
134
.. class :: TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False)
133
135
134
136
This class securely creates a temporary directory using the same rules as :func: `mkdtemp `.
135
- The resulting object can be used as a context manager (see
137
+ The resulting object can be used as a :term: ` context manager ` (see
136
138
:ref: `tempfile-examples `). On completion of the context or destruction
137
139
of the temporary directory object, the newly created temporary directory
138
140
and all its contents are removed from the filesystem.
139
141
140
- The directory name can be retrieved from the :attr: `name ` attribute of the
141
- returned object. When the returned object is used as a context manager, the
142
- :attr: `name ` will be assigned to the target of the :keyword: `!as ` clause in
143
- the :keyword: `with ` statement, if there is one.
144
-
145
- The directory can be explicitly cleaned up by calling the
146
- :func: `cleanup ` method. If *ignore_cleanup_errors * is true, any unhandled
147
- exceptions during explicit or implicit cleanup (such as a
148
- :exc: `PermissionError ` removing open files on Windows) will be ignored,
149
- and the remaining removable items deleted on a "best-effort" basis.
150
- Otherwise, errors will be raised in whatever context cleanup occurs
151
- (the :func: `cleanup ` call, exiting the context manager, when the object
152
- is garbage-collected or during interpreter shutdown).
142
+ .. attribute :: TemporaryDirectory.name
143
+
144
+ The directory name can be retrieved from the :attr: `!name ` attribute of the
145
+ returned object. When the returned object is used as a :term: `context manager `, the
146
+ :attr: `!name ` will be assigned to the target of the :keyword: `!as ` clause in
147
+ the :keyword: `with ` statement, if there is one.
148
+
149
+ .. method :: TemporaryDirectory.cleanup
150
+
151
+ The directory can be explicitly cleaned up by calling the
152
+ :meth: `!cleanup ` method. If *ignore_cleanup_errors * is true, any unhandled
153
+ exceptions during explicit or implicit cleanup (such as a
154
+ :exc: `PermissionError ` removing open files on Windows) will be ignored,
155
+ and the remaining removable items deleted on a "best-effort" basis.
156
+ Otherwise, errors will be raised in whatever context cleanup occurs
157
+ (the :meth: `!cleanup ` call, exiting the context manager, when the object
158
+ is garbage-collected or during interpreter shutdown).
153
159
154
160
.. audit-event :: tempfile.mkdtemp fullpath tempfile.TemporaryDirectory
155
161
0 commit comments