<commit_before>from traceback import print_exc as debug
from untwisted.core import Kill, Root
import inspect

class Stop(Exception):
    pass

class Erase(Exception):
    pass

class Dispatcher(object):
    base = dict()
    def __init__(self):
        self.base = dict()
        self.pool = list()

    def drive(self, event, *args):
        try:
            self.process_base(self.base, event, args)
        except KeyError:
            pass

        try:
            self.process_base(Dispatcher.base, event, args)
        except KeyError:
            pass

        for handle in self.pool:
            handle(self, event, args)

    def process_base(self, base, event, args):
        for handle, data in base[event][:]:
            try:
                seq = handle(self, *(args + data))
            except Stop:
                break
            except StopIteration:
                pass
            except Kill, Root:
                raise
            except Erase:
                base[event].remove((handle, data))
            except Exception as e:
                debug()
                self.drive(e.__class__, e)
    
    def add_map(self, event, handle, *args):
        item = self.base.setdefault(event, list())
        item.append((handle, args))

    def del_map(self, event, handle, *args):
        self.base[event].remove((handle, args))

    @classmethod
    def add_static_map(event, handle, *args):
        item = Dispatcher.base.setdefault(event, list())
        item.append((handle, args))

    @classmethod
    def del_static_map(event, handle, *args):
        pass

    def add_handle(self, handle):
        self.pool.append(handle)

    def del_handle(self, handle):
        self.pool.remove(handle)

xmap  = lambda dispatcher, *args: dispatcher.add_map(*args)
zmap  = lambda dispatcher, *args: dispatcher.del_map(*args)
spawn = lambda dispatcher, *args: dispatcher.drive(*args)

<commit_msg>Adding method clear_maps to Dispatcher class.<commit_after>from traceback import print_exc as debug
from untwisted.core import Kill, Root
import inspect

class Stop(Exception):
    pass

class Erase(Exception):
    pass

class Dispatcher(object):
    base = dict()
    def __init__(self):
        self.base = dict()
        self.pool = list()

    def drive(self, event, *args):
        try:
            self.process_base(self.base, event, args)
        except KeyError:
            pass

        try:
            self.process_base(Dispatcher.base, event, args)
        except KeyError:
            pass

        for handle in self.pool:
            handle(self, event, args)

    def process_base(self, base, event, args):
        for handle, data in base[event][:]:
            try:
                seq = handle(self, *(args + data))
            except Stop:
                break
            except StopIteration:
                pass
            except Kill, Root:
                raise
            except Erase:
                base[event].remove((handle, data))
            except Exception as e:
                debug()
                self.drive(e.__class__, e)
    
    def add_map(self, event, handle, *args):
        item = self.base.setdefault(event, list())
        item.append((handle, args))

    def del_map(self, event, handle, *args):
        self.base[event].remove((handle, args))

    def clear_maps(self, event, handle):
        self.base[event] = filter(lambda ind: ind[0] != handle, self.base[event])

    @classmethod
    def add_static_map(event, handle, *args):
        item = Dispatcher.base.setdefault(event, list())
        item.append((handle, args))

    @classmethod
    def del_static_map(event, handle, *args):
        pass

    def add_handle(self, handle):
        self.pool.append(handle)

    def del_handle(self, handle):
        self.pool.remove(handle)

xmap  = lambda dispatcher, *args: dispatcher.add_map(*args)
zmap  = lambda dispatcher, *args: dispatcher.del_map(*args)
spawn = lambda dispatcher, *args: dispatcher.drive(*args)



{'fraction_non_alphanumeric': 0.10738423028785983, 'fraction_numerical': 0.00025031289111389235, 'mean_word_length': 2.0809560524286814, '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': '4298100', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1131, 'n_words': 307}