<commit_before>import io
import uuid
import logging
import collections
import collections.abc
from concurrent.futures import Future

from . import protocol

from . import fsm

logger = logging.getLogger(__name__)


class Channel:

    Future = Future

    def __init__(self, channel_id, frame_max):
        self._channel_id = channel_id
        self._frame_max = frame_max

        self._buffer = io.BytesIO()
        # Future used to synchronise AMQP methods with OK replies
        self._fut = None
        self._method_handlers = self._setup_method_handlers()

        self._fsm = fsm.Channel()

        # protocol.Message is instantiated in _receive_BasicDeliver,
        # its delivery_info is set. Later, basic properties are set in
        # handle_frame: ContentHeaderFrame and body is updated in
        # handle_frame: ContentBodyFrame
        self._message = None
        self._message_fut = None

        # consumer_tag -> message_future mapping
        self._consumers = {}

        # Sequence number of next published message requiring confirmation.
        self._next_publish_seq_no = 0
        self._unconfirmed_set = set()
        self._ack_fut = self.Future()

        self.active = True

    def _setup_method_handlers(self):
        return {
            protocol.ChannelOpenOK: self._receive_ChannelOpenOK,
            protocol.ChannelClose: self._receive_ChannelClose,
            protocol.ChannelCloseOK: self._receive_ChannelCloseOK,
            protocol.ChannelFlow: self._receive_method,
            protocol.ChannelFlowOK: self._receive_ChannelFlowOK,

            protocol.ExchangeDeclareOK: self._receive_method,
            protocol.ExchangeBindOK: self._receive_method,
            protocol.ExchangeUnbindOK: self._receive_method,
            protocol.ExchangeDeleteOK: self._receive_method,

            protocol.QueueDeclareOK: self._receive_method,
            protocol.QueueBindOK: self._receive_method,
            protocol.QueueUnbindOK: self._receive_method,
            protocol.QueuePurgeOK: self._receive_method,
            protocol.QueueDeleteOK: self._receive_method,

            protocol.BasicConsumeOK: self._receive_BasicConsumeOK,
            protocol.BasicCancelOK: self._receive_method,
            protocol.BasicDeliver: self._receive_BasicDeliver,
            protocol.BasicGetOK: self._receive_BasicGetOK,
            protocol.BasicGetEmpty: self._receive_method,
            protocol.BasicAck: self._receive_BasicAck,
            protocol.BasicNack: self._receive_BasicNack,
            protocol.BasicQosOK: self._receive_method,
            protocol.BasicRecoverOK: self._receive_method,
            protocol.BasicReturn: self._receive_BasicReturn,
<commit_msg>Fix ChannelFlowOK handling<commit_after>import io
import uuid
import logging
import collections
import collections.abc
from concurrent.futures import Future

from . import protocol

from . import fsm

logger = logging.getLogger(__name__)


class Channel:

    Future = Future

    def __init__(self, channel_id, frame_max):
        self._channel_id = channel_id
        self._frame_max = frame_max

        self._buffer = io.BytesIO()
        # Future used to synchronise AMQP methods with OK replies
        self._fut = None
        self._method_handlers = self._setup_method_handlers()

        self._fsm = fsm.Channel()

        # protocol.Message is instantiated in _receive_BasicDeliver,
        # its delivery_info is set. Later, basic properties are set in
        # handle_frame: ContentHeaderFrame and body is updated in
        # handle_frame: ContentBodyFrame
        self._message = None
        self._message_fut = None

        # consumer_tag -> message_future mapping
        self._consumers = {}

        # Sequence number of next published message requiring confirmation.
        self._next_publish_seq_no = 0
        self._unconfirmed_set = set()
        self._ack_fut = self.Future()

        self.active = True

    def _setup_method_handlers(self):
        return {
            protocol.ChannelOpenOK: self._receive_ChannelOpenOK,
            protocol.ChannelClose: self._receive_ChannelClose,
            protocol.ChannelCloseOK: self._receive_ChannelCloseOK,
            protocol.ChannelFlow: self._receive_method,
            protocol.ChannelFlowOK: self._receive_method,

            protocol.ExchangeDeclareOK: self._receive_method,
            protocol.ExchangeBindOK: self._receive_method,
            protocol.ExchangeUnbindOK: self._receive_method,
            protocol.ExchangeDeleteOK: self._receive_method,

            protocol.QueueDeclareOK: self._receive_method,
            protocol.QueueBindOK: self._receive_method,
            protocol.QueueUnbindOK: self._receive_method,
            protocol.QueuePurgeOK: self._receive_method,
            protocol.QueueDeleteOK: self._receive_method,

            protocol.BasicConsumeOK: self._receive_BasicConsumeOK,
            protocol.BasicCancelOK: self._receive_method,
            protocol.BasicDeliver: self._receive_BasicDeliver,
            protocol.BasicGetOK: self._receive_BasicGetOK,
            protocol.BasicGetEmpty: self._receive_method,
            protocol.BasicAck: self._receive_BasicAck,
            protocol.BasicNack: self._receive_BasicNack,
            protocol.BasicQosOK: self._receive_method,
            protocol.BasicRecoverOK: self._receive_method,
            protocol.BasicReturn: self._receive_BasicReturn,

{'fraction_non_alphanumeric': 0.06472968002942259, 'fraction_numerical': 0.0003677822728944465, 'mean_word_length': 2.687457627118644, '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': '6394280', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1398, 'n_words': 302}