tron.utils.observer module

Implements the Observer/Observable pattern,

class tron.utils.observer.Observable

Bases: object

An Observable in the Observer/Observable pattern. It stores specifications and Observers which can be notified of changes by calling notify.

attach(watch_spec, observer)

Attach another observer to the listen_spec.

Listener Spec matches on:

True Matches everything <string> Matches only that event <sequence of strings> Matches any of the events in the sequence

clear_observers(watch_spec=None)

Remove all observers for a given watch_spec. Removes all observers if listen_spec is None

notify(event, event_data=None)

Notify all observers of the event.

remove_observer(observer)

Remove an observer from all watch_specs.

class tron.utils.observer.Observer

Bases: object

An observer in the Observer/Observable pattern. Given an observable object will watch for notify calls. Override handler to act on those notifications.

handler(observable, event)

Override this method to call a method to handle events.

stop_watching(observable)
watch(observable, event=True)

Adds this Observer as a watcher of the observable.

watch_all(observables, event=True)