pycyphal.application.register.backend.dynamic module

class pycyphal.application.register.backend.dynamic.DynamicBackend[source]

Bases: Backend

Register backend where register access is delegated to external getters and setters. It does not store values internally. Exceptions raised by getters/setters are wrapped into BackendError.

Create new registers and change value of existing ones using __setitem__().

>>> from pycyphal.application.register import Bit
>>> b = DynamicBackend()
>>> b.persistent
>>> b.get("foo") is None
>>> b.index(0) is None
>>> foo = Value(bit=Bit([True, False, True]))
>>> def set_foo(v: Value):
...     global foo
...     foo = v
>>> b["foo"] = (lambda: foo), set_foo   # Create new mutable register.
>>> b["foo"].mutable
>>> list(b["foo"].value.bit.value)
[True, False, True]
>>> b["foo"] = Value(bit=Bit([False, True, True]))  # Set new value.
>>> list(b["foo"].value.bit.value)
[False, True, True]
>>> b["foo"] = lambda: foo  # Replace register with a new one that is now immutable.
>>> b["foo"] = Value(bit=Bit([False, False, False]))    # Value cannot be changed.
>>> list(b["foo"].value.bit.value)
[False, True, True]
>>> list(b)
>>> del b["foo"]
>>> list(b)
__init__() None[source]
property location: str[source]

This is a stub.

property persistent: bool[source]

Always false.

close() None[source]

Clears all registered registers.

index(index: int) str | None[source]
__getitem__(key: str) Entry[source]
__setitem__(key: str, value: Entry | Value_1_0 | Callable[[], Value_1_0] | Tuple[Callable[[], Value_1_0], Callable[[Value_1_0], None]]) None[source]
  • key – The register name.

  • value

    • If this is an instance of Entry or Value, and the referenced register is mutable, its setter is invoked with the supplied instance of Value (if Entry is given, the value is extracted from there and the mutability flag is ignored). If the register is immutable, nothing is done. The caller is required to ensure that the type is acceptable.

    • If this is a single callable, a new immutable register is defined (existing registers overwritten).

    • If this is a tuple of two callables, a new mutable register is defined (existing registers overwritten).

__delitem__(key: str) None[source]
__iter__() Iterator[str][source]
__len__() int[source]