From b456f6b125aab4a6ba3d9660d110c5a86d89971b Mon Sep 17 00:00:00 2001 From: Evan Blaudy Date: Mon, 30 Oct 2023 00:26:23 +0100 Subject: [PATCH] Fix opentimelineio.url_utils.filepath_from_url for windows URL Signed-off-by: Evan Blaudy --- src/py-opentimelineio/opentimelineio/url_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/py-opentimelineio/opentimelineio/url_utils.py b/src/py-opentimelineio/opentimelineio/url_utils.py index 61e44be58..908c90196 100644 --- a/src/py-opentimelineio/opentimelineio/url_utils.py +++ b/src/py-opentimelineio/opentimelineio/url_utils.py @@ -10,8 +10,9 @@ request ) from pathlib import ( - Path, - PureWindowsPath + PurePath, + PureWindowsPath, + PurePosixPath ) @@ -21,7 +22,7 @@ def url_from_filepath(fpath): try: # appears to handle absolute windows paths better, which are absolute # and start with a drive letter. - return urlparse.unquote(Path(fpath).as_uri()) + return urlparse.unquote(PurePath(fpath).as_uri()) except ValueError: # scheme is "file" for absolute paths, else "" scheme = "file" if os.path.isabs(fpath) else "" @@ -56,16 +57,16 @@ def filepath_from_url(urlstr): parsed_result = urlparse.urlparse(urlstr) # Convert the parsed URL to a path - filepath = Path(request.url2pathname(parsed_result.path)) + filepath = PurePath(request.url2pathname(parsed_result.path)) # If the network location is a window drive, reassemble the path if PureWindowsPath(parsed_result.netloc).drive: - filepath = Path(parsed_result.netloc + parsed_result.path) + filepath = PureWindowsPath(parsed_result.netloc + parsed_result.path) # Otherwise check if the specified index is a windows drive, then offset the path elif PureWindowsPath(filepath.parts[1]).drive: # Remove leading "/" if/when `request.url2pathname` yields "/S:/path/file.ext" - filepath = filepath.relative_to(filepath.root) + filepath = PurePosixPath(*filepath.parts[1:]) # Convert "\" to "/" if needed return filepath.as_posix()