Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
aiohttp.py63 linesDownload Raw Back to pipeline
1# --------------------------------------------------------------------------2#3# Copyright (c) Microsoft Corporation. All rights reserved.4#5# The MIT License (MIT)6#7# Permission is hereby granted, free of charge, to any person obtaining a copy8# of this software and associated documentation files (the ""Software""), to9# deal in the Software without restriction, including without limitation the10# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or11# sell copies of the Software, and to permit persons to whom the Software is12# furnished to do so, subject to the following conditions:13#14# The above copyright notice and this permission notice shall be included in15# all copies or substantial portions of the Software.16#17# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING22# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS23# IN THE SOFTWARE.24#25# --------------------------------------------------------------------------26from typing import Any, Optional27 28from ..universal_http.aiohttp import AioHTTPSender as _AioHTTPSenderDriver29from . import AsyncHTTPSender, Request, Response30 31# Matching requests, because why not?32CONTENT_CHUNK_SIZE = 10 * 102433 34class AioHTTPSender(AsyncHTTPSender):35    """AioHttp HTTP sender implementation.36    """37 38    def __init__(self, driver: Optional[_AioHTTPSenderDriver] = None, *, loop=None) -> None:39        self.driver = driver or _AioHTTPSenderDriver(loop=loop)40 41    async def __aenter__(self):42        await self.driver.__aenter__()43 44    async def __aexit__(self, *exc_details):  # pylint: disable=arguments-differ45        await self.driver.__aexit__(*exc_details)46 47    def build_context(self) -> Any:48        """Allow the sender to build a context that will be passed49        across the pipeline with the request.50 51        Return type has no constraints. Implementation is not52        required and None by default.53        """54        return None55 56    async def send(self, request: Request, **config: Any) -> Response:57        """Send the request using this HTTP sender.58        """59        return Response(60            request,61            await self.driver.send(request.http_request)62        )63 
codekingpro/portable-devtools · Team Ai