Skip to content

Commit

Permalink
upath: fix parts handling for http
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- committed Oct 12, 2023
1 parent 8ffee0a commit 3cebeaa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions upath/implementations/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ def resolve(

return resolved_path

@property
def drive(self):
return f"{self._url.scheme}://{self._url.netloc}"

@property
def anchor(self) -> str:
return self.drive + self.root

@property
def parts(self) -> tuple[str, ...]:
parts = super().parts
if not parts:
return ()
p0, *partsN = parts
if p0 == "/":
p0 = self.anchor
if not partsN and self._url.path == "/":
partsN = [""]
return (p0, *partsN)

@property
def path(self) -> str:
# http filesystems use the full url as path
Expand Down
1 change: 0 additions & 1 deletion upath/tests/implementations/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def test_rename2(self):
@pytest.mark.parametrize(
"args,parts",
[
(("http://example.com"), ("http://example.com/",)),
(("http://example.com/"), ("http://example.com/", "")),
(("http://example.com//"), ("http://example.com/", "", "")),
(("http://example.com///"), ("http://example.com/", "", "", "")),
Expand Down

0 comments on commit 3cebeaa

Please sign in to comment.