aiomegfile.filesystem.webdav module

Filesystem adapter for WebDAV resources backed by aiodav.

class aiomegfile.filesystem.webdav.WebdavFileSystem(host: str, port: int | None = None, *, username: str | None = None, password: str | None = None, token: str | None = None, token_command: str | None = None, timeout: float | None = None, insecure: bool | None = None, show_port_in_uri: bool | None = None, show_username_in_uri: bool | None = None, show_password_in_uri: bool | None = None, max_retries: int = 10)[source]

Bases: BaseFileSystem

Filesystem adapter for webdav:// URIs using aiodav.

uri format:
  • webdav://[username[:password]@]hostname[:port]/file_path

  • webdavs://[username[:password]@]hostname[:port]/file_path

async absolute(path: str) str[source]

Return absolute normalized path without resolving symlinks.

Parameters:

path – Path without protocol.

Returns:

Absolute normalized path.

Return type:

str

build_uri(path: str) str

Build URI from path part.

Parameters:

path – Path without protocol.

Returns:

Full WebDAV URI.

Return type:

str

async copy(src_path: str, dst_path: str, callback: Callable[[int], None] | None = None) str[source]

Copy a single file on WebDAV.

Parameters:
  • src_path – Source path without protocol.

  • dst_path – Destination path without protocol.

  • callback – Optional callback receiving copied byte deltas.

Returns:

Destination path after copy.

Return type:

str

async download(src_path: str, dst_path: str, callback: Callable[[int], None] | None = None) None[source]

Download a remote file from WebDAV to local path.

Parameters:
  • src_path – Remote source path without protocol.

  • dst_path – Local destination file path.

  • callback – Optional progress callback receiving byte deltas.

async exists(path: str, followlinks: bool = False) bool[source]

Return whether the path points to an existing resource.

Parameters:
  • path – The path to check.

  • followlinks – Ignored for WebDAV protocol.

Returns:

True if path exists, otherwise False.

classmethod from_uri(uri: str)

Create filesystem instance from URI.

Parameters:

uri – URI string.

Returns:

WebdavFileSystem instance.

Return type:

WebdavFileSystem

async is_absolute(path: str) bool[source]

Return whether a path is absolute.

Parameters:

path – Path without protocol.

Returns:

True when path starts with /.

Return type:

bool

async is_dir(path: str, followlinks: bool = False) bool[source]

Return True if the path points to a directory.

Parameters:
  • path – The path to check.

  • followlinks – Ignored for WebDAV protocol.

Returns:

True if path is directory, otherwise False.

async is_file(path: str, followlinks: bool = False) bool[source]

Return True if the path points to a regular file.

Parameters:
  • path – The path to check.

  • followlinks – Ignored for WebDAV protocol.

Returns:

True if path is file, otherwise False.

Return whether path points to a symbolic link.

WebDAV does not support symlinks.

Parameters:

path – Path without protocol.

Returns:

Always False.

Return type:

bool

async mkdir(path: str, mode: int = 511, parents: bool = False, exist_ok: bool = False) None[source]

Create a directory.

Parameters:
  • path – Directory path without protocol.

  • mode – Permission bits for compatibility only.

  • parents – Whether to create parent directories.

  • exist_ok – Whether to ignore existing directory.

Raises:

FileExistsError – If directory exists and exist_ok is False.

async move(src_path: str, dst_path: str, overwrite: bool = True) str[source]

Move file or directory on WebDAV.

Parameters:
  • src_path – Source path without protocol.

  • dst_path – Destination path without protocol.

  • overwrite – Whether to overwrite destination when exists.

Returns:

Destination path after move.

Return type:

str

Raises:

FileExistsError – If destination exists and overwrite is False.

open(path: str, mode: str = 'r', buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None, **kwargs: Any) AsyncContextManager[source]

Open path as async reader or writer.

Read mode uses AioWebdavPrefetchReader. Append mode uses AioFileCacher to preserve local append semantics.

