Whad generic stack model reference

Decorators

class whad.common.stack.alias(name)[source]

Layer class decorator to specify layer text alias.

class whad.common.stack.source(source, tag='default', contextual=False)[source]

Layer method decorator to perform source matching.

Source matching can be done on layer name and optionally a tag (some user-defined text used to represent a specific state or operation).

This tag is used to dispatch the incoming data to the correct callback, each callback accepting additional named arguments as specified by the implementer.

class whad.common.stack.instance(source, tag='default')[source]

Instance has basically the same behavior as the source decorator, but forces it to include the instance reference.

Layer classes

class whad.common.stack.Layer(parent=None, layer_name=None, options={})[source]

Basic stack layer.

classmethod add(clazz, input=False)[source]

Add a sub-layer class.

configure(options)[source]

Configure callback.

Override this method to configure the layer when the stack is instanciated.

create_layer(layer_class, inst_name)[source]

Create a layer and registers it into our list of layers.

destroy(layer_instance)[source]

Remove an instantiated layer from our known layers.

classmethod export(output_file=None)[source]

Export to graphviz file.

classmethod find(alias)[source]

Find a sub-layer class based on its alias

get_entry_layer()[source]

Return the group entry layer.

get_handler(source, tag='default')[source]

Retrieve the registered handler for a given source and tag (if any).

get_layer(name, children_only=False)[source]

Retrieve a specific layer based on its name.

get_message_handler(source)[source]

Find the message handler associated with the source

classmethod get_structure()[source]

Retrieve layer structure.

has_handler(source, tag='default')[source]

Check if this layer has a registered method to process messages coming from a specific source/tag.

has_layer(name)[source]

Check if layer has a specific sublayer.

instantiate(contextual_clazz)[source]

Instantiate a contextual layer.

classmethod list_emitters()[source]

Find sublayers that send messages to the specified layer.

load(state)[source]

Set this layer properties dictionnary (used to load state).

populate(options={})[source]

Sub-layers instanciation.

We instanciate each layer and register these instances into our object.

register_monitor_callback(callback)[source]

Register a callback to monitor messages sent between layers.

classmethod remove(clazz)[source]

Remove a sub-layer class.

save()[source]

Return this layer saved state.

send(destination, data, tag='default', **kwargs)[source]

Send a message to the corresponding layer.

send_from(source, destination, data, tag='default', **kwargs)[source]

Dispatch data from source to destination, with an optional tag and arguments.

state_class

alias of LayerState

unregister_monitor_callback(callback)[source]

Unregister a previously registered callback.

class whad.common.stack.ContextualLayer(parent=None, layer_name=None, options={})[source]

This layer is not automatically loaded when the stack model is created and must be instanciated specifically by another layer.

Unit testing

class whad.common.stack.tests.Sandbox(parent=None, layer_name=None, options={}, target=None)[source]

This layer is used as a container for one or more layers that need to be tested.

dummy_message_handler(source, data, **kwargs)[source]

Dummy message handler, does nothing.

expect(messages, strict=False)[source]

Checks if one or more messages have been captured.

get_handler(source, tag)[source]

This method is called by our stack message handler search code, and is required here to return our dummy message handler.

get_layer(name: str)[source]

Retrieve a specific layer if one of ours, or this instance if layer cannot be found.

instantiate(clazz)[source]

Instantiate a layer and install a custom message monitor callback

log_message(source, destination, data, tag='default', **kwargs)[source]

Layer message monitoring.

populate(options={})[source]

Populate static layers and install a custom message monitor callback

class whad.common.stack.tests.LayerMessage(source, destination, data, tag='default', **kwargs)[source]

This class is used by Sandbox to represent a message between two layers, keeping track of the source, destination, data, tag and named arguments.