<commit_before>class NotEventException(Exception):
    pass

def event(func):

    func.is_event = True
    return func

def listenable(klass):

    """
        Class decorator to implement a lightweight event-dispatch model.
        @listenable on the class
        @event on the method you want to monitor


        listeners must implement the function signature of the event exactly (or take *args, **kwargs generically),
        plus a special argument called "event_result" that contains the return value of the method invocation.

        TODO: Make it work with other decorators, inheritance
    """

    def wrapper(method):

        def wrapped(*args, **kwargs):

            self = args[0]

            if self.dispatch_events(self._interrogators, method.__name__, *args, **kwargs):

                args, kwargs = self.run_manglers(method.__name__, *args, **kwargs)

                result = method(*args, **kwargs)

                kwargs["event_result"] = result

                self.dispatch_events(self._listeners, method.__name__, *args, **kwargs)

                return result

        wrapped.is_event = True
        return wrapped


    def _attach(self, event, func, handler_collection_name):
        
        if not hasattr(getattr(self, event), "is_event"):

            raise NotEventException("This method hasn't been decorated as an event listener")

        handler_collection = getattr(self, handler_collection_name)

        handlers = handler_collection.get(event, [])
        handlers.append(func)
        handler_collection[event] = handlers

        setattr(self, handler_collection_name, handler_collection)


    def attach_interrogator(self, event, interrogator):

        _attach(self, event, interrogator, "_interrogators")


    def attach_listener(self, event, listener):

        _attach(self, event, listener, "_listeners")


    def attach_mangler(self, event, listener):

        _attach(self, event, listener, "_manglers")


    def run_manglers(self, method_name, *args, **kwargs):

        for mangler in self._manglers.get(method_name, []):
            try:<commit_msg>disable the event check<commit_after>class NotEventException(Exception):
    pass

def event(func):
    func.is_event = True
    return func

def listenable(klass):

    """
        Class decorator to implement a lightweight event-dispatch model.
        @listenable on the class
        @event on the method you want to monitor


        listeners must implement the function signature of the event exactly (or take *args, **kwargs generically),
        plus a special argument called "event_result" that contains the return value of the method invocation.

        TODO: Make it work with other decorators, inheritance
    """

    def wrapper(method):

        def wrapped(*args, **kwargs):

            self = args[0]

            if self.dispatch_events(self._interrogators, method.__name__, *args, **kwargs):

                args, kwargs = self.run_manglers(method.__name__, *args, **kwargs)

                result = method(*args, **kwargs)

                kwargs["event_result"] = result

                self.dispatch_events(self._listeners, method.__name__, *args, **kwargs)

                return result

        wrapped.is_event = True
        return wrapped


    def _attach(self, event, func, handler_collection_name):
        
        #TEMPORARILY REMOVED WHILE I FIGURE OUT HOW TO MAKE MULTIPLE DECORATORS HAPPY
        #if not hasattr(getattr(self, event), "is_event"):

        #    raise NotEventException("This method hasn't been decorated as an event listener")

        handler_collection = getattr(self, handler_collection_name)

        handlers = handler_collection.get(event, [])
        handlers.append(func)
        handler_collection[event] = handlers

        setattr(self, handler_collection_name, handler_collection)


    def attach_interrogator(self, event, interrogator):

        _attach(self, event, interrogator, "_interrogators")


    def attach_listener(self, event, listener):

        _attach(self, event, listener, "_listeners")


    def attach_mangler(self, event, listener):

        _attach(self, event, listener, "_manglers")


    def run_manglers(self, method_name, *args, **kwargs):

        for mangler in self._manglers.get(method_name, []):
            try:
{'fraction_non_alphanumeric': 0.08927335640138408, 'fraction_numerical': 0.000461361014994233, 'mean_word_length': 2.773716275021758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5724196', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1128, 'n_words': 346}