summaryrefslogtreecommitdiff
path: root/django/utils/_os.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/utils/_os.py')
-rw-r--r--django/utils/_os.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/django/utils/_os.py b/django/utils/_os.py
index b2a2a9d426..f85fe09248 100644
--- a/django/utils/_os.py
+++ b/django/utils/_os.py
@@ -23,12 +23,15 @@ def safe_join(base, *paths):
# safe_join("/dir", "/../d"))
# b) The final path must be the same as the base path.
# c) The base path must be the most root path (meaning either "/" or "C:\\")
- if (not normcase(final_path).startswith(normcase(base_path + sep)) and
- normcase(final_path) != normcase(base_path) and
- dirname(normcase(base_path)) != normcase(base_path)):
+ if (
+ not normcase(final_path).startswith(normcase(base_path + sep))
+ and normcase(final_path) != normcase(base_path)
+ and dirname(normcase(base_path)) != normcase(base_path)
+ ):
raise SuspiciousFileOperation(
- 'The joined path ({}) is located outside of the base path '
- 'component ({})'.format(final_path, base_path))
+ "The joined path ({}) is located outside of the base path "
+ "component ({})".format(final_path, base_path)
+ )
return final_path
@@ -39,8 +42,8 @@ def symlinks_supported():
permissions).
"""
with tempfile.TemporaryDirectory() as temp_dir:
- original_path = os.path.join(temp_dir, 'original')
- symlink_path = os.path.join(temp_dir, 'symlink')
+ 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)
@@ -55,5 +58,5 @@ def to_path(value):
if isinstance(value, Path):
return value
elif not isinstance(value, str):
- raise TypeError('Invalid path type: %s' % type(value).__name__)
+ raise TypeError("Invalid path type: %s" % type(value).__name__)
return Path(value)