aside.boilerplate.observable module

Contains implementation of observable-related classes.

uuid_str()str[source]

Generate a random UUID and convert it into a string.

class EventType(value)[source]

Bases: enum.Enum

Possible event types.

REASSIGN = 1
CHANGE = 2
ADD = 3
DISCARD = 4
class Event(*, attr_name: str, obj: Observable, event_type: EventType)[source]

Bases: object

Describes the cause of the observable event.

attr_name: str
obj: Observable
event_type: EventType
get_nested_object(level: Optional[int] = None)[source]

Get nested object of event.

Parameters

level – Behaves as a list index, negative indices are valid.

property split_attr_path

Get list of consecutive attributes leading to source of event.

class Observer(*, callback: Callable, regexp: Pattern[~ AnyStr], order: int, event_types: Set[EventType])[source]

Bases: object

Contains information about a subscribed observer.

callback: Callable
regexp: Pattern[~AnyStr]
order: int
event_types: Set[EventType]
class Observable(*args, **kwds)[source]

Bases: typing_extensions.Protocol

Common protocol/interface for all observable classes.

uuid: str
subscribe(callback, regexp: str = '.*', order: int = 0, event_types: Optional[Iterable[EventType]] = None)None[source]

Subscribe to changes of Observable object.

drop_observers()[source]

Drop list of tracked observers, as if no subscription were ever made.

wrap_init(old_init: Callable)Callable[source]
wrap_setattr(old_setattr: Callable)Callable[source]
observable(cls: type)Union[Type[Observable], type][source]

Make the attributes of an attrs-style Observable class also observable.

class ObservableCollection(*args, **kwds)[source]

Bases: collections.abc.MutableSet, collections.abc.Mapping, aside.boilerplate.observable.Observable

Observable collection of Observable objects.

__init__(init_vals: Optional[Iterable[Observable]] = None)[source]

Construct collection and populate it from init_vals, if any.

add(value: Observable)None[source]

Add value to collection, overwriting old value with same UUID, if any.

discard(value: Observable)None[source]

Discard object with same UUID from collection.

uuid: str