skip to navigation
skip to content

observer.simple 1.0.0

A very simple implementation of the observer pattern

A simple implementation of the observer pattern.

import observer
# Create a subject and list the events it might fire
foo = observer.Subject('bar', 'baz')

# Add a listener
def foo_bar_listener(*args):
   print("heard 'bar'", args)

foo('bar', foo_bar_listener)

# fire events
foo.fire('bar', 1, 2, 3)
# -> heard 'bar' (1, 2, 3)

# Trying to listen to an unregistered event throws an error
foo('snorble', lambda: None)
# -> AssertionError: snorble is not a valid event for this subject

# Same with trying to fire an unregistered event
foo.fire('snorble')
# -> AssertionError: snorble is not a valid event for this subject
 
File Type Py Version Uploaded on Size
observer.simple-1.0.0.tar.gz (md5) Source 2015-03-30 1KB