11from __future__ import annotations
22
3+ import os
34from typing import Any
45from urllib .parse import urlsplit
5- from urllib .parse import urlunsplit
66
77from fsspec .registry import known_implementations
88from fsspec .registry import register_implementation
3030class WebdavPath (UPath ):
3131 __slots__ = ()
3232
33- def __init__ (
34- self , * args , protocol : str | None = None , ** storage_options : Any
35- ) -> None :
36- base_options = getattr (self , "_storage_options" , {}) # when unpickling
37- if args :
33+ @classmethod
34+ def _transform_init_args (
35+ cls ,
36+ args : tuple [str | os .PathLike , ...],
37+ protocol : str ,
38+ storage_options : dict [str , Any ],
39+ ) -> tuple [tuple [str | os .PathLike , ...], str , dict [str , Any ]]:
40+ if not args :
41+ args = ("/" ,)
42+ elif args and protocol in {"webdav+http" , "webdav+https" }:
3843 args0 , * argsN = args
3944 url = urlsplit (str (args0 ))
40- args0 = urlunsplit (url ._replace (scheme = "" , netloc = "" )) or "/"
41- if "base_url" not in storage_options :
42- if self ._protocol == "webdav+http" :
43- storage_options ["base_url" ] = urlunsplit (
44- url ._replace (scheme = "http" , path = "" )
45- )
46- elif self ._protocol == "webdav+https" :
47- storage_options ["base_url" ] = urlunsplit (
48- url ._replace (scheme = "https" , path = "" )
49- )
50- else :
51- args0 , argsN = "/" , []
52- storage_options = {** base_options , ** storage_options }
45+ base = url ._replace (scheme = protocol .split ("+" )[1 ], path = "" ).geturl ()
46+ args0 = url ._replace (scheme = "" , netloc = "" ).geturl () or "/"
47+ storage_options ["base_url" ] = base
48+ args = (args0 , * argsN )
5349 if "base_url" not in storage_options :
5450 raise ValueError (
5551 f"must provide `base_url` storage option for args: { args !r} "
5652 )
57- self ._protocol = "webdav"
58- super ().__init__ (args0 , * argsN , protocol = "webdav" , ** storage_options )
53+ return super ()._transform_init_args (args , "webdav" , storage_options )
5954
6055 @property
6156 def path (self ) -> str :
@@ -64,4 +59,4 @@ def path(self) -> str:
6459
6560 def __str__ (self ):
6661 base_url = str_remove_suffix (self .storage_options ["base_url" ], "/" )
67- return super ().__str__ ().replace ("webdav://" , f"webdav+{ base_url } " , 1 )
62+ return super ().__str__ ().replace ("webdav://" , f"webdav+{ base_url } / " , 1 )
0 commit comments