skshetry / webdav4

WebDAV client library with a fsspec based filesystem and a CLI.
https://skshetry.github.io/webdav4
MIT License
61 stars 17 forks source link

Allow only use `client` without `base_url` #187

Open z0z0r4 opened 1 month ago

z0z0r4 commented 1 month ago
from webdav4.fsspec import WebdavFileSystem
from webdav4.client import Client

client = Client("http://localhost:5244/dav", auth=("admin", "admin"))

fs = WebdavFileSystem(client=client)

like this which raised

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/.pyenv/versions/3.11.4/lib/python3.11/site-packages/fsspec/spec.py", line 81, in __call__
    obj = super().__call__(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: WebdavFileSystem.__init__() missing 1 required positional argument: 'base_url'

Change:

class WebdavFileSystem(AbstractFileSystem):
    """Provides access to webdav through fsspec-compliant APIs."""

    protocol = ("webdav", "dav")

    def __init__(
        self,
        base_url: Optional["URLTypes"] = None,
        auth: Optional["AuthTypes"] = None,
        client: Optional["Client"] = None,
        **client_opts: Any,
    ) -> None:
        """Instantiate WebdavFileSystem with base_url and auth.

        Args:
            base_url: base url of the server
            auth: Authentication to the server
                Refer to HTTPX's auth for more information.
            client: Webdav client to use instead, useful for testing/mocking,
                or extending WebdavFileSystem.
            client_opts: Extra args that are passed to Webdav Client.
                (refer to it's documenting for more information).
        """
        super().__init__()
        client_opts.setdefault("chunk_size", self.blocksize)
        if not base_url and not client:
            raise ValueError("Either base_url or client must be provided")
        self.client = client or Client(base_url, auth=auth, **client_opts)
z0z0r4 commented 1 month ago

Should I open a PR for this?