<commit_before>from bigsuds import ServerError
import f5
import f5.util
import re

def enabled_bool(enabled_statuses):
    """Switch from enabled_status to bool"""
    bools = []
    for es in enabled_statuses:
        if es == 'ENABLED_STATUS_ENABLED':
           bools.append(True)
        elif es == 'ENABLED_STATUS_DISABLED_BY_PARENT':
            bools.append(True)
        elif es == 'ENABLED_STATUS_DISABLED':
            bools.append(False)

    return bools


def bool_enabled(bools):
    """Switch from bool to enabled_status"""
    return ['STATE_ENABLED' if b else 'STATE_DISABLED' for b in bools]


def munge_av_status(av_statuses):
    """Truncate and lowercase availability_status"""
    return [a[20:].lower() for a in av_statuses]

class CachedFactory(f5.util.CachedFactory):
    def create(self, nodeportpools, lb=None, *args, **kwargs):
        objects = []

        for nps in nodeportpools:
            key = nps[0].name + str(nps[1]) + nps[2].name
            if lb is not None:
                key = lb.host + key

            # Save some bytes
            key = hash(key)

            if key in self._cache:
                objects.append(self._cache[key])
            else:
                obj = self._Klass(nps[0], nps[1], nps[2], *args, lb=lb, **kwargs)

                self._cache[key] = obj
                objects.append(obj)

        return objects

    def put(self, obj):
        key = obj.node.name + str(obj.port) + obj.pool.name
        if obj.lb is not None:
            key = obj.lb.host + key

        key = hash(key)
        self._cache[key] = obj


class PoolMember(object):
    __version = 11

    def __init__(self,
            node,
            port,
            pool,
            lb                  = None,
            availability_status = None,
            connection_limit    = None,
            description         = None,
            dynamic_ratio       = None,
            enabled             = None,
            priority            = None,
            rate_limit          = None,
            ratio               = None,
            status_description  = None):

        if lb is not None and not isinstance(lb, f5.Lb):
            raise ValueError('lb must be of type f5.Lb, not %s' % (type(lb).__name__))<commit_msg>Fix key delete in poolmember cachedfactory<commit_after>from bigsuds import ServerError
import f5
import f5.util
import re

def enabled_bool(enabled_statuses):
    """Switch from enabled_status to bool"""
    bools = []
    for es in enabled_statuses:
        if es == 'ENABLED_STATUS_ENABLED':
           bools.append(True)
        elif es == 'ENABLED_STATUS_DISABLED_BY_PARENT':
            bools.append(True)
        elif es == 'ENABLED_STATUS_DISABLED':
            bools.append(False)

    return bools


def bool_enabled(bools):
    """Switch from bool to enabled_status"""
    return ['STATE_ENABLED' if b else 'STATE_DISABLED' for b in bools]


def munge_av_status(av_statuses):
    """Truncate and lowercase availability_status"""
    return [a[20:].lower() for a in av_statuses]

class CachedFactory(f5.util.CachedFactory):
    def create(self, nodeportpools, lb=None, *args, **kwargs):
        objects = []

        for nps in nodeportpools:
            key = nps[0].name + str(nps[1]) + nps[2].name
            if lb is not None:
                key = lb.host + key

            # Save some bytes
            key = hash(key)

            if key in self._cache:
                objects.append(self._cache[key])
            else:
                obj = self._Klass(nps[0], nps[1], nps[2], *args, lb=lb, **kwargs)

                self._cache[key] = obj
                objects.append(obj)

        return objects

    def put(self, obj):
        key = obj.node.name + str(obj.port) + obj.pool.name
        if obj.lb is not None:
            key = obj.lb.host + key

        key = hash(key)
        self._cache[key] = obj

    def delete(self, obj):
        key = obj.node.name + str(obj.port) + obj.pool.name
        if obj.lb is not None:
            key = obj.lb.host + key

        key = hash(key)
        if key in self._cache:
            del self._cache[key]

class PoolMember(object):
    __version = 11

    def __init__(self,
            node,
            port,
            pool,
            lb                  = None,
            availability_status = None,
            connection_limit    = None,
            description         = None,
            dynamic_ratio       = None,
            enabled             = None,
            priority            = None,
            rate_limit          = None,
            ratio               = None,
            status_description  = None):

        if lb is not None and not isinstance(lb, f5.Lb):
            raise ValueError('lb must be of type f5.Lb, not %s' % (type(lb).__name__))
{'fraction_non_alphanumeric': 0.09887827170751974, 'fraction_numerical': 0.0062318238471125885, 'mean_word_length': 1.6839464882943145, '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': '1309063', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1429, 'n_words': 387}