Skip to content

Commit

Permalink
Fix opentimelineio.url_utils.filepath_from_url for windows URL in pyt…
Browse files Browse the repository at this point in the history
…hon 3.12

Signed-off-by: Evan Blaudy <evan@cg-wire.com>
  • Loading branch information
EvanBldy committed Oct 30, 2023
1 parent 4e8ea8e commit b3ca8d5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/py-opentimelineio/opentimelineio/url_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
request
)
from pathlib import (
Path,
PureWindowsPath
PurePath,
PureWindowsPath,
PurePosixPath
)


Expand All @@ -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 ""
Expand Down Expand Up @@ -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 = PurePath(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()

0 comments on commit b3ca8d5

Please sign in to comment.