<commit_before># coding=utf-8
"""
Basic asyncio.Protocol interface for IRC connections
"""
import asyncio
import base64
import random
import ssl
from asyncio import Protocol
from collections import defaultdict
from enum import IntEnum, auto, unique
from itertools import cycle
from typing import Sequence, Optional, Tuple, Callable, Dict, Coroutine, AnyStr, TYPE_CHECKING

from asyncirc.irc import Message, CapList
from asyncirc.server import ConnectedServer
from asyncirc.util.backoff import AsyncDelayer

if TYPE_CHECKING:
    from logging import Logger
    from asyncirc.irc import Cap
    from asyncirc.server import Server
    from asyncio import AbstractEventLoop, Transport


@unique
class SASLMechanism(IntEnum):
    """Represents different SASL auth mechanisms"""
    NONE = auto()
    PLAIN = auto()
    EXTERNAL = auto()


async def _internal_ping(conn: 'IrcProtocol', message: 'Message'):
    conn.send("PONG {}".format(message.parameters))


async def _internal_cap_handler(conn: 'IrcProtocol', message: 'Message'):
    caplist = []
    if len(message.parameters) > 2:
        caplist = CapList.parse(message.parameters[-1])

    if message.parameters[1] == 'LS':
        for cap in caplist:
            if cap.name in conn.cap_handlers:
                conn.server.caps[cap.name] = (cap, None)

        if message.parameters[2] != '*':
            for cap in conn.server.caps:
                conn.send("CAP REQ :{}".format(cap))
            if not conn.server.caps:
                conn.send("CAP END")  # We haven't request any CAPs, send a CAP END to end negotiation

    elif message.parameters[1] in ('ACK', 'NAK'):
        enabled = message.parameters[1] == 'ACK'
        for cap in caplist:
            current = conn.server.caps[cap.name][0]
            conn.server.caps[cap.name] = (current, enabled)
            if enabled:
                handlers = filter(None, conn.cap_handlers[cap.name])
                await asyncio.gather(*[func(conn) for func in handlers])
        if all(val[1] is not None for val in conn.server.caps.values()):
            conn.send("CAP END")
    elif message.parameters[1] == 'LIST':
        if conn.logger:
            conn.logger.info("Current Capabilities: %s", caplist)
    elif message.parameters[1] == 'NEW':<commit_msg>Fixed parameter mismatch in cap handlers<commit_after># coding=utf-8
"""
Basic asyncio.Protocol interface for IRC connections
"""
import asyncio
import base64
import random
import ssl
from asyncio import Protocol
from collections import defaultdict
from enum import IntEnum, auto, unique
from itertools import cycle
from typing import Sequence, Optional, Tuple, Callable, Dict, Coroutine, AnyStr, TYPE_CHECKING

from asyncirc.irc import Message, CapList
from asyncirc.server import ConnectedServer
from asyncirc.util.backoff import AsyncDelayer

if TYPE_CHECKING:
    from logging import Logger
    from asyncirc.irc import Cap
    from asyncirc.server import Server
    from asyncio import AbstractEventLoop, Transport


@unique
class SASLMechanism(IntEnum):
    """Represents different SASL auth mechanisms"""
    NONE = auto()
    PLAIN = auto()
    EXTERNAL = auto()


async def _internal_ping(conn: 'IrcProtocol', message: 'Message'):
    conn.send("PONG {}".format(message.parameters))


async def _internal_cap_handler(conn: 'IrcProtocol', message: 'Message'):
    caplist = []
    if len(message.parameters) > 2:
        caplist = CapList.parse(message.parameters[-1])

    if message.parameters[1] == 'LS':
        for cap in caplist:
            if cap.name in conn.cap_handlers:
                conn.server.caps[cap.name] = (cap, None)

        if message.parameters[2] != '*':
            for cap in conn.server.caps:
                conn.send("CAP REQ :{}".format(cap))
            if not conn.server.caps:
                conn.send("CAP END")  # We haven't request any CAPs, send a CAP END to end negotiation

    elif message.parameters[1] in ('ACK', 'NAK'):
        enabled = message.parameters[1] == 'ACK'
        for cap in caplist:
            current = conn.server.caps[cap.name][0]
            conn.server.caps[cap.name] = (current, enabled)
            if enabled:
                handlers = filter(None, conn.cap_handlers[cap.name])
                await asyncio.gather(*[func(conn, cap) for func in handlers])
        if all(val[1] is not None for val in conn.server.caps.values()):
            conn.send("CAP END")
    elif message.parameters[1] == 'LIST':
        if conn.logger:
            conn.logger.info("Current Capabilities: %s", caplist)
    elif message.parameters[1] == 'NEW':
{'fraction_non_alphanumeric': 0.10823170731707317, 'fraction_numerical': 0.005662020905923345, 'mean_word_length': 2.969749351771824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1736086', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1315, 'n_words': 409}