<commit_before>__author__ = 'calvin'
__version__ = '1.3.0'

from properties import BaseProperty, DictProperty, ObservableDict

class BindException(Exception):
    pass

class EventDispatcher(object):

    def __init__(self, **kwargs):
        self._events = {}
        bindings = {}
        # Walk through the MRO looking for Property attributes in the classes. Then register and bind them to
        # 'on_<prop_name>' if it exists.
        for cls in self.__class__.__mro__:
            for prop_name, prop in cls.__dict__.iteritems():
                if isinstance(prop, BaseProperty):
                    prop.name = prop_name
                    prop.register(self, prop_name, prop.default_value)
                    if hasattr(self, 'on_{}'.format(prop_name)):
                        func = getattr(self, 'on_{}'.format(prop_name))
                        bindings.update({prop_name: func})

        self.bind(**bindings)

    def dispatch(self, key, *args):
        prop = BaseProperty.get_property(self, key)
        for callback in prop.instances[self]['callbacks']:
            if callback(*args):
                break

    def dispatch_event(self, event, *args):
        for callback in self._events[event]:
            if callback(*args):
                break

    def register_event(self, name):
        self._events[name] = [getattr(self, 'on_{}'.format(name))] if hasattr(self, 'on_{}'.format(name)) else []

    def unbind(self, **kwargs):
        for prop_name, callback in kwargs.iteritems():
            prop = BaseProperty.get_property(self, prop_name)
            prop.instances[self]['callbacks'].remove(callback)

    def bind(self, **kwargs):
        for prop_name, callback in kwargs.iteritems():<commit_msg>unbind now unbinds events. added unbind_all<commit_after>__author__ = 'calvin'
__version__ = '1.3.0'

from properties import BaseProperty, DictProperty, ObservableDict

class BindException(Exception):
    pass

class EventDispatcher(object):

    def __init__(self, **kwargs):
        self._events = {}
        bindings = {}
        # Walk through the MRO looking for Property attributes in the classes. Then register and bind them to
        # 'on_<prop_name>' if it exists.
        for cls in self.__class__.__mro__:
            for prop_name, prop in cls.__dict__.iteritems():
                if isinstance(prop, BaseProperty):
                    prop.name = prop_name
                    prop.register(self, prop_name, prop.default_value)
                    if hasattr(self, 'on_{}'.format(prop_name)):
                        func = getattr(self, 'on_{}'.format(prop_name))
                        bindings.update({prop_name: func})

        self.bind(**bindings)

    def dispatch(self, key, *args):
        prop = BaseProperty.get_property(self, key)
        for callback in prop.instances[self]['callbacks']:
            if callback(*args):
                break

    def dispatch_event(self, event, *args):
        for callback in self._events[event]:
            if callback(*args):
                break

    def register_event(self, name):
        self._events[name] = [getattr(self, 'on_{}'.format(name))] if hasattr(self, 'on_{}'.format(name)) else []

    def unbind(self, **kwargs):
        for prop_name, callback in kwargs.iteritems():
            try:
                prop = BaseProperty.get_property(self, prop_name)
            except KeyError:
                if callback in self._events:
                    self._events.remove(callback)
                else:
                    raise ValueError('No such bindings for event %s' % prop_name)
            else:
                prop.instances[self]['callbacks'].remove(callback)

    def unbind_all(self, *args):
        for prop_name in args:
            try:
                prop = BaseProperty.get_property(self, prop_name)
            except KeyError:
                if prop_name in self._events:
                    self._events[prop_name] = []
                else:
                    raise ValueError('No such bindings for event %s' % prop_name)
            else:
                prop.instances[self]['callbacks'] = []


    def bind(self, **kwargs):
        for prop_name, callback in kwargs.iteritems():
{'fraction_non_alphanumeric': 0.10798010892730286, 'fraction_numerical': 0.0014207909069381957, 'mean_word_length': 2.101321585903084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3540849', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1137, 'n_words': 295}