summaryrefslogtreecommitdiff
path: root/django/utils/_os.py
diff options
context:
space:
mode:
authorChillar Anand <anand21nanda@gmail.com>2017-01-27 00:24:16 +0530
committerTim Graham <timograham@gmail.com>2017-01-26 13:54:16 -0500
commit6478e07a62ce968f33e71a345e561bce36923f8e (patch)
treeef8a1c8cdfbd03fe51d22a346871eab156ddc275 /django/utils/_os.py
parentfee42fd99ee470528858c2ccb3621135c30ec262 (diff)
Refs #23919 -- Replaced tempfile.mkdtemp() with TemporaryDirectory() context manager.
Diffstat (limited to 'django/utils/_os.py')
-rw-r--r--django/utils/_os.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/django/utils/_os.py b/django/utils/_os.py
index 8309e08fbf..937ba82fbc 100644
--- a/django/utils/_os.py
+++ b/django/utils/_os.py
@@ -56,18 +56,13 @@ def symlinks_supported():
host platform and/or if they are allowed to be created (e.g.
on Windows it requires admin permissions).
"""
- tmpdir = tempfile.mkdtemp()
- original_path = os.path.join(tmpdir, 'original')
- symlink_path = os.path.join(tmpdir, 'symlink')
- os.makedirs(original_path)
- try:
- os.symlink(original_path, symlink_path)
- supported = True
- except (OSError, NotImplementedError, AttributeError):
- supported = False
- else:
- os.remove(symlink_path)
- finally:
- os.rmdir(original_path)
- os.rmdir(tmpdir)
+ with tempfile.TemporaryDirectory() as temp_dir:
+ original_path = os.path.join(temp_dir, 'original')
+ symlink_path = os.path.join(temp_dir, 'symlink')
+ os.makedirs(original_path)
+ try:
+ os.symlink(original_path, symlink_path)
+ supported = True
+ except (OSError, NotImplementedError):
+ supported = False
return supported