Client¶
Client for the webdav.
- exception webdav4.client.BadGatewayError[source]¶
Bases:
ClientError
Error when bad gateway error is thrown.
Raised when 502 status code is raised by the server.
- class webdav4.client.Client(base_url: URLTypes, auth: AuthTypes | None = None, http_client: HTTPClient | None = None, retry: RetryFunc | bool = True, chunk_size: int = 4194304, **client_opts: Any)[source]¶
Bases:
object
Provides higher level APIs for interacting with Webdav server.
Instantiate client for webdav.
Examples
>>> client = Client("https://webdav.example.org") >>> client.ls("/")
- Parameters:
base_url – base url of the Webdav server
auth –
Auth for the webdav. Auth can be any of the following:
a tuple of (user, password)
None if no auth is required.
Refer to Customizing Authentication for more options.
http_client – http client to use instead, useful in mocking (when extending, it is expected to have implemented additional verbs from webdav)
retry – disable or enable retry on client. Can also pass a callable to handle it there. Some well-known errors are handled and retried a few times with the backoff.
All of the following keyword arguments are passed along to the httpx, the http library this client is built on.
- Keyword Arguments:
headers – Dict. of HTTP headers to include when sending requests
cookies – Dict. of Cookie items to include when sending requests
verify –
SSL certificates used to verify the identity of requested hosts. Can be any of:
True (uses default CA bundle),
a path to an SSL certificate file,
False (disable verification), or
cert – An SSL certificate used by the requested host to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file), or a three-tuple of (certificate file, key file, password).
proxies – A dictionary mapping proxy keys to proxy URLs
timeout – The timeout configuration to use when sending requests
limits – The limits configuration to use
max_redirects – The maximum number of redirect responses that should be followed
trust_env – Enables or disables usage of environment variables for configuration
- content_language(path: str) str | None [source]¶
Returns content language of the resource with the given path.
- content_length(path: str) int | None [source]¶
Returns content-length of the resource with the given path.
- content_type(path: str) str | None [source]¶
Returns content type of the resource with the given path.
- copy(from_path: str, to_path: str, depth: int | str = 'infinity', overwrite: bool = False) None [source]¶
Copy resource.
- created(path: str) datetime | None [source]¶
Returns creationdate of the resource with the given path.
- property detected_features: FeatureDetection¶
Feature detection for the server.
- download_file(from_path: str, to_path: PathLike[AnyStr], chunk_size: int | None = None, callback: Callable[[int], Any] | None = None) None [source]¶
Download file from remote path to local path.
- download_fileobj(from_path: str, file_obj: BinaryIO, callback: Callable[[int], Any] | None = None, chunk_size: int | None = None) None [source]¶
Write stream from path to given file object.
- get_property(path: str, name: str, namespace: str | None = None) Any [source]¶
Returns appropriate property from the propfind response.
Also supports getting named properties (for now restricted to a single string with the given namespace)
- get_props(path: str, name: str | None = None, namespace: str | None = None, data: str | None = None) DAVProperties [source]¶
Returns properties of a resource by doing a propfind request.
Can also selectively request the properties by passing name or data.
- join_url(path: str, add_trailing_slash: bool = False) URL [source]¶
Join resource path with base url of the webdav server.
- ls(path: str, detail: bool = True, allow_listing_resource: bool = True) List[str | Dict[str, Any]] [source]¶
List items in a resource/collection.
- Parameters:
path – Path to the resource
detail – If detail=True, additional information is returned in a dictionary
allow_listing_resource – If True and path is a resource (non-collection), ls will return the file entry/details. Otherwise, it will raise an error.
- modified(path: str) datetime | None [source]¶
Returns getlastmodified of the resource with the given path.
- move(from_path: str, to_path: str, overwrite: bool = False) None [source]¶
Move resource to a new destination (with or without overwriting).
- open(path: str, mode: str = 'r', encoding: str | None = None, chunk_size: int | None = None) Iterator[TextIO | BinaryIO] [source]¶
Returns file-like object to a resource.
- propfind(path: str, data: str | None = None, headers: HeaderTypes | None = None, follow_redirects: bool = False) MultiStatusResponse [source]¶
Returns properties of the specific resource by propfind request.
- request(method: str, path: str, **kwargs: Any) HTTPResponse [source]¶
Sends request to a server with given method and path.
Also checks for Multistatus response and other http errors.
- exception webdav4.client.ClientError(msg: str)[source]¶
Bases:
Exception
Custom exception thrown by the Client.
Instantiate exception with a msg.
- class webdav4.client.FeatureDetection(options_response: HTTPResponse | None = None)[source]¶
Bases:
object
Detect features in the webdav resources.
Mostly used for detecting support for Accept-Ranges as ownCloud/NextCloud don’t advertise support for it in GET requests.
Initialize with the given response.
- exception webdav4.client.ForbiddenOperation(msg: str)[source]¶
Bases:
ClientError
Raised when the operation was forbidden (got 403).
Instantiate exception with a msg.
- exception webdav4.client.HTTPError(response: HTTPResponse)[source]¶
Bases:
ClientError
Custom Exception for our HTTPStatusError.
Instantiate exception with the failed response.
- exception webdav4.client.InsufficientStorage(path: str)[source]¶
Bases:
ClientError
Error when the resource does not exist on the server.
Instantiate exception with the path for which the request failed.
- exception webdav4.client.IsACollectionError(path: str, msg: str = '')[source]¶
Bases:
ClientError
Exception thrown when the path is a collection.
Could be thrown when the resource/non-collection is expected.
Initialize with the path and the appropriate message.
- exception webdav4.client.IsAResourceError(path: str, msg: str = '')[source]¶
Bases:
ClientError
Exception thrown when the path is a resource.
Could be thrown when the collection is expected.
Initialize with the path and the appropriate message.
- exception webdav4.client.MultiStatusError(msg: str)[source]¶
Bases:
ClientError
Wrapping MultiStatusResponseError with ClientError.
Instantiate exception with a msg.
- exception webdav4.client.ResourceAlreadyExists(path: str)[source]¶
Bases:
ClientError
Error returned if the resource already exists.
Instantiate exception with the path that already exists.
- exception webdav4.client.ResourceConflict(msg: str)[source]¶
Bases:
ClientError
Raised when there was conflict during the operation (got 409).
Instantiate exception with a msg.
- exception webdav4.client.ResourceLocked(msg: str)[source]¶
Bases:
ClientError
Error raised when the resource is locked.
Instantiate exception with a msg.
- exception webdav4.client.ResourceNotFound(path: str)[source]¶
Bases:
ClientError
Error when the resource does not exist on the server.
Instantiate exception with path that does not exist.