rics.translation.dio package

Submodules

rics.translation.dio.exceptions module

Data structure I exceptions.

exception rics.translation.dio.exceptions.DataStructureIOError[source]

Bases: RuntimeError

Base class for translator exceptions.

exception rics.translation.dio.exceptions.UntranslatableTypeError(t: Type[Any])[source]

Bases: DataStructureIOError

Exception indicating that a type cannot be translated.

Parameters

t – A type.

exception rics.translation.dio.exceptions.NotInplaceTranslatableError(arg: Any)[source]

Bases: DataStructureIOError

Exception indicating that a type cannot be translated in-place.

Parameters

arg – Something that can’t be translated inplace.

Module contents

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

class rics.translation.dio.DataStructureIO[source]

Bases: object

Insertion and extraction of IDs and translations.

static handles_type(arg: Any) bool[source]

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

abstract static extract(c: Any, names: List[NameType]) Dict[NameType, Sequence[IdType]][source]

Extract IDs from c.

Parameters
  • c – A collection to extract IDs from.

  • names – List of names to extract IDs for.

Returns

A dict {name, ids}.

abstract static insert(c: Any, names: List[NameType], tmap: TranslationMap, copy: bool) Optional[Any][source]

Insert translations into c.

Parameters
  • c – A collection apply translations for. Modified iff copy=False.

  • names – Names in t to translate..

  • tmap – Translations for IDs in c.

  • copy – If True modify contents of the original collection c. Otherwise, return a copy.

Returns

A copy of c if copy=True. None otherwise.

Raises

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

rics.translation.dio.resolve_io(arg: DefaultTranslatable) Type[DataStructureIO][source]

Get an IO instance for arg.

Parameters

arg – An argument to get IO for.

Returns

A data structure IO instance for arg.

Raises

UntranslatableTypeError – If not IO could be found.