<commit_before>#!/usr/bin/env python3
# Written by <NAME> <<EMAIL>>
# Released under the ISC license
from .utils import CaseInsensitiveDict, CaseInsensitiveList


def cap_list(caps):
    """Given a cap string, return a list of cap, value."""
    out = []
    caps = caps.split()

    for cap in caps:
        # strip first initial =/~
        if cap.startswith('=') or cap.startswith('~'):
            cap = cap[1:]

        if '=' in cap:
            cap, value = cap.rsplit('=', 1)
        else:
            value = True

        out.append([cap, value])

    return out


class Capabilities:
    """Ingests sets of client capabilities and provides access to them."""

    def __init__(self, wanted=[]):
        self.available = CaseInsensitiveDict()
        self.wanted = CaseInsensitiveList(wanted)
        self.enabled = CaseInsensitiveList()

    def ingest(self, cmd, parameters):
        cmd = cmd.casefold()

        if cmd == 'ls':
            for cap, value in cap_list(parameters[0]):
                self.available[cap] = value

        elif cmd == 'ack':
            for cap, value in cap_list(parameters[0]):
                if cap not in self.enabled:
                    self.enabled.append(cap)

        elif cmd == 'nak':
            for cap, value in cap_list(parameters[0]):
                if cap in self.enabled:
                    self.enabled.remove(cap)

    @property
    def to_enable(self):
        l = []

        for cap in self.wanted:
            if cap in self.available and cap not in self.enabled:<commit_msg>caps: Split out modifier characters into named modifiers<commit_after>#!/usr/bin/env python3
# Written by <NAME> <<EMAIL>>
# Released under the ISC license
from .utils import CaseInsensitiveDict, CaseInsensitiveList

cap_modifiers = {
    '-': 'disabled',
    '~': 'sticky',  # deprecated
    '=': 'ack-required',  # deprecated
}


def cap_list(caps):
    """Given a cap string, return a list of cap, value."""
    out = []
    caps = caps.split()

    for cap in caps:
        # turn modifier chars into named modifiers
        mods = []

        while len(cap) > 0 and cap[0] in cap_modifiers:
            attr = cap[0]
            cap = cap[1:]

            mods.append(cap_modifiers[attr])

        # either give string value or True if not specified
        if '=' in cap:
            cap, value = cap.rsplit('=', 1)
        else:
            value = True

        out.append([cap, value, mods])

    return out


class Capabilities:
    """Ingests sets of client capabilities and provides access to them."""

    def __init__(self, wanted=[]):
        self.available = CaseInsensitiveDict()
        self.wanted = CaseInsensitiveList(wanted)
        self.enabled = CaseInsensitiveList()

    def ingest(self, cmd, parameters):
        cmd = cmd.casefold()

        if cmd == 'ls':
            for cap, value, mods in cap_list(parameters[0]):
                self.available[cap] = (value, mods)

        elif cmd == 'ack':
            for cap, value, mods in cap_list(parameters[0]):
                if cap not in self.enabled:
                    self.enabled.append(cap)

        elif cmd == 'nak':
            for cap, value, mods in cap_list(parameters[0]):
                if cap in self.enabled:
                    self.enabled.remove(cap)

    @property
    def to_enable(self):
        l = []

        for cap in self.wanted:
            if cap in self.available and cap not in self.enabled:
{'fraction_non_alphanumeric': 0.11333333333333333, 'fraction_numerical': 0.004347826086956522, 'mean_word_length': 1.9878787878787878, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '72912', 'n_tokens_mistral': 1037, 'n_tokens_neox': 967, 'n_words': 314}