anyconfig.processors¶
Provide a list of a anyconfig.models.processor and so on.
Changed in version 0.10.2:
Split and re-organize the module and add some data types.
Added in version 0.9.5:
Add to abstract processors such like Parsers (loaders and dumpers).
- class anyconfig.processors.Processors(processors=None)¶
Bases:
objectAn abstract class of which instance holding processors.
- register(pcls)¶
Register processor or its children class objects.
- Return type:
None
- load_plugins()¶
Load and register pluggable processor classes internally.
- Return type:
None
- list(*, sort=False)¶
List processors.
- list_by_cid()¶
List processors by those IDs.
- list_by_type()¶
List processors by those types.
- list_by_x(item=None)¶
List processors by those factor ‘x’.
- list_x(key=None)¶
List the factor ‘x’ of processors.
- Parameters:
key (
str|None) – Which of key to return from ‘cid’, ‘type’, and ‘extention’- Return type:
list[str]- Returns:
A list of x ‘key’
- findall(obj, forced_type=None)¶
Find all of the processors match with tthe given conditions.
- Parameters:
obj (
Union[str,Path,IO,IOInfo,None]) – a file path, file, file-like object, pathlib.Path object or an ‘anyconfig.ioinfo.IOInfo’ (namedtuple) objectforced_type (
str|None) – Forced processor type to find
- Return type:
- Returns:
A list of instances of processor classes to process ‘obj’
- Raises:
ValueError, UnknownProcessorTypeError, UnknownFileTypeError
- find(obj, forced_type=None)¶
Find the processor best match with tthe given conditions.
- Parameters:
obj (
Union[str,Path,IO,IOInfo,None]) – a file path, file, file-like object, pathlib.Path object or an ‘anyconfig.ioinfo.IOInfo’ (namedtuple) objectforced_type (
Union[str,TypeVar(ProcT, bound=Processor),type[TypeVar(ProcT, bound=Processor)],None]) – Forced processor type to find or a processor class object or a processor intance
- Return type:
TypeVar(ProcT, bound=Processor)- Returns:
an instance of processor class to process ‘obj’
- Raises:
ValueError, UnknownProcessorTypeError, UnknownFileTypeError
- anyconfig.processors.list_by_x(prs, key)¶
List items by the factor ‘x’.
- Parameters:
key (
str) – Grouping key, ‘type’ or ‘extensions’- Return type:
list[tuple[str,list[TypeVar(ProcT, bound=Processor)]]]- Returns:
A list of
Processoror its children classes grouped by given ‘item’, [(cid, [Processor)]] by default
- anyconfig.processors.load_plugins(pgroup)¶
Load processor plugins.
A generator function to yield a class object of
anyconfig.models.processor.Processor.- Parameters:
pgroup (
str) – A string represents plugin type, e.g. anyconfig_backends- Return type:
Iterator[type[TypeVar(ProcT, bound=Processor)]]