pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/100132/commits/e15d6f6f4150fbedeea3b26e0ecda13accfe03fe

rimer-primitives-ef1311e26457f1ec.css" /> gh-100131: Add optional delete parameter to tempfile.TemporaryDirectory() by JakobDev · Pull Request #100132 · python/cpython · GitHub
Skip to content
Next Next commit
Add optional delete parameter to tempfile.TemporaryDirectory()
  • Loading branch information
JakobDev authored Dec 9, 2022
commit e15d6f6f4150fbedeea3b26e0ecda13accfe03fe
15 changes: 9 additions & 6 deletions Lib/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,13 +854,14 @@ class TemporaryDirectory:
"""

def __init__(self, suffix=None, prefix=None, dir=None,
ignore_cleanup_errors=False):
ignore_cleanup_errors=False, delete=True):
self.name = mkdtemp(suffix, prefix, dir)
self._ignore_cleanup_errors = ignore_cleanup_errors
self._delete = delete
self._finalizer = _weakref.finalize(
self, self._cleanup, self.name,
warn_message="Implicitly cleaning up {!r}".format(self),
ignore_errors=self._ignore_cleanup_errors)
ignore_errors=self._ignore_cleanup_errors, delete=self._delete)

@classmethod
def _rmtree(cls, name, ignore_errors=False):
Expand Down Expand Up @@ -894,9 +895,10 @@ def resetperms(path):
_shutil.rmtree(name, onerror=onerror)

@classmethod
def _cleanup(cls, name, warn_message, ignore_errors=False):
cls._rmtree(name, ignore_errors=ignore_errors)
_warnings.warn(warn_message, ResourceWarning)
def _cleanup(cls, name, warn_message, ignore_errors=False, delete=True):
if delete:
cls._rmtree(name, ignore_errors=ignore_errors)
_warnings.warn(warn_message, ResourceWarning)

def __repr__(self):
return "<{} {!r}>".format(self.__class__.__name__, self.name)
Expand All @@ -905,7 +907,8 @@ def __enter__(self):
return self.name

def __exit__(self, exc, value, tb):
self.cleanup()
if self._delete:
self.cleanup()

def cleanup(self):
if self._finalizer.detach() or _os.path.exists(self.name):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy