baroque.datastructures package

Submodules

baroque.datastructures.bags module

class baroque.datastructures.bags.EventTypesBag(eventtypes=None)

Bases: object

A type-aware collection of event types

Parameters:eventtypes (collection, optional) – collection of baroque.entities.eventtypes.EventType items.
add(eventtypes)

Adds a collection of eventtypes to this bag.

Parameters:of (list) – the event types to be added
Raises:AssertionError – when the supplied arg is not a collection or its items are not baroque.entities.eventtypes.EventType instances or baroque.entities.eventtypes.EventType subclasses
class baroque.datastructures.bags.ReactorsBag

Bases: object

A type-aware collection of reactors.

count()

Tells how many reactors are in this bag.

Returns:int
remove(reactor)

Removes a reactor from this bag.

Parameters:reactor (baroque.entities.reactor.Reactor) – the reactor to be removed
remove_all()

Removes all reactors from this bag.

run(reactor)

Adds a reactor to this bag.

Parameters:reactor (baroque.entities.reactor.Reactor) – the reactor to be added
Raises:AssertionError – when the supplied arg is not a baroque.entities.reactor.Reactor instance
trigger(reactor)

Alias for baroque.datastructures.bags.ReactorBag.run method

Parameters:reactor (baroque.entities.reactor.Reactor) – the reactor to be added
Raises:AssertionError – when the supplied arg is not a baroque.entities.reactor.Reactor instance

baroque.datastructures.counters module

class baroque.datastructures.counters.EventCounter

Bases: object

A counter of events.

count(eventtype)

Tells how many events have been counted of the specified type

Parameters:eventtype (baroque.entities.eventtype.EventType) – the type of events to be counted
Returns:int
count_all()

Tells how many events have been counted globally

Returns:int
increment_counting(event)

Counts an event

Parameters:event (baroque.entities.event.Event) – the event to be counted

baroque.datastructures.registries module

class baroque.datastructures.registries.EventTypesRegistry

Bases: object

Interface adapter to an event bag.

count()

Tells how many event types are registered on this registry

Returns:int
register(eventtype)

Adds an event type to this registry.

Parameters:eventtype (baroque.entities.eventtypes.EventType instance or type object) – the event type to be added
Raises:AssertionError – when argument is not an baroque.entities.eventtypes.EventType instance or a type object
remove(eventtype)

Removes an event type from this registry

Parameters:eventtype (baroque.entities.eventtypes.EventType instance or type object) – the event type to be removed
Raises:AssertionError – when argument is not an baroque.entities.eventtypes.EventType instance or a type object
remove_all()

Removes all event types from this registry.

class baroque.datastructures.registries.ReactorsRegistry

Bases: object

A tracker for reaactors. Each reactor is intended to be executed when a certain type of events is fired: the reactors-eventtypes relationship is stored internally using a dict of bag datastructures.

Some reactors must be executed upon any event firing: these are stored internally into a “jolly bag”.

get_bag(eventtype)

Gives the reactors bag associated to the specified event type.

Parameters:eventtype (baroque.entities.eventtype.EventType) – the associated event type
Returns:baroque.datastructures.bags.ReactorsBag
Raises:AssertionError – when the supplied event type is not a baroque.entities.eventtype.EventType instance or a type object
get_event_types_registry()

Gives the encapsulated event type registry

Returns:baroque.registries.EventTypeRegistry
get_jolly_bag()

Gives the encapsulated bag that contains reactors to be executed upon any event firing.

Returns:baroque.registries.EventTypeRegistry
get_or_create_bag(eventtype)

Gives the reactors bag associated to the specified event type, or creates one in case it does not exist yet.

Parameters:eventtype (baroque.entities.eventtype.EventType instance or type object) – the associated event type
Returns:baroque.datastructures.bags.ReactorsBag
Raises:AssertionError – when the supplied event type is not a baroque.entities.eventtype.EventType instance or a type object
remove_all()

Clears the contents of all the encapsulated reactor bags.

to(eventtype)

Gives the encapsulated bag that contains reactors to be executed upon the firing of events of the supplied type.

Parameters:eventtype (baroque.entities.eventtype.EventType) – the associated event type
Returns:baroque.datastructures.bags.ReactorsBag
to_any_event()

Gives the encapsulated jolly bag, containing reactors to be executed upon the firing of any event.

Returns:baroque.datastructures.bags.ReactorsBag
class baroque.datastructures.registries.TopicsRegistry

Bases: object

A tracker for reactors to be executed upong event firing of events on specified topics: the reactors-topics relationship is stored internally using a dict

count()

Tells how many topics are registered.

Returns:int
new(name, eventtypes, **kwargs)

Creates a new topic, adds it to the registry and returns it.

Parameters:name (str) – name of the new topic
eventtypes (collection): the baroque.entities.eventtype.EventType objects that characterize the new topic
**kwargs: positional arguments for Topic instantiation
Returns:baroque.entities.topic.Topic
of(owner)

Returns the topics belonging to the supplied owner

Parameters:owner (str) – the topics owner
Returns:list of baroque.entities.topic.Topic items
on_topic_run(topic, reactor)

Binds the specified reactor to event firing on the specified topic.

Parameters:
Raises:

AssertionError – when any of the supplied args is of wrong type

publish_on_topic(event, topic)
Publishes an event on a tracked topic, executing all the reactors
bound to that topic.
Parameters:
  • event (:obj:`baroque.entities.event.Event) – the event to be published
  • topic (:obj:`baroque.entities.topic.Topic) – the target topic
Raises:

AssertionError – when any of the supplied args is of wrong type

register(topic)

Adds a topic to the registry.

Parameters:topic (baroque.entities.topic.Topic) – the topic to be added
remove(topic)

Removes a topic from the registry.

Parameters:topic (baroque.entities.topic.Topic) – the topic to be removed
remove_all()

Clears all the topics from the registry.

with_id(id)

Returns the topic with the specified identifier

Parameters:id (str) – the topic id
Returns:baroque.entities.topic.Topic
with_name(name)

Returns the topic with the specified name (exact string matching)

Parameters:name (str) – the topic name
Returns:baroque.entities.topic.Topic
with_tags(tags)

Returns the topics marked by the specified tags.

Parameters:tags (set of str items) – the tag set
Returns:list of baroque.entities.topic.Topic items
Raises:AssertionError – when the supplied tag set is not an iterable

Module contents