From 3762a7ab774f32f0d791c5edd0e318265818a333 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Thu, 12 Oct 2023 22:49:32 +0200 Subject: [PATCH] upath.implementations.memory: ignore authority parts in memory URIs --- upath/implementations/memory.py | 7 +++++++ upath/tests/test_core.py | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/upath/implementations/memory.py b/upath/implementations/memory.py index 4d7d8bd0..6c4fe78b 100644 --- a/upath/implementations/memory.py +++ b/upath/implementations/memory.py @@ -27,3 +27,10 @@ def iterdir(self): name = name.rstrip("/") name = self._sub_path(name) yield self._make_child_relpath(name) + + @classmethod + def _from_parts(cls, args, url=None, **kwargs): + if url and url.netloc: + args[0:0] = ["/", url.netloc] + url = url._replace(netloc="") + return super()._from_parts(args, url=url, **kwargs) diff --git a/upath/tests/test_core.py b/upath/tests/test_core.py index ad49cb3c..299a40be 100644 --- a/upath/tests/test_core.py +++ b/upath/tests/test_core.py @@ -339,12 +339,15 @@ def test_uri_parsing(): ("http://example.com/a//..//.", "http://example.com/a//"), ("http://example.com/a//..//b", "http://example.com/a//b"), # Normalization with and without an authority component - ("memory:/a/b/..", "memory:/a/"), - ("memory:/a/b/../..", "memory:/"), - ("memory:/a/b/../../..", "memory:/"), - ("memory://a/b/..", "memory://a/"), - ("memory://a/b/../..", "memory://a/"), - ("memory://a/b/../../..", "memory://a/"), + ("memory:/a/b/..", "memory:///a/"), + ("memory:/a/b/../..", "memory:///"), + ("memory:/a/b/../../..", "memory:///"), + ("memory://a/b/..", "memory:///a/"), + ("memory://a/b/../..", "memory:///"), + ("memory://a/b/../../..", "memory:///"), + ("memory:///a/b/..", "memory:///a/"), + ("memory:///a/b/../..", "memory:///"), + ("memory:///a/b/../../..", "memory:///"), ), )