Parameters:
  • path – Path without protocol.

  • mode – File open mode.

  • buffering – Unused compatibility argument.

  • encoding – Text encoding in text mode.

  • errors – Text error handling.

  • newline – Currently unused compatibility argument.

  • kwargs – Extra prefetch parameters.

Returns:

Async context manager for opened file.

Return type:

T.AsyncContextManager

parse_uri(uri: str) str[source]

Parse URI into path part without protocol.

Parameters:

uri – URI string.

Returns:

Path without protocol.

Return type:

str

protocol = 'webdav'
async remove(path: str, missing_ok: bool = False) None[source]

Remove (delete) file or directory recursively.

Parameters:
  • path – Path without protocol.

  • missing_ok – Ignore missing target when True.

same_endpoint(other_filesystem: BaseFileSystem) bool[source]

Return whether this filesystem points to same WebDAV endpoint.

Parameters:

other_filesystem – Filesystem to compare.

Returns:

True when both filesystems share endpoint settings.

Return type:

bool

async samefile(path: str, other_path: str) bool[source]

Return whether two paths refer to the same remote resource.

Parameters:
  • path – Path without protocol.

  • other_path – Other path without protocol.

Returns:

True when both normalized paths are equal and exist.

Return type:

bool

scandir(path: str) AsyncContextManager[AsyncIterator[FileEntry]][source]

Return async iterator over direct children of a directory.

Parameters:

path – Directory path without protocol.

Returns:

Async context manager yielding FileEntry values.

Return type:

T.AsyncContextManager[T.AsyncIterator[FileEntry]]

scanfile(path: str, sort: bool = False) AsyncContextManager[AsyncIterator[FileEntry]][source]

Return async iterator over files recursively.

Parameters:
  • path – Root path without protocol.

  • sort – Compatibility flag for protocol-aligned scanfile APIs.

Returns:

Async context manager yielding file FileEntry values.

Return type:

T.AsyncContextManager[T.AsyncIterator[FileEntry]]

async stat(path: str, followlinks: bool = False) StatResult[source]

Get metadata status for the path.

Parameters:
  • path – Path without protocol.

  • followlinks – Ignored for WebDAV protocol.

Returns:

StatResult for the path.

Return type:

StatResult

async upload(src_path: str, dst_path: str, callback: Callable[[int], None] | None = None) None[source]

Upload a local file to WebDAV.

Parameters:
  • src_path – Local source file path.

  • dst_path – Remote destination path without protocol.

  • callback – Optional progress callback receiving byte deltas.

class aiomegfile.filesystem.webdav.WebdavsFileSystem(host: str, port: int | None = None, *, username: str | None = None, password: str | None = None, token: str | None = None, token_command: str | None = None, timeout: float | None = None, insecure: bool | None = None, show_port_in_uri: bool | None = None, show_username_in_uri: bool | None = None, show_password_in_uri: bool | None = None, max_retries: int = 10)[source]

Bases: WebdavFileSystem

Filesystem adapter for webdavs:// URIs.

protocol = 'webdavs'
async aiomegfile.filesystem.webdav.get_webdav_client(hostname: str, *, username: str | None = None, password: str | None = None, token: str | None = None, token_command: str | None = None, timeout: float | None = None, insecure: bool | None = None)[source]

Get cached WebDAV client bound to current event loop.

Explicit token and WEBDAV_TOKEN are resolved before token_command. If token is resolved, username/password will be ignored.

Parameters:
  • hostname – WebDAV host url with scheme.

  • username – Optional username.

  • password – Optional password.

  • token – Optional bearer token.

  • token_command – Optional command to fetch token.

  • timeout – Optional request timeout in seconds.

  • insecure – Optional SSL verification flag.

Returns:

Cached initialized aiodav.client.Client instance.

Return type:

Any

Raises:

ModuleNotFoundError – If optional dependency is unavailable.

aiomegfile.filesystem.webdav.is_webdav(path: str | PathLike) bool[source]

Return whether the given path is a WebDAV URI.

Parameters:

path – Path to be tested.

Returns:

True when path uses webdav:// or webdavs://.

Return type:

bool