def on_circuit_built(self, callback): """ :param callback: will be called (with 'circuit' instance) when a CIRC BUILT event happens """ listener = CircuitListenerMixin() listener.circuit_built = callback self.add_circuit_listener(listener) return callback # so we can be used as a listener
def on_circuit_failed(self, callback): """ :param callback: will be called (with 'circuit' instance, and arbitrary kwargs) when a CIRC FAILED event happens """ listener = CircuitListenerMixin() listener.circuit_failed = callback self.add_circuit_listener(listener) return callback # so we can be used as a listener
def on_circuit_extend(self, callback): """ :param callback: will be called (with 'circuit' and 'router' instances) when a CIRC EXTENDED event happens """ listener = CircuitListenerMixin() listener.circuit_extend = callback self.add_circuit_listener(listener) return callback # so we can be used as a listener
def test_listener_mixin(self): listener = CircuitListenerMixin() from zope.interface.verify import verifyObject self.assertTrue(verifyObject(ICircuitListener, listener)) # call all the methods with None for each arg. This is mostly # just to gratuitously increase test coverage, but also # serves to ensure these methods don't just blow up for (methodname, desc) in ICircuitListener.namesAndDescriptions(): method = getattr(listener, methodname) args = [None] * len(desc.positional) method(*args)