From 138d99dd7ffc1e10cbe1274936c073402b56e18b Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sat, 8 Jun 2024 20:27:13 -0400 Subject: [PATCH] Update code to adjust to most recent python/fastapi. --- etebase_server/fastapi/sendfile/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/etebase_server/fastapi/sendfile/utils.py b/etebase_server/fastapi/sendfile/utils.py index c68559f..22e8266 100644 --- a/etebase_server/fastapi/sendfile/utils.py +++ b/etebase_server/fastapi/sendfile/utils.py @@ -1,4 +1,5 @@ import logging +import os from functools import lru_cache from importlib import import_module from pathlib import Path, PurePath @@ -32,9 +33,7 @@ def _convert_file_to_url(path): path_obj = PurePath(path) relpath = path_obj.relative_to(path_root) - # Python 3.5: Path.resolve() has no `strict` kwarg, so use pathmod from an - # already instantiated Path object - url = relpath._flavour.pathmod.normpath(str(url_root / relpath)) + url = os.path.normpath(str(url_root / relpath)) return quote(str(url)) @@ -48,9 +47,7 @@ def _sanitize_path(filepath): filepath_obj = Path(filepath) # get absolute path - # Python 3.5: Path.resolve() has no `strict` kwarg, so use pathmod from an - # already instantiated Path object - filepath_abs = Path(filepath_obj._flavour.pathmod.normpath(str(path_root / filepath_obj))) + filepath_abs = Path(os.path.normpath(str(path_root / filepath_obj))) # if filepath_abs is not relative to path_root, relative_to throws an error try: