# Path: chamber/models/handlers.py
# class BaseHandler:
#     """
#     Base dispatcher class that can be subclassed to call a handler based on a change in some a SmartModel.
#     If you subclass, be sure the __call__ method does not change signature.
#     """
# 
#     signal = None
# 
#     def __init__(self, signal=None):
#         self._signal = signal if signal is not None else self.signal
# 
#     def connect(self, sender):
#         if not self._signal:
#             raise ImproperlyConfigured('Handler cannot be connected as dispatcher, because signal is not set')
#         self._signal.connect(self, sender=sender)
# 
#     def __call__(self, instance, **kwargs):
#         """
#         `instance` ... instance of the SmartModel where the handler is being called
#         Some dispatchers require additional params to evaluate the handler can be dispatched,
#         these are hidden in args and kwargs.
#         """
#         if self.can_handle(instance, **kwargs):
#             self._handle(instance, **kwargs)
# 
#     def _handle(self, instance, **kwargs):
#         self.handle(instance, **kwargs)
# 
#     def can_handle(self, instance, **kwargs):
#         return True
# 
#     def handle(self, instance, **kwargs):
#         raise NotImplementedError


import types
from collections import defaultdict
from django.core.exceptions import ImproperlyConfigured
from .handlers import BaseHandler





class BaseDispatcher:
    """
    Base dispatcher class that can be subclassed to call a handler based on a change in some a SmartModel.
    If you subclass, be sure the __call__ method does not change signature.
    """

    signal = None

    def __init__(self, handler, signal=None):
        self.handler = handler
        assert (isinstance(handler, types.FunctionType)

# Path: chamber/models/handlers.py
# class BaseHandler:
#     """
#     Base dispatcher class that can be subclassed to call a handler based on a change in some a SmartModel.
#     If you subclass, be sure the __call__ method does not change signature.
#     """
# 
#     signal = None
# 
#     def __init__(self, signal=None):
#         self._signal = signal if signal is not None else self.signal
# 
#     def connect(self, sender):
#         if not self._signal:
#             raise ImproperlyConfigured('Handler cannot be connected as dispatcher, because signal is not set')
#         self._signal.connect(self, sender=sender)
# 
#     def __call__(self, instance, **kwargs):
#         """
#         `instance` ... instance of the SmartModel where the handler is being called
#         Some dispatchers require additional params to evaluate the handler can be dispatched,
#         these are hidden in args and kwargs.
#         """
#         if self.can_handle(instance, **kwargs):
#             self._handle(instance, **kwargs)
# 
#     def _handle(self, instance, **kwargs):
#         self.handle(instance, **kwargs)
# 
#     def can_handle(self, instance, **kwargs):
#         return True
# 
#     def handle(self, instance, **kwargs):
#         raise NotImplementedError


# Path: chamber/models/dispatchers.py
import types
from collections import defaultdict
from django.core.exceptions import ImproperlyConfigured
from .handlers import BaseHandler






class BaseDispatcher:
    """
    Base dispatcher class that can be subclassed to call a handler based on a change in some a SmartModel.
    If you subclass, be sure the __call__ method does not change signature.
    """

    signal = None

    def __init__(self, handler, signal=None):
        self.handler = handler
        assert (isinstance(handler, types.FunctionType)

                or isinstance(handler, BaseHandler)), 'Handler must be function or instance of ' \