openmedialibrary_platform_w.../Lib/site-packages/setuptools/py31compat.py

33 lines
820 B
Python
Raw Normal View History

2019-01-20 10:35:31 +00:00
__all__ = []
2016-01-31 14:44:46 +00:00
2019-01-20 10:35:31 +00:00
__metaclass__ = type
2016-01-31 14:44:46 +00:00
try:
# Python >=3.2
from tempfile import TemporaryDirectory
except ImportError:
import shutil
import tempfile
2019-01-20 10:35:31 +00:00
class TemporaryDirectory:
2016-01-31 14:44:46 +00:00
"""
Very simple temporary directory context manager.
Will try to delete afterward, but will also ignore OS and similar
errors on deletion.
"""
2019-01-20 10:35:31 +00:00
2016-01-31 14:44:46 +00:00
def __init__(self):
2019-01-20 10:35:31 +00:00
self.name = None # Handle mkdtemp raising an exception
2016-01-31 14:44:46 +00:00
self.name = tempfile.mkdtemp()
def __enter__(self):
return self.name
def __exit__(self, exctype, excvalue, exctrace):
try:
shutil.rmtree(self.name, True)
2019-01-20 10:35:31 +00:00
except OSError: # removal errors are not the only possible
2016-01-31 14:44:46 +00:00
pass
self.name = None