Utilities

class yadisk.utils.CaseInsensitiveDict(*args, **kwargs)[source]

A case-insensitive dictionary. All keys are converted to lowercase.

get(key: str, /, *args, **kwargs) Any[source]

Return the value for key if key is in the dictionary, else default.

pop(k[, d]) v, remove specified key and return the corresponding value.[source]

If the key is not found, return the default if given; otherwise, raise a KeyError.

setdefault(key: str, *args, **kwargs) Any[source]

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

async yadisk.utils.async_auto_retry(func: Callable[[...], Any] | Callable[[...], Awaitable[Any]], n_retries: int | None = None, retry_interval: int | float | None = None, args: tuple | None = None, kwargs: dict[str, Any] | None = None, retry_on: tuple[type[Exception], ...] = ()) Any[source]

Attempt to perform a request with automatic retries. A retry is triggered by RequestError or RetriableYaDiskError, unless the raised exception has disable_retry set to True.

Parameters:
  • func – function to run, must not require any arguments

  • n_retriesint, maximum number of retries

  • retry_intervalint or float, delay between retries (in seconds)

  • argstuple or None, additional arguments for func

  • kwargsdict or None, additional keyword arguments for func

  • retry_ontuple, additional exception classes to retry on

Returns:

return value of func()

yadisk.utils.auto_retry(func: Callable[[...], T], n_retries: int | None = None, retry_interval: int | float | None = None, args: tuple | None = None, kwargs: dict[str, Any] | None = None, retry_on: tuple[type[Exception], ...] = ()) T[source]

Attempt to perform a request with automatic retries. A retry is triggered by RequestError or RetriableYaDiskError, unless the raised exception has disable_retry set to True.

Parameters:
  • func – function to run, must not require any arguments

  • n_retriesint, maximum number of retries

  • retry_intervalint or float, delay between retries (in seconds)

  • argstuple or None, additional arguments for func

  • kwargsdict or None, additional keyword arguments for func

  • retry_ontuple, additional exception classes to retry on

Returns:

return value of func()

yadisk.utils.get_exception(response: Response | AsyncResponse, error: ErrorObject | None) YaDiskError[source]

Get an exception instance based on response, assuming the request has failed.

Parameters:
Returns:

an exception instance, subclass of YaDiskError