<commit_before>import re


class BaseHandler:
    def __init__(self, pattern=None, *args, **kwargs):
        self.pattern = pattern
        self.kwargs = kwargs

    def check(self, message):
        self.message = message
        self.full_clean()
        return self.match(self.message)

    def full_clean(self):
        for method_name in dir(self):
            if method_name.startswith('clean_'):
                method = getattr(self, method_name)
                method()

    def match(self, message):
        raise Exception('Method Not Implemented')


class RegexHandler(BaseHandler):
    def match(self, message):
        compile = re.compile(self.pattern)
        if compile.match(self.message.text):
            return True
        return False


class CaseSensitiveMixin:
    def clean_case_senstive(self):
        if not self.kwargs.get('case_sensitive'):
            self.message.text = self.message.text.lower()


class MessageHandler(CaseSensitiveMixin, BaseHandler):
    def match(self, message):
        if message.text == self.pattern:
            return True
        return False


class StartswithHandler(CaseSensitiveMixin, BaseHandler):
    def match(self, message):
        if message.text.startswith(self.pattern):
            return True
        return False


class DefaultHandler:
    def check(self, message):
        return True
<commit_msg>Added if to avoid call re.compile twice<commit_after>import re


class BaseHandler:
    def __init__(self, pattern=None, *args, **kwargs):
        self.pattern = pattern
        self.kwargs = kwargs

    def check(self, message):
        self.message = message
        self.full_clean()
        return self.match(self.message)

    def full_clean(self):
        for method_name in dir(self):
            if method_name.startswith('clean_'):
                method = getattr(self, method_name)
                method()

    def match(self, message):
        raise Exception('Method Not Implemented')


class RegexHandler(BaseHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.regex = None

    def match(self, message):
        if not self.regex:
            self.regex = re.compile(self.pattern)

        if self.regex.match(message.text):
            return True
        return False


class CaseSensitiveMixin:
    def clean_case_senstive(self):
        if not self.kwargs.get('case_sensitive'):
            self.message.text = self.message.text.lower()


class MessageHandler(CaseSensitiveMixin, BaseHandler):
    def match(self, message):
        if message.text == self.pattern:
            return True
        return False


class StartswithHandler(CaseSensitiveMixin, BaseHandler):
    def match(self, message):
        if message.text.startswith(self.pattern):
            return True
        return False


class DefaultHandler:
    def check(self, message):
        return True

{'fraction_non_alphanumeric': 0.09427494000685636, 'fraction_numerical': 0.0, 'mean_word_length': 2.4329411764705884, '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': '1158700', 'n_tokens_mistral': 817, 'n_tokens_neox': 792, 'n_words': 205}