<commit_before>from __future__ import absolute_import

from . import atoms
from . import rules


__all__ = ["AND", "OR", "NOT", "MATCH", "ANYTHING", "NETBLOCK"]


AND = rules.And
OR = rules.Or
NOT = rules.No
MATCH = rules.Match
ANYTHING = rules.Anything


def NETBLOCK(ip_or_range, bits_or_end=None, keys=None):
    atom = atoms.IP(ip_or_range, bits_or_end)
    if keys:
        return rules.Or(*[rules.Match(x, atom) for x in set(keys)])
    return rules.Match(value=atom)<commit_msg>abusehelper.core.rules.compat: Instantiating one of the deprecated classes (rules.AND, rules.OR, ...) now warns of their impending removal.<commit_after>from __future__ import absolute_import

import warnings
import functools

from . import atoms
from . import rules


__all__ = ["AND", "OR", "NOT", "MATCH", "ANYTHING", "NETBLOCK"]


def _deprecated(callable):
    @functools.wraps(callable)
    def _callable(*args, **keys):
        warnings.warn(
            "abusehelper.core.rules.AND, OR, NOT, MATCH, ANYTHING and NETBLOCK " +
            "are deprecated. They will be removed in an upcoming AbuseHelper version. " +
            "Please use abusehelper.core.rules.And, Or, No, Match and Anything " +
            "instead.",
            DeprecationWarning,
            stacklevel=2
        )
        return callable(*args, **keys)
    return _callable


AND = _deprecated(rules.And)
OR = _deprecated(rules.Or)
NOT = _deprecated(rules.No)
MATCH = _deprecated(rules.Match)
ANYTHING = _deprecated(rules.Anything)


@_deprecated
def NETBLOCK(ip_or_range, bits_or_end=None, keys=None):
    atom = atoms.IP(ip_or_range, bits_or_end)
    if keys:
        return rules.Or(*[rules.Match(x, atom) for x in set(keys)])
    return rules.Match(value=atom)
{'fraction_non_alphanumeric': 0.11893764434180139, 'fraction_numerical': 0.0005773672055427252, 'mean_word_length': 3.5366492146596857, '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': '5373325', 'n_tokens_mistral': 577, 'n_tokens_neox': 563, 'n_words': 149}