openmedialibrary_platform/Shared/lib/python3.7/site-packages/setuptools/py31compat.py

33 lines
820 B
Python
Raw Normal View History

2018-12-15 00:08:54 +00:00
__all__ = []
2013-10-11 17:28:32 +00:00
2018-12-15 00:08:54 +00:00
__metaclass__ = type
2013-10-11 17:28:32 +00:00
try:
# Python >=3.2
from tempfile import TemporaryDirectory
except ImportError:
import shutil
import tempfile
2018-12-15 00:08:54 +00:00
class TemporaryDirectory:
2016-01-09 07:16:19 +00:00
"""
2013-10-11 17:28:32 +00:00
Very simple temporary directory context manager.
Will try to delete afterward, but will also ignore OS and similar
errors on deletion.
"""
2018-12-15 00:08:54 +00:00
2013-10-11 17:28:32 +00:00
def __init__(self):
2018-12-15 00:08:54 +00:00
self.name = None # Handle mkdtemp raising an exception
2013-10-11 17:28:32 +00:00
self.name = tempfile.mkdtemp()
def __enter__(self):
return self.name
def __exit__(self, exctype, excvalue, exctrace):
try:
shutil.rmtree(self.name, True)
2018-12-15 00:08:54 +00:00
except OSError: # removal errors are not the only possible
2013-10-11 17:28:32 +00:00
pass
self.name = None