<commit_before>__all__ = [
    'HttpError',
    'Protocol',
    'Request',
    'Response',
]

import asyncio
import http
import logging
import traceback

from .http2 import Session
from .models import Request, Response


LOG = logging.getLogger(__name__)
LOG.addHandler(logging.NullHandler())


class HttpError(Exception):

    def __init__(self, status):
        super().__init__(status.name)
        self.status = status


class Protocol(asyncio.Protocol):

    def __init__(self, handler_factory, loop=None):
        super().__init__()
        self.handler_factory = handler_factory
        self.handler = None
        self.loop = loop

    def connection_made(self, transport):
        if LOG.isEnabledFor(logging.DEBUG):
            peername = transport.get_extra_info('peername')
            LOG.debug('accept %s:%d', peername[0], peername[1])
        self.handler = self.handler_factory()
        self.session = Session(self, transport)

    def data_received(self, data):
        self.session.data_received(data)

    def connection_lost(self, exc):
        if LOG.isEnabledFor(logging.DEBUG):
            if exc:
                tb_lines = traceback.format_exception(
                    exc.__class__, exc, exc.__traceback__)
                LOG.debug('close connection\n%s', ''.join(tb_lines))
            else:
                LOG.debug('close connection')
        self.session.close()
        self.handler = None

    # Called from http2.Session

    def handle_request(self, stream_id, request):
        for name, value in request.headers.items():
            if name.lower() == b'expect' and b'100-continue' in value.lower():
                LOG.debug('reject "expect: 100-continue"')
                response = Response()
                response.headers[b':status'] = (
                    b'%d' % http.HTTPStatus.EXPECTATION_FAILED.value)
                self.session.handle_response(stream_id, response)
                return
        LOG.debug('handle request of stream %d', stream_id)
        asyncio.ensure_future(self._handle(stream_id, request), loop=self.loop)

    async def _handle(self, stream_id, request):
        response = Response()<commit_msg>Shutdown connection on incompatible remote peer<commit_after>__all__ = [
    'HttpError',
    'Protocol',
    'Request',
    'Response',
]

import asyncio
import http
import logging
import traceback

from .http2 import Session
from .models import Request, Response


LOG = logging.getLogger(__name__)
LOG.addHandler(logging.NullHandler())


class HttpError(Exception):

    def __init__(self, status):
        super().__init__(status.name)
        self.status = status


class Protocol(asyncio.Protocol):

    def __init__(self, handler_factory, loop=None):
        super().__init__()
        self.handler_factory = handler_factory
        self.handler = None
        self.loop = loop

    def connection_made(self, transport):
        if LOG.isEnabledFor(logging.DEBUG):
            peername = transport.get_extra_info('peername')
            LOG.debug('accept %s:%d', peername[0], peername[1])
        self.transport = transport
        self.handler = self.handler_factory()
        self.session = Session(self, transport)

    def data_received(self, data):
        try:
            self.session.data_received(data)
        except:
            LOG.exception('error while receiving data')
            self.transport.close()

    def connection_lost(self, exc):
        if LOG.isEnabledFor(logging.DEBUG):
            if exc:
                tb_lines = traceback.format_exception(
                    exc.__class__, exc, exc.__traceback__)
                LOG.debug('close connection\n%s', ''.join(tb_lines))
            else:
                LOG.debug('close connection')
        self.session.close()
        self.handler = None

    # Called from http2.Session

    def handle_request(self, stream_id, request):
        for name, value in request.headers.items():
            if name.lower() == b'expect' and b'100-continue' in value.lower():
                LOG.debug('reject "expect: 100-continue"')
                response = Response()
                response.headers[b':status'] = (
                    b'%d' % http.HTTPStatus.EXPECTATION_FAILED.value)
                self.session.handle_response(stream_id, response)
                return
        LOG.debug('handle request of stream %d', stream_id)
        asyncio.ensure_future(self._handle(stream_id, request), loop=self.loop)

    async def _handle(self, stream_id, request):
        response = Response()
{'fraction_non_alphanumeric': 0.10930283703540797, 'fraction_numerical': 0.004398504508467121, 'mean_word_length': 2.404191616766467, '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': '4595402', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1230, 'n_words': 279}