<commit_before>from functools import partial
_rfa_conditions = {}
_award_rfa_cache = {}


def rfa(*rfa_names):
    rfa_names = frozenset(rfa_names)
    if rfa_names not in _rfa_conditions:
        _rfa_conditions[rfa_names] = partial(_rfa, rfa_names)
    return _rfa_conditions[rfa_names]


def _rfa(rfa_names, value, system):
    context = system['context']
    award_uuid = context.upgrade_properties(finalize=False)['award']
    # Cache award rfa as these do not change
    if award_uuid not in _award_rfa_cache:
        root = system['root']
        award = root.get_by_uuid(award_uuid)
        _award_rfa_cache[award_uuid] = award.upgrade_properties(finalize=False)['rfa']
    return _award_rfa_cache[award_uuid] in rfa_names<commit_msg>Rewrite rfa condition<commit_after>import functools


def memoize(obj):
    # Replace with functools.lru_cache() for Python 3.2+
    cache = obj.cache = {}

    @functools.wraps(obj)
    def memoizer(*args, **kwargs):
        if args not in cache:
            cache[args] = obj(*args, **kwargs)
        return cache[args]
    return memoizer


@memoize
def rfa(*rfa_names):
    """ award.rfa auditor condition factory
    """
    def rfa_condition(value, system):
        context = system['context']
        award_uuid = context.upgrade_properties(finalize=False)['award']
        rfa = _award_rfa(award_uuid, system['root'])
        return rfa in rfa_names

    return rfa_condition


@memoize
def _award_rfa(award_uuid, root):
    award = root.get_by_uuid(award_uuid)
    return award.upgrade_properties(finalize=False)['rfa']
{'fraction_non_alphanumeric': 0.10382165605095542, 'fraction_numerical': 0.0012738853503184713, 'mean_word_length': 3.833846153846154, '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': '3844735', 'n_tokens_mistral': 557, 'n_tokens_neox': 545, 'n_words': 111}