<commit_before>from rightshift import Transformer, TransformationException
from rightshift.matchers import Matcher

__author__ = '<EMAIL>'


class BreakerException(TransformationException): pass


class Breaker(Transformer):
    """
    Breaker is a base class for all Breakers.
    """
    pass


class BreakIf(Breaker):
    """
    A basic Breaker that causes a BreakerException to be thrown if the value
    it is called with does not match the Matcher supplied when the BreakIf
    instance was created.
    """
    def __init__(self, matcher):
        """

        :param matcher:
        :return:
        """
        if not isinstance(matcher, Matcher):
            raise BreakerException('{} is not an instance of {}'.format(matcher, Matcher.__class__))
        self.matcher = matcher

    def __call__(self, value, **flags):
        """
        :param value:
        :param flags:
        :return:
        """
        if self.matcher(value, **flags):
            raise BreakerException
        return value


break_if = BreakIf
"""
break_if is an alias to the BreakIf class.
"""<commit_msg>#14: Added the BreakIfNot class.<commit_after>from rightshift import Transformer, TransformationException
from rightshift.matchers import Matcher

__author__ = '<EMAIL>'


class BreakerException(TransformationException): pass


class Breaker(Transformer):
    """
    Breaker is a base class for all Breakers.
    """
    pass


class BreakIf(Breaker):
    """
    A basic Breaker that causes a BreakerException to be thrown if the value
    it is called with does not match the Matcher supplied when the BreakIf
    instance was created.
    """
    def __init__(self, matcher):
        """

        :param matcher:
        :return:
        """
        if not isinstance(matcher, Matcher):
            raise BreakerException('{} is not an instance of {}'.format(matcher, Matcher.__class__))
        self.matcher = matcher

    def __call__(self, value, **flags):
        """
        :param value:
        :param flags:
        :return:
        """
        if self.matcher(value, **flags):
            raise BreakerException
        return value

break_if = BreakIf
"""
break_if is an alias to the BreakIf class.
"""


class BreakIfNot(BreakIf):
    """
    An inverted version of the BreakIf breaker.
    """

    def __call__(self, value, **flags):
        """

        :param value:
        :param flags:
        :return:
        """
        if not self.matcher(value, **flags):
            raise BreakerException
        return value

break_if_not = BreakIfNot
"""
break_if_not is an alias to the BreakIfNot class.
"""

{'fraction_non_alphanumeric': 0.09423884013735216, 'fraction_numerical': 0.0007630675314765357, 'mean_word_length': 2.4820717131474104, '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': '7424034', 'n_tokens_mistral': 740, 'n_tokens_neox': 722, 'n_words': 246}