Commit Graph

188 Commits

Author SHA1 Message Date
Samuel Sloniker 32bea69b89
gh-51574: Make tempfile.mkdtemp() always return absolute paths (#94612)
Co-authored-by: Éric <merwok@netwok.org>
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2023-04-25 16:05:59 +00:00
JakobDev 64cb1a4f0f
gh-100131: Add optional delete parameter to tempfile.TemporaryDirectory() (#100132)
Add optional delete parameter to tempfile.TemporaryDirectory().

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-03-24 14:52:06 -07:00
Irit Katriel 7f760c2fca
gh-102828: emit deprecation warning for onerror arg to shutil.rmtree (#102850) 2023-03-21 11:08:46 +00:00
Ev2geny 743453a554
gh-58451: Add optional delete_on_close parameter to NamedTemporaryFile (GH-97015) 2022-10-04 23:37:33 +01:00
Serhiy Storchaka d4792ce916
gh-83499: Fix closing file descriptors in tempfile (GH-93874) 2022-06-26 10:58:28 +03:00
Carey Metcalfe 78e70be331
gh-70363: Implement `io.IOBase` interface for `SpooledTemporaryFile` (GH-29560)
Since the underlying file-like objects (either `io.BytesIO`,
or a true file object) all implement the `io.IOBase`
interface, the `SpooledTemporaryFile` should as well.

Additionally, since the underlying file object will either be an
instance of an `io.BufferedIOBase` (for binary mode) or an
`io.TextIOBase` (for text mode), methods for these classes were also
implemented.

In every case, the required methods and properties are simply delegated
to the underlying file object.

Co-authored-by: Gary Fernie <Gary.Fernie@skyscanner.net>
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
2022-05-03 21:18:18 +09:00
Kyungmin Lee 6270d3eeaf
bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323)
An object implementing the os.PathLike protocol can represent a file
system path as a str or bytes object.
Therefore, _infer_return_type function should infer os.PathLike[str]
object as str type and os.PathLike[bytes] object as bytes type.
2021-10-20 21:54:41 +02:00
Catherine Devlin b3ab4344d1
bpo-4928: Document NamedTemporaryFile non-deletion after SIGKILL (#26198)
* bpo-4928 Document NamedTemporaryFile non-deletion after SIGKILL

* 📜🤖 Added by blurb_it.

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2021-05-19 10:21:03 -04:00
Inada Naoki 4827483f47
bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)
See [PEP 597](https://www.python.org/dev/peps/pep-0597/).

* Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`.
* Add EncodingWarning
* Add io.text_encoding()
* open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled.
* _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python)
* bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding().
* What's new entry
2021-03-29 12:28:14 +09:00
CAM Gerlach bd2fa3c416
bpo-29982: Add "ignore_cleanup_errors" param to tempfile.TemporaryDirectory() (GH-24793) 2021-03-14 11:06:56 -07:00
Eric L 9c7927400c
bpo-40701: tempfile mixes str and bytes in an inconsistent manner (GH-20442)
The case of tempfile.tempdir variable being bytes is now handled consistently.
The getters return the right type and no more error of mixing str and bytes unless explicitly caused by the user.

Adds a regression test.

Expands the documentation to clarify the behavior.

Co-authored-by: Eric L <ewl+git@lavar.de>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2021-03-03 12:36:22 -08:00
Inada Naoki d2810054c7
tempfile: Use random.choises() instead of choise() (GH-23068) 2020-11-01 20:02:03 +09:00
Inada Naoki 43ca084c88
Revert "bpo-42160: tempfile: Reduce overhead of pid check. (GH-22997)"
`_RandomNameSequence` is not true singleton so using `os.register_at_fork` doesn't make sense unlike `random._inst`.

This reverts commit 8e409cebad.
2020-10-31 11:15:38 +09:00
Eric W 8e409cebad
bpo-42160: tempfile: Reduce overhead of pid check. (GH-22997)
The _RandomSequence class in tempfile used to check the current pid every time its rng property was used.
This commit replaces this code with `os.register_at_fork` to reduce the overhead.
2020-10-30 13:56:28 +09:00
Rishav Kundu e55de68be3
bpo-41410: Fix outdated info in mkstemp docs (GH-21701)
Automerge-Triggered-By: @ericvsmith
2020-08-13 18:33:14 -07:00
Inada Naoki 485e715cb1
bpo-40287: Fix SpooledTemporaryFile.seek() return value (GH-19540)
It has not returned the file position after the seek.
2020-04-17 15:56:35 +09:00
Batuhan Taşkaya 0361556537
bpo-39481: PEP 585 for a variety of modules (GH-19423)
- concurrent.futures
- ctypes
- http.cookies
- multiprocessing
- queue
- tempfile
- unittest.case
- urllib.parse
2020-04-10 07:46:36 -07:00
Guido van Rossum 48b069a003
bpo-39481: Implementation for PEP 585 (#18239)
This implements things like `list[int]`,
which returns an object of type `types.GenericAlias`.
This object mostly acts as a proxy for `list`,
but has attributes `__origin__` and `__args__`
that allow recovering the parts (with values `list` and `(int,)`.

There is also an approximate notion of type variables;
e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`.
Type variables are objects of type `typing.TypeVar`.
2020-04-07 09:50:06 -07:00
Shantanu d469d666b8
bpo-39719: Remove softspace from tempfile.SpooledTemporaryFile (GH-18599) 2020-03-17 23:43:20 +02:00
Batuhan Taşkaya 09c482fad1 bpo-39019: Implement missing __class_getitem__ for SpooledTemporaryFile (GH-17560) 2019-12-30 16:08:08 +00:00
Inada Naoki ea9835c5d1
bpo-26730: Fix SpooledTemporaryFile data corruption (GH-17400)
SpooledTemporaryFile.rollback() might cause data corruption
when it is in text mode.

Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
2019-11-27 22:22:06 +09:00
Steve Dower 60419a7e96
bpo-37363: Add audit events for a range of modules (GH-14301) 2019-06-24 08:42:54 -07:00
Serhiy Storchaka e9b51c0ad8
bpo-26660, bpo-35144: Fix permission errors in TemporaryDirectory cleanup. (GH-10320)
TemporaryDirectory.cleanup() failed when non-writeable or non-searchable
files or directories were created inside a temporary directory.
2019-05-31 11:30:37 +03:00
Anthony Sottile 8377cd4fcd Clean up code which checked presence of os.{stat,lstat,chmod} (#11643) 2019-02-25 23:32:27 +01:00
sth 825aab95fd bpo-27300: Add the errors parameter to tempfile classes. (GH-6696) 2018-05-23 08:07:01 +03:00
Steve Dower e5f41d2f1e
bpo-33522: Enable CI builds on Visual Studio Team Services (#6865) 2018-05-16 17:50:29 -04:00
Wolfgang Maier 9c463ec88b Update docstring of tempfile._RandomNameSequence (GH-6414)
When bpo-12015 got resolved by increasing the length of the
random string generated by _RandomNameSequence from six to eight
characters, the docstring of the class was not adjusted accordingly.
2018-04-09 09:42:39 +09:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Victor Stinner 1e62bf145b bpo-30030: Revert f50354ad (tempfile) (#1187)
Revert f50354adaaafebe95ad09d09b825804a686ea843: it introduced a
regression in test_threadedtempfile.
2017-04-19 22:59:51 +02:00
Serhiy Storchaka f50354adaa Reimplement tempfile._RandomNameSequence using a generator function. (#1075) 2017-04-11 22:45:59 +03:00
Victor Stinner e19558af1b Add a source parameter to warnings.warn()
Issue #26604:

* Add a new optional source parameter to _warnings.warn() and warnings.warn()
* Modify asyncore, asyncio and _pyio modules to set the source parameter when
  logging a ResourceWarning warning
2016-03-23 00:28:08 +01:00
Martin Panter 7869a22779 Issue #26385: Cleanup NamedTemporaryFile if open() fails, by SilentGhost 2016-02-28 05:22:20 +00:00
Martin Panter 1f0e1f3cbb Issue #26261: Clarify NamedTemporaryFile name attribute vs file.name 2016-02-22 10:10:00 +00:00
Martin Panter 9b566c324d Issue #25064: Adjust documentation according to new mkstemp signature
The mkstemp() and mkdtemp() signatures have already been updated, but the
higher-level functions still suggest that the default values are forced to
text strings. Also merged some paragraphs describing the "suffix" and
"prefix" parameters, and pointed out that mktemp() does not support the new
changes.
2015-11-07 00:32:50 +00:00
Victor Stinner 9aba8c8a95 Issue #21515: Elaborate tempfile.TemporaryFile() comment
Explain why calling os.open() with os.O_TMPFILE is a safe test to check if
O_TMPFILE is supported by the running kernel.
2015-10-21 00:15:08 +02:00
Gregory P. Smith ad577b938b 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).
2015-05-22 16:18:14 -07:00
Serhiy Storchaka 492f027793 Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again
when a directory with the chosen name already exists on Windows as well as
on Unix.  tempfile.mkstemp() now fails early if parent directory is not
valid (not exists or is a file) on Windows.
2015-05-20 00:14:00 +03:00
Serhiy Storchaka 5d6b7b1cb7 Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again
when a directory with the chosen name already exists on Windows as well as
on Unix.  tempfile.mkstemp() now fails early if parent directory is not
valid (not exists or is a file) on Windows.
2015-05-20 00:11:48 +03:00
Serhiy Storchaka 7e7a3dba5f Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released
even if errors are occured.
2015-04-10 13:24:41 +03:00
Serhiy Storchaka 2116b12da5 Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released
even if errors are occured.
2015-04-10 13:29:28 +03:00
R David Murray 5d06c74f41 Merge: #23700: fix/improve comment 2015-03-22 12:34:50 -04:00
R David Murray 75ed90a4cf #23700: fix/improve comment 2015-03-22 12:33:46 -04:00
Serhiy Storchaka 000391b7de Issue #23700: NamedTemporaryFile iterator closed underlied file object in
some circunstances while NamedTemporaryFile object was living.  This causes
failing test_csv.  Changed the implementation of NamedTemporaryFile.__iter__
to make tests passed.
2015-03-20 16:12:43 +02:00
Serhiy Storchaka d83b7c2df4 Issue #23700: NamedTemporaryFile iterator closed underlied file object in
some circunstances while NamedTemporaryFile object was living.  This causes
failing test_csv.  Changed the implementation of NamedTemporaryFile.__iter__
to make tests passed.
2015-03-20 16:11:20 +02:00
Serhiy Storchaka 4f418d3671 Issue #23700: Iterator of NamedTemporaryFile now keeps a reference to
NamedTemporaryFile instance.  Patch by Bohuslav Kabrda.
2015-03-19 15:24:27 +02:00
Serhiy Storchaka 56cefa69ee Issue #23700: Iterator of NamedTemporaryFile now keeps a reference to
NamedTemporaryFile instance.  Patch by Bohuslav Kabrda.
2015-03-19 15:23:15 +02:00
Yury Selivanov 0b86660891 tempfile: Fix docstring. Issue #21397, patch by R. David Murray. 2014-09-26 17:08:21 -04:00
Serhiy Storchaka e9a086bf01 Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
2014-09-24 13:29:27 +03:00
Serhiy Storchaka 5e193ac0bd Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
2014-09-24 13:26:25 +03:00
Yury Selivanov 3e67d583ee tempfile: Fix docstring. Issue #21397, patch by R. David Murray. 2014-09-26 17:08:02 -04:00