Handler definitions


In [1]:
def printer(*args, **kwargs):
    print args, kwargs

def pretty_printer(*args, **kwargs):
    import pprint
    pprint.pprint(args)
    pprint.pprint(kwargs)
    
def errorer(*args, **kwargs):
    raise Exception

Event


In [3]:
from observed import event

class C(object):
    @event
    def do(self, *args, **kwargs):
        pass

c = C()

Are multiple handlers allowed?


In [4]:
c.do.add_observer(printer)
c.do.add_observer(pretty_printer)

In [8]:
c.do(1, 2, a=3)


(1, 2) {'a': 3}
(1, 2)
{'a': 3}

Are duplicate registrations detected?


In [9]:
c.do.add_observer(printer)
c.do(1, 2, a=3)


(1, 2) {'a': 3}
(1, 2)
{'a': 3}

Do errors stop all handlers?


In [10]:
@event
def do(*args, **kwargs):
    pass

do.add_observer(errorer)
do.add_observer(printer)
do(1, 2, a=3)


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-10-eee83120b5cd> in <module>()
      5 do.add_observer(errorer)
      6 do.add_observer(printer)
----> 7 do(1, 2, a=3)

/Users/sc015622/VirtualEnvs/observers/lib/python2.7/site-packages/observed/base.pyc in __call__(self, *arg, **kw)
    128                     callback(caller, *arg, **kw)
    129                 else:
--> 130                     callback(*arg, **kw)
    131             elif callback_type == 'bound_method':
    132                 for methodName in info:

<ipython-input-1-1bd812cf050d> in errorer(*args, **kwargs)
      8 
      9 def errorer(*args, **kwargs):
---> 10     raise Exception

Exception: 

Project health

Overall: medium (more recent, but essentially one quick burst)


In [ ]: