id_translation.dio#

Integration for insertion and extraction of IDs and translations to and from various data structures.

Functions

get_resolution_order(*[, real])

Returns known DataStructureIO implementations.

register_io(io)

Register a new IO implementation.

resolve_io(arg, **kwargs)

Get an IO instance for arg.

Classes

DataStructureIO()

Insertion and extraction of IDs and translations.

class DataStructureIO[source]#

Bases: Generic[TranslatableT, NameType, SourceType, IdType]

Insertion and extraction of IDs and translations.

abstract extract(translatable, names)[source]#

Extract IDs from translatable.

Parameters:
  • translatable – Data to extract IDs from.

  • names – List of names in translatable to extract IDs for.

Returns:

A dict {name: ids}.

classmethod get_rank()[source]#

Return the rank of this implementation.

See dio.get_resolution_order() for details.

Returns:

Implementation rank.

Raises:

ValueError – If the implementation is not registered.

abstract classmethod handles_type(arg)[source]#

Return True if the implementation handles data for the type of arg.

abstract insert(translatable, names, tmap, copy)[source]#

Insert translations into translatable.

Parameters:
  • translatable – Data to translate. Modified iff copy=False.

  • names – Names in translatable to translate.

  • tmap – Translations for IDs in translatable.

  • copy – If True, modify contents of the original translatable. Otherwise, returns a copy.

Returns:

A copy of translatable if copy=True, None otherwise.

Raises:

NotInplaceTranslatableError – If copy=False for a type which is not translatable in-place.

names(translatable)[source]#

Extract names from translatable.

Parameters:

translatable – Data to extract names from.

Returns:

A list of names to translate. Returns None if names cannot be extracted.

classmethod register()[source]#

Register this implementation for all Translator instances.

See dio.register_io() for details.

get_resolution_order(*, real=False)[source]#

Returns known DataStructureIO implementations.

Parameters:

real – If True, return the actual list instead of a copy.

Returns:

A list of IO implementations.

register_io(io)[source]#

Register a new IO implementation.

Classes are polled through DataStructureIO.handles_type() in reverse insertion order (new implementations are polled first). Re-registering an implementation again will move it to the first position in the search order.

Parameters:

io – A DataStructureIO type.

resolve_io(arg, **kwargs)[source]#

Get an IO instance for arg.

Parameters:
  • arg – An argument to get IO for.

  • **kwargs – Keyword arguments for the IO class.

Returns:

A data structure IO instance for arg.

Raises:

UntranslatableTypeError – If no suitable IO implementation could be found.

See also

The register_io() function.

Modules

id_translation.dio.exceptions

Data structure I exceptions.

id_translation.dio.integration

Integration modules.