Source code for id_translation.fetching.exceptions

"""Errors and warnings related to fetching."""

from collections.abc import Iterable as _Iterable
from typing import Any as _Any


[docs] class FetcherWarning(RuntimeWarning): """Base class for ``Fetcher`` warnings."""
[docs] class FetcherError(RuntimeError): """Base class for ``Fetcher`` exceptions."""
[docs] class ForbiddenOperationError(FetcherError): """Exception indicating that the ``Fetcher`` does not support an operation.""" def __init__(self, operation: str, reason: str) -> None: super().__init__(f"Operation '{operation}' " + reason) self.operation = operation
[docs] class ImplementationError(FetcherError): """An underlying implementation did something wrong."""
[docs] class UnknownPlaceholderError(FetcherError): """Caller requested unknown placeholder name(s)."""
[docs] class UnknownIdError(FetcherError): """Caller requested unknown id(s)."""
[docs] class UnknownSourceError(FetcherError): """Caller requested unknown source(s). Args: unknown_sources: The sources which are not known to the Fetcher. sources: Sources known to the fetcher. msg: A format string that takes `unknown_sources` and `sources`. """ def __init__( self, unknown_sources: _Iterable[_Any], sources: _Iterable[_Any], msg: str = "Sources {unknown_sources} not recognized. Known sources: {sources}.", ) -> None: self.sources = set(sources) self.unknown_sources = set(unknown_sources) super().__init__(msg.format(unknown_sources=self.unknown_sources, sources=self.sources))
[docs] class DuplicateSourceWarning(FetcherWarning): """Duplicate sources detected."""
[docs] class DuplicateSourceError(FetcherError): """Multiple translations for the same source received."""
[docs] class CacheAccessNotAvailableError(FetcherError): """Raised when calling :attr:`.AbstractFetcher.cache_access` on an instance that is not cached."""