Skip to content

Commit

Permalink
Revert "revert merge"
Browse files Browse the repository at this point in the history
This reverts commit 60300d6.
  • Loading branch information
lobis committed Oct 6, 2023
1 parent 60300d6 commit 2884e02
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/uproot/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,30 +280,25 @@ def file_object_path_split(path):
"""
Split a path with a colon into a file path and an object-in-file path.
"""
path = regularize_path(path)

try:
index = path.rindex(":")
except ValueError:
return path, None
else:
file_path, object_path = path[:index], path[index + 1 :]
# remove whitespace
path = path.strip()

if (
_might_be_port.match(object_path) is not None
and urlparse(file_path).path == ""
):
return path, None
# split url into parts
parsed_url = urlparse(path)

file_path = file_path.rstrip()
object_path = object_path.lstrip()
parts = parsed_url.path.split(":")
if len(parts) == 1:
obj = None
elif len(parts) == 2:
obj = parts[1]
# remove the object from the path (including the colon)
path = path[: -len(obj) - 1]
obj = obj.strip()
else:
raise ValueError(f"too many colons in file path: {path} for url {parsed_url}")

if file_path.upper() in _schemes:
return path, None
elif win and _windows_drive_letter_ending.match(file_path) is not None:
return path, None
else:
return file_path, object_path
return path, obj


def file_path_to_source_class(file_path, options):
Expand Down
60 changes: 60 additions & 0 deletions tests/test_0976_path_object_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest

import uproot


def test_url_split():
for input_url, result in [
(
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root:Events",
(
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
"Events",
),
),
(
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
(
"https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
None,
),
),
(
"github://scikit-hep:scikit-hep-testdata@v0.4.33/src/skhep_testdata/data/uproot-issue121.root:Dir/Events",
(
"github://scikit-hep:scikit-hep-testdata@v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
"Dir/Events",
),
),
(
"github://scikit-hep:scikit-hep-testdata@v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
(
"github://scikit-hep:scikit-hep-testdata@v0.4.33/src/skhep_testdata/data/uproot-issue121.root",
None,
),
),
(
" http://localhost:8080/dir/test.root: Test ",
(
"http://localhost:8080/dir/test.root",
"Test",
),
),
(
"/tmp/test/dir/file.root:Test",
(
"/tmp/test/dir/file.root",
"Test",
),
),
(
r"C:\tmp\test\dir\file.root:Dir/Test",
(
r"C:\tmp\test\dir\file.root",
"Dir/Test",
),
),
]:
url, obj = uproot._util.file_object_path_split(input_url)
assert url == result[0]
assert obj == result[1]

0 comments on commit 2884e02

Please sign in to comment.