<commit_before>from copy import copy
from rightshift import Transformer

__author__ = '<EMAIL>'


class Matcher(Transformer):
    """
    TODO: Document
    """
    def __or__(self, other):
        """
        TODO: Document
        """
        if isinstance(other, Matcher):
            transformers = [self]
            if isinstance(other, BooleanOr):
                transformers.extend(copy(other.transformers))
            else:
                transformers.append(other)
            return BooleanOr(*transformers)

        return super(Matcher, self).__or__(other)

    def __and__(self, other):
        """
        TODO: Document
        """
        if isinstance(other, Matcher):
            transformers = [self]
            if isinstance(other, BooleanAnd):
                transformers.extend(copy(other.transformers))
            else:
                transformers.append(other)
            return BooleanAnd(*transformers)

        return super(Matcher, self).__and__(other)


class BooleanAnd(Matcher):
    """
    TODO: Document
    """
    def __init__(self, *transformers):
        """
        TODO: Document
        """
        self.transformers = transformers

    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        for transformer in self.transformers:
            if transformer(value, **flags) is False:
                return False
        return True


class BooleanOr(Matcher):
    """
    TODO: Document
    """
    def __init__(self, *transformers):
        """
        TODO: Document
        """
        self.transformers = transformers

    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        for transformer in self.transformers:
            if transformer(value, **flags) is True:
                return True
        return False


class InstanceOf(Matcher):
    """
    An InstanceOf matcher is very simple. When called with a value it will indicate
    whether the value is an instance of the type the matcher was instantiated
    with.

    """
    def __init__(self, type):
        """
        :param type: A type or tuple of types.
        """
        self.type = type

    def __call__(self, value, **flags):
        return isinstance(value, self.type)

instance_of = InstanceOf
"""
instance_of is a an alias to the InstanceOf class within this module.
"""
<commit_msg>#3: Added MatcherException and Comparison matchers.<commit_after>from copy import copy
from rightshift import Transformer, RightShiftException

__author__ = '<EMAIL>'


class MatcherException(RightShiftException):
    """
    TODO: Document
    """
    pass


class Matcher(Transformer):
    """
    TODO: Document
    """
    def __or__(self, other):
        """
        TODO: Document
        """
        if isinstance(other, Matcher):
            transformers = [self]
            if isinstance(other, BooleanOr):
                transformers.extend(copy(other.transformers))
            else:
                transformers.append(other)
            return BooleanOr(*transformers)

        return super(Matcher, self).__or__(other)

    def __and__(self, other):
        """
        TODO: Document
        """
        if isinstance(other, Matcher):
            transformers = [self]
            if isinstance(other, BooleanAnd):
                transformers.extend(copy(other.transformers))
            else:
                transformers.append(other)
            return BooleanAnd(*transformers)

        return super(Matcher, self).__and__(other)


class BooleanAnd(Matcher):
    """
    TODO: Document
    """
    def __init__(self, *transformers):
        """
        TODO: Document
        """
        self.transformers = transformers

    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        for transformer in self.transformers:
            if transformer(value, **flags) is False:
                return False
        return True

true_for_all_of = all = every = BooleanAnd
"""
TODO: Document
"""


class BooleanOr(Matcher):
    """
    TODO: Document
    """
    def __init__(self, *transformers):
        """
        TODO: Document
        """
        self.transformers = transformers

    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        for transformer in self.transformers:
            if transformer(value, **flags) is True:
                return True
        return False

true_for_one_of = some = any = BooleanOr
"""
TODO: Document
"""


class IsInstance(Matcher):
    """
    An IsInstance matcher is very simple. When called with a value it will indicate
    whether the value is an instance of the type the matcher was instantiated
    with.

    """
    def __init__(self, type):
        """
        :param type: A type or tuple of types.
        """
        self.type = type

    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type)

is_instance = IsInstance
"""
is_instance is a an alias to the IsInstance class within this module.
"""


class Comparison(Matcher):
    """
    TODO: Document
    """
    def __init__(self, value):
        """
        TODO: Document
        """
        self.value = value
        self.type = type(value)


class LessThan(Comparison):
    """
    TODO: Document
    """
    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type) and value < self.value


class LessThanEqualTo(Comparison):
    """
    TODO: Document
    """
    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type) and value <= self.value


class EqualTo(Comparison):
    """
    TODO: Document
    """
    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type) and value == self.value


class NotEqualTo(Comparison):
    """
    TODO: Document
    """
    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type) and value != self.value


class GreaterThanEqualTo(Comparison):
    """
    TODO: Document
    """
    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type) and value >= self.value


class GreaterThan(Comparison):
    """
    TODO: Document
    """
    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return isinstance(value, self.type) and value > self.value


class __ValueIs(object):
    """
    TODO: Document
    """
    def __lt__(self, other):
        """
        TODO: Document
        """
        return LessThan(other)

    def __le__(self, other):
        """
        TODO: Document
        """
        return LessThanEqualTo(other)

    def __eq__(self, other):
        """
        TODO: Document
        """
        return EqualTo(other)

    def __ne__(self, other):
        """
        TODO: Document
        """
        return NotEqualTo(other)

    def __ge__(self, other):
        """
        TODO: Document
        """
        return GreaterThanEqualTo(other)

    def __gt__(self, other):
        """
        TODO: Document
        """
        return GreaterThan(other)

value_is = __ValueIs()
"""
TODO: Document
"""


class IsNot(Matcher):
    """
    TODO: Document
    """
    def __init__(self, matcher):
        """
        TODO: Document
        """
        if not isinstance(matcher, Matcher):
            raise MatcherException('{} is not an instance of '
                                   'rightshift.matchers.Matcher'.format(matcher))
        self.matcher = matcher

    def __call__(self, value, **flags):
        """
        TODO: Document
        """
        return not self.matcher(value, **flags)

is_not = IsNot
{'fraction_non_alphanumeric': 0.11158744168452907, 'fraction_numerical': 0.00012608750472828143, 'mean_word_length': 1.9118942731277533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965558', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2131, 'n_words': 579}