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.

New in version 0.9.5:

  • Add to abstract processors such like Parsers (loaders and dumpers).

class anyconfig.processors.Processors(processors=None)

Bases: object

An 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.

Parameters:

sort (bool) – Result will be sorted if it’s True

Return type:

List[Type[TypeVar(ProcT, bound= Processor)]]

Returns:

A list of Processor or its children classes

list_by_cid()

List processors by those IDs.

Return type:

List[Tuple[str, List[TypeVar(ProcT, bound= Processor)]]]

Returns:

A list of Processor or its children classes grouped by each cid, [(cid, [Processor)]]

list_by_type()

List processors by those types.

Return type:

List[Tuple[str, List[TypeVar(ProcT, bound= Processor)]]]

Returns:

A list of Processor or its children classes grouped by each type, [(type, [Processor)]]

list_by_x(item=None)

List processors by those factor ‘x’.

Parameters:

item (Optional[str]) – Grouping key, one of ‘cid’, ‘type’ and ‘extensions’

Return type:

List[Tuple[str, List[TypeVar(ProcT, bound= Processor)]]]

Returns:

A list of Processor or its children classes grouped by given ‘item’, [(cid, [Processor)]] by default

list_x(key=None)

List the factor ‘x’ of processors.

Parameters:

key (Optional[str]) – 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) object

  • forced_type (Optional[str]) – Forced processor type to find

Return type:

List[TypeVar(ProcT, bound= Processor)]

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) object

  • forced_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 Processor or 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)]]