is_relative_to is from 3.9.

This commit is contained in:
Roland 2021-11-02 11:59:57 -06:00
parent c6b55b47b5
commit 0187dae8ff
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 7 additions and 2 deletions

View file

@ -1,3 +1,5 @@
user www-data;
events {
}
@ -46,7 +48,7 @@ http {
autoindex on;
autoindex_exact_size off;
alias /opt/media;
alias /media/wrolpi;
}
}

View file

@ -29,7 +29,7 @@ class MediaPath:
if not path.is_absolute():
# Assume the path is relative to the media directory.
path = get_media_directory() / path
elif not path.is_relative_to(get_media_directory()):
elif not str(path).startswith(str(get_media_directory())):
# Absolute paths must be within the media directory.
raise ValueError(f'Path {path} must be in {get_media_directory()}')

View file

@ -37,3 +37,6 @@ class TestMediaPath(unittest.TestCase):
# Absolute paths must be in media directory.
d = MediaPath(f'{self.test_dir.name}/foo')
self.assertEqual(d._path, pathlib.Path(f'{self.test_dir.name}/foo'))
# Error is raised when the path is not in the media path.
self.assertRaises(ValueError, MediaPath, '/tmp/foo')