Registry

class minkit.Registry(*args, **kwargs)[source]

Bases: list

Extension of a list to hold information used in minkit. It represents a collection of objects with the attribute name, providing a unique identifier (each object is assumed to be identified by its name). Any attempt to add a new element to the registry with the same name as one already existing will skip the process, as long as the two objects are the same. If they are not, then an error is raised. Constructor is directly forwarded to list.

Attributes Summary

names Names in the current registry.

Methods Summary

append(el) Append a new element to the registry.
clear() Remove all the elements from the registry.
copy() Create a copy of this instance.
count(predicate) Count the number of elements that satisfy the given predicate.
extend(iterable) Extend list by appending elements from the iterable.
from_json_object(obj) Build the parameter from a JSON object (a dictionary).
get(name) Return the object with name name in this registry.
index(name) Get the position in the registry of the object with the given name.
insert(i, p) Insert an object before index i.
pop(name) Remove and return the item with the given name.
reduce(names) Create a new Registry object keeping only the given names.
remove(name) Remove the object with the given name.
restoring_state() Enter a context where the attributes of the parameter will be restored on exit.
reverse() Reverse the registry in-place.
sort() Sort by name in-place.
to_json_object() Represent this class as a JSON-like object.

Attributes Documentation

names

Names in the current registry.

Type:list(str)

Methods Documentation

append(el)[source]

Append a new element to the registry.

Parameters:el (object) – new element to add.
Raises:ValueError – If an element is found with the same name as that provided, but they are different instances.
clear()[source]

Remove all the elements from the registry.

copy()[source]

Create a copy of this instance.

Returns:Copy of this instance.
Return type:Registry
count(predicate)[source]

Count the number of elements that satisfy the given predicate.

Parameters:predicate – function to check the contained objects.
extend(iterable)[source]

Extend list by appending elements from the iterable.

Parameters:iterable – iterable to get the new elements.
classmethod from_json_object(obj)[source]

Build the parameter from a JSON object (a dictionary). This is meant to be used together with the json module.

Parameters:obj (dict) – object to use to construct the class.
Returns:Parameter created from the JSON object.
Return type:Registry
get(name)[source]

Return the object with name name in this registry.

Parameters:name (str) – name of the object.
Returns:Object with the specified name.
Raises:LookupError – If no object is found with the given name.
index(name)[source]

Get the position in the registry of the object with the given name.

Parameters:name (str) – name of the object.
Returns:Position of the object with the given name.
Return type:int
Raises:LookupError – If no object is found with the given name.
insert(i, p)[source]

Insert an object before index i.

Parameters:
  • i (int) – index where to insert the object.
  • p (object) – object to insert.
Raises:

ValueError – If an element is found with the same name as that provided, but they are different instances.

pop(name)[source]

Remove and return the item with the given name.

Parameters:name (str) – name of the object.
reduce(names)[source]

Create a new Registry object keeping only the given names.

Parameters:names (tuple(str)) – names
Returns:New registry keeping only the provided names.
Rype:Registry
remove(name)[source]

Remove the object with the given name.

Parameters:name (str) – name of the object.
restoring_state()[source]

Enter a context where the attributes of the parameter will be restored on exit.

reverse()[source]

Reverse the registry in-place.

sort()[source]

Sort by name in-place.

to_json_object()[source]

Represent this class as a JSON-like object.

Returns:This class as a JSON-like object.
Return type:dict