<commit_before>import asyncio
import functools
import logging
import typing
from concurrent.futures import ThreadPoolExecutor
from urllib.parse import urlunparse

from aiohttp import web
from spyne import Application
from spyne.application import get_fault_string_from_exception
from spyne.interface import AllYourInterfaceDocuments
from spyne.auxproc import process_contexts
from spyne.model.fault import Fault
from spyne.protocol.http import HttpRpc
from spyne.server import ServerBase

from .aio_method_ctx import AioMethodContext

logger = logging.getLogger(__name__)


class AioBase(ServerBase):
    transport = "http://schemas.xmlsoap.org/soap/http"

    def __init__(
        self,
        app: Application,
        chunked: bool = False,
        cache_wsdl: bool = True,
        threads: typing.Optional[int] = None,
    ) -> None:
        super(AioBase, self).__init__(app)
        self._chunked: bool = chunked
        self._cache_wsdl: bool = cache_wsdl
        self._wsdl: typing.Optional[bytes] = None
        self._thread_pool: typing.Optional[ThreadPoolExecutor] = None
        if threads:
            self._thread_pool = ThreadPoolExecutor(max_workers=threads)

    @staticmethod
    async def make_streaming_response(
        req: web.Request,
        status: int,
        content: typing.Iterable[bytes],
        chunked: bool = False,
        headers: typing.Optional[dict] = None,
    ) -> web.StreamResponse:
        response = web.StreamResponse(status=status, headers=headers)

        # If chunked encoding is requested, then enable it and leave content-length unset
        # If we're not using chunked, set the content-length by summing size of all content blocks
        if chunked:
            response.enable_chunked_encoding()
        else:
            response.content_length = sum([len(c) for c in content])
<commit_msg>Drop unnecessary list conversion from content_length calculation<commit_after>import asyncio
import functools
import logging
import typing
from concurrent.futures import ThreadPoolExecutor
from urllib.parse import urlunparse

from aiohttp import web
from spyne import Application
from spyne.application import get_fault_string_from_exception
from spyne.interface import AllYourInterfaceDocuments
from spyne.auxproc import process_contexts
from spyne.model.fault import Fault
from spyne.protocol.http import HttpRpc
from spyne.server import ServerBase

from .aio_method_ctx import AioMethodContext

logger = logging.getLogger(__name__)


class AioBase(ServerBase):
    transport = "http://schemas.xmlsoap.org/soap/http"

    def __init__(
        self,
        app: Application,
        chunked: bool = False,
        cache_wsdl: bool = True,
        threads: typing.Optional[int] = None,
    ) -> None:
        super(AioBase, self).__init__(app)
        self._chunked: bool = chunked
        self._cache_wsdl: bool = cache_wsdl
        self._wsdl: typing.Optional[bytes] = None
        self._thread_pool: typing.Optional[ThreadPoolExecutor] = None
        if threads:
            self._thread_pool = ThreadPoolExecutor(max_workers=threads)

    @staticmethod
    async def make_streaming_response(
        req: web.Request,
        status: int,
        content: typing.Iterable[bytes],
        chunked: bool = False,
        headers: typing.Optional[dict] = None,
    ) -> web.StreamResponse:
        response = web.StreamResponse(status=status, headers=headers)

        # If chunked encoding is requested, then enable it and leave content-length unset
        # If we're not using chunked, set the content-length by summing size of all content blocks
        if chunked:
            response.enable_chunked_encoding()
        else:
            response.content_length = sum(len(c) for c in content)

{'fraction_non_alphanumeric': 0.07087663202771116, 'fraction_numerical': 0.0, 'mean_word_length': 3.21324354657688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5184076', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1024, 'n_words': 302}