rics.translation.factory#
Factory functions for translation classes.
Module Attributes
A callable used to create |
|
A callable used to created |
Functions
|
Create a |
|
Create a |
Classes
|
Create a |
- FetcherFactory#
A callable used to create
Fetcherinstances.alias of
Callable[[str,Dict[str,Any]],AbstractFetcher]
- MapperFactory#
A callable used to created
Mapperinstances.
- default_fetcher_factory(clazz: str, config: Dict[str, Any]) AbstractFetcher[source]#
Create a
Fetcherfrom a dict config.- Parameters
clazz – Type of
Fetcherto create.config – Keyword arguments for the fetcher class.
- Returns
An AbstractFetcher instance.
- Raises
exceptions.ConfigurationError – If config is invalid.
TypeError – If clazz is not an AbstractFetcher subtype.
- default_mapper_factory(config: Dict[str, Any], for_fetcher: bool) Optional[Mapper][source]#
Create a
Mapperfrom a dict config.- Parameters
config – Keyword arguments for the
Mapper.for_fetcher – Flag indicating that the
Mapperreturned will be used by anAbstractFetcherinstance.
- Returns
A
Mapperinstance.- Raises
ConfigurationError – If config is invalid.
- class TranslatorFactory(file: Union[str, bytes, PathLike], extra_fetchers: Iterable[Union[str, bytes, PathLike]], fetcher_factory: Callable[[str, Dict[str, Any]], AbstractFetcher], mapper_factory: Callable[[Dict[str, Any], bool], Optional[Mapper]])[source]#
Bases:
Generic[NameType,SourceType,IdType]Create a
Translatorfrom TOML inputs.- Parameters
file – Path to a TOML file, or a pre-parsed dict.
extra_fetchers – Path to TOML files defining additional fetchers. Useful for fetching from multiple sources or kinds of sources, for example locally stored files in conjunction with one or more databases. The fetchers are ranked by input order, with the fetcher defined in file being given the highest priority (rank 0).
fetcher_factory – A Fetcher instance, or a callable taking (name, kwargs) which returns an
AbstractFetcher.mapper_factory – A
Mapperinstance, or a callable taking (kwargs) which returns aMapper. Used for bothTranslatorandFetchermapper initialization.
See also
The Translator Configuration Files page.
- create() Translator[source]#
Create a
Translatorfrom a TOML file.- Returns
A
Translatorobject.- Raises
exceptions.ConfigurationError – If the config is invalid.