<commit_before># -*- encoding: utf-8 -*-
"""Routines to handle filtering rules.
"""


from enum import Enum
from collections import namedtuple
import functools
import re
import argparse


class RuleOperator(Enum):
    include = "+"
    exclude = "-"

class Rule(namedtuple("BaseRule", ("operator", "pattern"))):

    def __new__(cls, operator=None, pattern=None):
        if not isinstance(operator, RuleOperator):
            raise TypeError("must be a rule operator, not {}"
                            .format(type(operator).__name__))
        if not pattern:
            raise ValueError("pattern cannot be empty")
        try:
            re.compile(pattern)
        except re.error:
            raise ValueError("invalid pattern '{}': {}"
                             .format(pattern, str(e)))
        return super(Rule, cls).__new__(cls, operator, pattern)

    @property
    def include(self):
        return self.operator is RuleOperator.include

    @property
    def exclude(self):
        return self.operator is RuleOperator.exclude
<commit_msg>Add missing 'fnmatch' import.<commit_after># -*- encoding: utf-8 -*-
"""Routines to handle filtering rules.
"""


from enum import Enum
from collections import namedtuple
import functools
import re
import argparse
import fnmatch


class RuleOperator(Enum):
    include = "+"
    exclude = "-"

class Rule(namedtuple("BaseRule", ("operator", "pattern"))):

    def __new__(cls, operator=None, pattern=None):
        if not isinstance(operator, RuleOperator):
            raise TypeError("must be a rule operator, not {}"
                            .format(type(operator).__name__))
        if not pattern:
            raise ValueError("pattern cannot be empty")
        try:
            re.compile(pattern)
        except re.error:
            raise ValueError("invalid pattern '{}': {}"
                             .format(pattern, str(e)))
        return super(Rule, cls).__new__(cls, operator, pattern)

    @property
    def include(self):
        return self.operator is RuleOperator.include

    @property
    def exclude(self):
        return self.operator is RuleOperator.exclude

{'fraction_non_alphanumeric': 0.1103865859338612, 'fraction_numerical': 0.0009315323707498836, 'mean_word_length': 2.470113085621971, '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': '7216228', 'n_tokens_mistral': 561, 'n_tokens_neox': 550, 'n_words': 171}