From 98895e5b09ea5e3f19b2263ddca028c7b296abb2 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 1 Oct 2023 06:38:11 +0200 Subject: Update HuggingChat to new api Impersonate Aivvm Provider Add ChatForAi and FreeGpt Provider Update AItianhuSpace Provider Improve StreamRequest Support Update get_event_loop Helper --- g4f/requests.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 736442e3..f6f2383b 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -1,6 +1,6 @@ from __future__ import annotations -import json, sys +import json, sys, asyncio from functools import partialmethod from aiohttp import StreamReader @@ -8,6 +8,9 @@ from aiohttp.base_protocol import BaseProtocol from curl_cffi.requests import AsyncSession as BaseSession from curl_cffi.requests import Response +from curl_cffi import AsyncCurl + +is_newer_0_5_9 = hasattr(AsyncCurl, "remove_handle") class StreamResponse: @@ -35,7 +38,7 @@ class StreamResponse: class StreamRequest: def __init__(self, session: AsyncSession, method: str, url: str, **kwargs): self.session = session - self.loop = session.loop + self.loop = session.loop if session.loop else asyncio.get_running_loop() self.content = StreamReader( BaseProtocol(session.loop), sys.maxsize, @@ -51,10 +54,9 @@ class StreamRequest: self.content.feed_data(data) def on_done(self, task): + if not self.enter.done(): + self.enter.set_result(None) self.content.feed_eof() - self.curl.clean_after_perform() - self.curl.reset() - self.session.push_curl(self.curl) async def __aenter__(self) -> StreamResponse: self.curl = await self.session.pop_curl() @@ -66,18 +68,30 @@ class StreamRequest: content_callback=self.on_content, **self.options ) - await self.session.acurl.add_handle(self.curl, False) - self.handle = self.session.acurl._curl2future[self.curl] + if is_newer_0_5_9: + self.handle = self.session.acurl.add_handle(self.curl) + else: + await self.session.acurl.add_handle(self.curl, False) + self.handle = self.session.acurl._curl2future[self.curl] self.handle.add_done_callback(self.on_done) await self.enter + if is_newer_0_5_9: + response = self.session._parse_response(self.curl, _, header_buffer) + response.request = request + else: + response = self.session._parse_response(self.curl, request, _, header_buffer) return StreamResponse( - self.session._parse_response(self.curl, request, _, header_buffer), + response, self.content, request ) async def __aexit__(self, exc_type, exc, tb): - pass + if not self.handle.done(): + self.session.acurl.set_result(self.curl) + self.curl.clean_after_perform() + self.curl.reset() + self.session.push_curl(self.curl) class AsyncSession(BaseSession): def request( -- cgit v1.2.3 From bb481a03ab1a64e47731eb28e461e1dc1d655383 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 1 Oct 2023 10:36:09 +0200 Subject: Disable Wewordle Provider Update Ylokh Provider Improve StreamRequest --- g4f/requests.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index f6f2383b..6f4b587c 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -11,7 +11,7 @@ from curl_cffi.requests import Response from curl_cffi import AsyncCurl is_newer_0_5_9 = hasattr(AsyncCurl, "remove_handle") - +is_newer_0_5_8 = hasattr(BaseSession, "_set_cookies") class StreamResponse: def __init__(self, inner: Response, content: StreamReader, request): @@ -46,6 +46,10 @@ class StreamRequest: ) self.method = method self.url = url + if "proxy" in kwargs: + proxy = kwargs.pop("proxy") + if proxy: + kwargs["proxies"] = {"http": proxy, "https": proxy} self.options = kwargs def on_content(self, data): @@ -75,7 +79,7 @@ class StreamRequest: self.handle = self.session.acurl._curl2future[self.curl] self.handle.add_done_callback(self.on_done) await self.enter - if is_newer_0_5_9: + if is_newer_0_5_8: response = self.session._parse_response(self.curl, _, header_buffer) response.request = request else: @@ -91,7 +95,7 @@ class StreamRequest: self.session.acurl.set_result(self.curl) self.curl.clean_after_perform() self.curl.reset() - self.session.push_curl(self.curl) + self.session.push_curl(self.curl) class AsyncSession(BaseSession): def request( -- cgit v1.2.3 From 7b9ad21de81cd5129b047d8de3ce8d9e5a53ea9a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 1 Oct 2023 20:29:57 +0200 Subject: Change event loop policy on windows Support more versions from curl_cffi --- g4f/requests.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 6f4b587c..367bafa0 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -8,10 +8,12 @@ from aiohttp.base_protocol import BaseProtocol from curl_cffi.requests import AsyncSession as BaseSession from curl_cffi.requests import Response -from curl_cffi import AsyncCurl -is_newer_0_5_9 = hasattr(AsyncCurl, "remove_handle") -is_newer_0_5_8 = hasattr(BaseSession, "_set_cookies") +import curl_cffi + +is_newer_0_5_8 = hasattr(BaseSession, "_set_cookies") or hasattr(curl_cffi.requests.Cookies, "get_cookies_for_curl") +is_newer_0_5_9 = hasattr(curl_cffi.AsyncCurl, "remove_handle") +is_newer_0_5_10 = hasattr(BaseSession, "release_curl") class StreamResponse: def __init__(self, inner: Response, content: StreamReader, request): @@ -65,13 +67,22 @@ class StreamRequest: async def __aenter__(self) -> StreamResponse: self.curl = await self.session.pop_curl() self.enter = self.loop.create_future() - request, _, header_buffer = self.session._set_curl_options( - self.curl, - self.method, - self.url, - content_callback=self.on_content, - **self.options - ) + if is_newer_0_5_10: + request, _, header_buffer, _, _ = self.session._set_curl_options( + self.curl, + self.method, + self.url, + content_callback=self.on_content, + **self.options + ) + else: + request, _, header_buffer = self.session._set_curl_options( + self.curl, + self.method, + self.url, + content_callback=self.on_content, + **self.options + ) if is_newer_0_5_9: self.handle = self.session.acurl.add_handle(self.curl) else: -- cgit v1.2.3 From eb0e2c6a93c3f21937457d13220ce2b7fca1f04a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 2 Oct 2023 02:04:22 +0200 Subject: +Curl +Async +Stream Requests Update Model List --- g4f/requests.py | 121 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 41 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 367bafa0..78acb9de 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -1,25 +1,24 @@ from __future__ import annotations -import json, sys, asyncio -from functools import partialmethod +import warnings, json, asyncio -from aiohttp import StreamReader -from aiohttp.base_protocol import BaseProtocol +from functools import partialmethod +from asyncio import Future, Queue +from typing import AsyncGenerator -from curl_cffi.requests import AsyncSession as BaseSession -from curl_cffi.requests import Response +from curl_cffi.requests import AsyncSession, Response import curl_cffi -is_newer_0_5_8 = hasattr(BaseSession, "_set_cookies") or hasattr(curl_cffi.requests.Cookies, "get_cookies_for_curl") +is_newer_0_5_8 = hasattr(AsyncSession, "_set_cookies") or hasattr(curl_cffi.requests.Cookies, "get_cookies_for_curl") is_newer_0_5_9 = hasattr(curl_cffi.AsyncCurl, "remove_handle") -is_newer_0_5_10 = hasattr(BaseSession, "release_curl") +is_newer_0_5_10 = hasattr(AsyncSession, "release_curl") class StreamResponse: - def __init__(self, inner: Response, content: StreamReader, request): + def __init__(self, inner: Response, queue: Queue): self.inner = inner - self.content = content - self.request = request + self.queue = queue + self.request = inner.request self.status_code = inner.status_code self.reason = inner.reason self.ok = inner.ok @@ -27,7 +26,7 @@ class StreamResponse: self.cookies = inner.cookies async def text(self) -> str: - content = await self.content.read() + content = await self.read() return content.decode() def raise_for_status(self): @@ -35,36 +34,74 @@ class StreamResponse: raise RuntimeError(f"HTTP Error {self.status_code}: {self.reason}") async def json(self, **kwargs): - return json.loads(await self.content.read(), **kwargs) + return json.loads(await self.read(), **kwargs) + + async def iter_lines(self, chunk_size=None, decode_unicode=False, delimiter=None) -> AsyncGenerator[bytes]: + """ + Copied from: https://requests.readthedocs.io/en/latest/_modules/requests/models/ + which is under the License: Apache 2.0 + """ + pending = None + + async for chunk in self.iter_content( + chunk_size=chunk_size, decode_unicode=decode_unicode + ): + if pending is not None: + chunk = pending + chunk + if delimiter: + lines = chunk.split(delimiter) + else: + lines = chunk.splitlines() + if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]: + pending = lines.pop() + else: + pending = None + + for line in lines: + yield line + + if pending is not None: + yield pending + + async def iter_content(self, chunk_size=None, decode_unicode=False) -> As: + if chunk_size: + warnings.warn("chunk_size is ignored, there is no way to tell curl that.") + if decode_unicode: + raise NotImplementedError() + while True: + chunk = await self.queue.get() + if chunk is None: + return + yield chunk + + async def read(self) -> bytes: + return b"".join([chunk async for chunk in self.iter_content()]) class StreamRequest: def __init__(self, session: AsyncSession, method: str, url: str, **kwargs): self.session = session self.loop = session.loop if session.loop else asyncio.get_running_loop() - self.content = StreamReader( - BaseProtocol(session.loop), - sys.maxsize, - loop=session.loop - ) + self.queue = Queue() self.method = method self.url = url - if "proxy" in kwargs: - proxy = kwargs.pop("proxy") - if proxy: - kwargs["proxies"] = {"http": proxy, "https": proxy} self.options = kwargs + self.handle = None - def on_content(self, data): + def _on_content(self, data): if not self.enter.done(): self.enter.set_result(None) - self.content.feed_data(data) + self.queue.put_nowait(data) - def on_done(self, task): + def _on_done(self, task: Future): if not self.enter.done(): self.enter.set_result(None) - self.content.feed_eof() + self.queue.put_nowait(None) - async def __aenter__(self) -> StreamResponse: + self.loop.call_soon(self.session.release_curl, self.curl) + + async def fetch(self) -> StreamResponse: + if self.handle: + raise RuntimeError("Request already started") self.curl = await self.session.pop_curl() self.enter = self.loop.create_future() if is_newer_0_5_10: @@ -72,7 +109,7 @@ class StreamRequest: self.curl, self.method, self.url, - content_callback=self.on_content, + content_callback=self._on_content, **self.options ) else: @@ -80,7 +117,7 @@ class StreamRequest: self.curl, self.method, self.url, - content_callback=self.on_content, + content_callback=self._on_content, **self.options ) if is_newer_0_5_9: @@ -88,8 +125,12 @@ class StreamRequest: else: await self.session.acurl.add_handle(self.curl, False) self.handle = self.session.acurl._curl2future[self.curl] - self.handle.add_done_callback(self.on_done) + self.handle.add_done_callback(self._on_done) + # Wait for headers await self.enter + # Raise exceptions + if self.handle.done(): + self.handle.result() if is_newer_0_5_8: response = self.session._parse_response(self.curl, _, header_buffer) response.request = request @@ -97,18 +138,16 @@ class StreamRequest: response = self.session._parse_response(self.curl, request, _, header_buffer) return StreamResponse( response, - self.content, - request + self.queue ) - - async def __aexit__(self, exc_type, exc, tb): - if not self.handle.done(): - self.session.acurl.set_result(self.curl) - self.curl.clean_after_perform() - self.curl.reset() - self.session.push_curl(self.curl) - -class AsyncSession(BaseSession): + + async def __aenter__(self) -> StreamResponse: + return await self.fetch() + + async def __aexit__(self, *args): + self.session.release_curl(self.curl) + +class StreamSession(AsyncSession): def request( self, method: str, -- cgit v1.2.3 From 5fcf9434f49d224b4264a88eb7162f557f566e71 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:27:33 +0200 Subject: ~ | quick fix --- g4f/requests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 78acb9de..4146341e 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -145,7 +145,8 @@ class StreamRequest: return await self.fetch() async def __aexit__(self, *args): - self.session.release_curl(self.curl) + return + #self.session.release_curl(self.curl) class StreamSession(AsyncSession): def request( -- cgit v1.2.3 From a4da030d67bc1bd0affd1cd094291bb398126f36 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:31:28 +0200 Subject: ~ | g4f v-0.1.4.4 release_curl bug --- g4f/requests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 4146341e..5dd2f56e 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -97,7 +97,8 @@ class StreamRequest: self.enter.set_result(None) self.queue.put_nowait(None) - self.loop.call_soon(self.session.release_curl, self.curl) + #self.loop.call_soon(self.session.rel, self.curl) + return async def fetch(self) -> StreamResponse: if self.handle: -- cgit v1.2.3 From ff4d9ae584cd3e9eefee6642c2a5290b63351b0a Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 2 Oct 2023 17:01:15 +0200 Subject: Add Phind Provider Add release_curl in url_cffi requets Support create image response in Bing --- g4f/requests.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 5dd2f56e..c51d9804 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -97,8 +97,7 @@ class StreamRequest: self.enter.set_result(None) self.queue.put_nowait(None) - #self.loop.call_soon(self.session.rel, self.curl) - return + self.loop.call_soon(self.release_curl) async def fetch(self) -> StreamResponse: if self.handle: @@ -146,8 +145,22 @@ class StreamRequest: return await self.fetch() async def __aexit__(self, *args): - return - #self.session.release_curl(self.curl) + self.release_curl() + + def release_curl(self): + if is_newer_0_5_10: + self.session.release_curl(self.curl) + return + if not self.curl: + return + self.curl.clean_after_perform() + if is_newer_0_5_9: + self.session.acurl.remove_handle(self.curl) + elif not self.handle.done() and not self.handle.cancelled(): + self.session.acurl.set_result(self.curl) + self.curl.reset() + self.session.push_curl(self.curl) + self.curl = None class StreamSession(AsyncSession): def request( -- cgit v1.2.3 From f7bb30036e5e5482611627a040f54254ac162f72 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 7 Oct 2023 10:17:43 +0200 Subject: Improve code by AI --- g4f/requests.py | 81 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index c51d9804..3a4a3f54 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -1,47 +1,44 @@ from __future__ import annotations -import warnings, json, asyncio - +import warnings +import json +import asyncio from functools import partialmethod from asyncio import Future, Queue from typing import AsyncGenerator from curl_cffi.requests import AsyncSession, Response - import curl_cffi -is_newer_0_5_8 = hasattr(AsyncSession, "_set_cookies") or hasattr(curl_cffi.requests.Cookies, "get_cookies_for_curl") -is_newer_0_5_9 = hasattr(curl_cffi.AsyncCurl, "remove_handle") -is_newer_0_5_10 = hasattr(AsyncSession, "release_curl") +is_newer_0_5_8: bool = hasattr(AsyncSession, "_set_cookies") or hasattr(curl_cffi.requests.Cookies, "get_cookies_for_curl") +is_newer_0_5_9: bool = hasattr(curl_cffi.AsyncCurl, "remove_handle") +is_newer_0_5_10: bool = hasattr(AsyncSession, "release_curl") + class StreamResponse: - def __init__(self, inner: Response, queue: Queue): - self.inner = inner - self.queue = queue + def __init__(self, inner: Response, queue: Queue[bytes]) -> None: + self.inner: Response = inner + self.queue: Queue[bytes] = queue self.request = inner.request - self.status_code = inner.status_code - self.reason = inner.reason - self.ok = inner.ok + self.status_code: int = inner.status_code + self.reason: str = inner.reason + self.ok: bool = inner.ok self.headers = inner.headers self.cookies = inner.cookies async def text(self) -> str: - content = await self.read() + content: bytes = await self.read() return content.decode() - def raise_for_status(self): + def raise_for_status(self) -> None: if not self.ok: raise RuntimeError(f"HTTP Error {self.status_code}: {self.reason}") - async def json(self, **kwargs): + async def json(self, **kwargs) -> dict: return json.loads(await self.read(), **kwargs) - - async def iter_lines(self, chunk_size=None, decode_unicode=False, delimiter=None) -> AsyncGenerator[bytes]: - """ - Copied from: https://requests.readthedocs.io/en/latest/_modules/requests/models/ - which is under the License: Apache 2.0 - """ - pending = None + + async def iter_lines(self, chunk_size=None, decode_unicode=False, delimiter=None) -> AsyncGenerator[bytes, None]: + pending: bytes = None async for chunk in self.iter_content( chunk_size=chunk_size, decode_unicode=decode_unicode @@ -63,7 +60,7 @@ class StreamResponse: if pending is not None: yield pending - async def iter_content(self, chunk_size=None, decode_unicode=False) -> As: + async def iter_content(self, chunk_size=None, decode_unicode=False) -> AsyncGenerator[bytes, None]: if chunk_size: warnings.warn("chunk_size is ignored, there is no way to tell curl that.") if decode_unicode: @@ -77,22 +74,23 @@ class StreamResponse: async def read(self) -> bytes: return b"".join([chunk async for chunk in self.iter_content()]) + class StreamRequest: - def __init__(self, session: AsyncSession, method: str, url: str, **kwargs): - self.session = session - self.loop = session.loop if session.loop else asyncio.get_running_loop() - self.queue = Queue() - self.method = method - self.url = url - self.options = kwargs - self.handle = None - - def _on_content(self, data): + def __init__(self, session: AsyncSession, method: str, url: str, **kwargs) -> None: + self.session: AsyncSession = session + self.loop: asyncio.AbstractEventLoop = session.loop if session.loop else asyncio.get_running_loop() + self.queue: Queue[bytes] = Queue() + self.method: str = method + self.url: str = url + self.options: dict = kwargs + self.handle: curl_cffi.AsyncCurl = None + + def _on_content(self, data: bytes) -> None: if not self.enter.done(): self.enter.set_result(None) self.queue.put_nowait(data) - def _on_done(self, task: Future): + def _on_done(self, task: Future) -> None: if not self.enter.done(): self.enter.set_result(None) self.queue.put_nowait(None) @@ -102,8 +100,8 @@ class StreamRequest: async def fetch(self) -> StreamResponse: if self.handle: raise RuntimeError("Request already started") - self.curl = await self.session.pop_curl() - self.enter = self.loop.create_future() + self.curl: curl_cffi.AsyncCurl = await self.session.pop_curl() + self.enter: asyncio.Future = self.loop.create_future() if is_newer_0_5_10: request, _, header_buffer, _, _ = self.session._set_curl_options( self.curl, @@ -121,7 +119,7 @@ class StreamRequest: **self.options ) if is_newer_0_5_9: - self.handle = self.session.acurl.add_handle(self.curl) + self.handle = self.session.acurl.add_handle(self.curl) else: await self.session.acurl.add_handle(self.curl, False) self.handle = self.session.acurl._curl2future[self.curl] @@ -140,14 +138,14 @@ class StreamRequest: response, self.queue ) - + async def __aenter__(self) -> StreamResponse: return await self.fetch() - async def __aexit__(self, *args): + async def __aexit__(self, *args) -> None: self.release_curl() - def release_curl(self): + def release_curl(self) -> None: if is_newer_0_5_10: self.session.release_curl(self.curl) return @@ -162,6 +160,7 @@ class StreamRequest: self.session.push_curl(self.curl) self.curl = None + class StreamSession(AsyncSession): def request( self, @@ -170,7 +169,7 @@ class StreamSession(AsyncSession): **kwargs ) -> StreamRequest: return StreamRequest(self, method, url, **kwargs) - + head = partialmethod(request, "HEAD") get = partialmethod(request, "GET") post = partialmethod(request, "POST") -- cgit v1.2.3 From dfdb759639479da640701fe0db716d4455b7ae38 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 7 Oct 2023 19:00:45 +0200 Subject: Improve code with ai --- g4f/requests.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'g4f/requests.py') diff --git a/g4f/requests.py b/g4f/requests.py index 3a4a3f54..f238062e 100644 --- a/g4f/requests.py +++ b/g4f/requests.py @@ -5,7 +5,7 @@ import json import asyncio from functools import partialmethod from asyncio import Future, Queue -from typing import AsyncGenerator +from typing import AsyncGenerator, Union, Optional from curl_cffi.requests import AsyncSession, Response import curl_cffi @@ -37,7 +37,14 @@ class StreamResponse: async def json(self, **kwargs) -> dict: return json.loads(await self.read(), **kwargs) - async def iter_lines(self, chunk_size=None, decode_unicode=False, delimiter=None) -> AsyncGenerator[bytes, None]: + async def iter_lines( + self, chunk_size: Optional[int] = None, decode_unicode: bool = False, delimiter: Optional[str] = None + ) -> AsyncGenerator[bytes, None]: + """ + Copied from: https://requests.readthedocs.io/en/latest/_modules/requests/models/ + which is under the License: Apache 2.0 + """ + pending: bytes = None async for chunk in self.iter_content( @@ -60,7 +67,9 @@ class StreamResponse: if pending is not None: yield pending - async def iter_content(self, chunk_size=None, decode_unicode=False) -> AsyncGenerator[bytes, None]: + async def iter_content( + self, chunk_size: Optional[int] = None, decode_unicode: bool = False + ) -> AsyncGenerator[bytes, None]: if chunk_size: warnings.warn("chunk_size is ignored, there is no way to tell curl that.") if decode_unicode: @@ -76,14 +85,14 @@ class StreamResponse: class StreamRequest: - def __init__(self, session: AsyncSession, method: str, url: str, **kwargs) -> None: + def __init__(self, session: AsyncSession, method: str, url: str, **kwargs: Union[bool, int, str]) -> None: self.session: AsyncSession = session self.loop: asyncio.AbstractEventLoop = session.loop if session.loop else asyncio.get_running_loop() self.queue: Queue[bytes] = Queue() self.method: str = method self.url: str = url self.options: dict = kwargs - self.handle: curl_cffi.AsyncCurl = None + self.handle: Optional[curl_cffi.AsyncCurl] = None def _on_content(self, data: bytes) -> None: if not self.enter.done(): @@ -134,10 +143,7 @@ class StreamRequest: response.request = request else: response = self.session._parse_response(self.curl, request, _, header_buffer) - return StreamResponse( - response, - self.queue - ) + return StreamResponse(response, self.queue) async def __aenter__(self) -> StreamResponse: return await self.fetch() @@ -163,10 +169,7 @@ class StreamRequest: class StreamSession(AsyncSession): def request( - self, - method: str, - url: str, - **kwargs + self, method: str, url: str, **kwargs ) -> StreamRequest: return StreamRequest(self, method, url, **kwargs) -- cgit v1.2.3