Skip to content

Commit 2b5ed0f

Browse files
authored
flexible protocols for LocalFileSystem (#2014)
1 parent 2853792 commit 2b5ed0f

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

fsspec/implementations/local.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ def rm(self, path, recursive=False, maxdepth=None):
204204
os.remove(p)
205205

206206
def unstrip_protocol(self, name):
207+
protocol = self.protocol if isinstance(self.protocol, str) else self.protocol[0]
207208
name = self._strip_protocol(name) # normalise for local/win/...
208-
return f"file://{name}"
209+
return f"{protocol}://{name}"
209210

210211
def _open(self, path, mode="rb", block_size=None, **kwargs):
211212
path = self._strip_protocol(path)
@@ -253,14 +254,12 @@ def _parent(cls, path):
253254
@classmethod
254255
def _strip_protocol(cls, path):
255256
path = stringify_path(path)
256-
if path.startswith("file://"):
257-
path = path[7:]
258-
elif path.startswith("file:"):
259-
path = path[5:]
260-
elif path.startswith("local://"):
261-
path = path[8:]
262-
elif path.startswith("local:"):
263-
path = path[6:]
257+
protos = (cls.protocol,) if isinstance(cls.protocol, str) else cls.protocol
258+
prefixes = (protocol + sep for protocol in protos for sep in ("://", ":"))
259+
for prefix in prefixes:
260+
if path.startswith(prefix):
261+
path = path.removeprefix(prefix)
262+
break
264263

265264
path = make_path_posix(path)
266265
if os.sep != "/":

0 commit comments

Comments
 (0)