From b7eee50930dbd782d7c068d1d29cd270b97bc741 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 15 Mar 2024 14:55:53 +0100 Subject: Move raise_for_status, Create FormData wrapper --- g4f/requests/curl_cffi.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'g4f/requests/curl_cffi.py') diff --git a/g4f/requests/curl_cffi.py b/g4f/requests/curl_cffi.py index cfcdd63b..91142365 100644 --- a/g4f/requests/curl_cffi.py +++ b/g4f/requests/curl_cffi.py @@ -1,6 +1,6 @@ from __future__ import annotations -from curl_cffi.requests import AsyncSession, Response +from curl_cffi.requests import AsyncSession, Response, CurlMime from typing import AsyncGenerator, Any from functools import partialmethod import json @@ -65,6 +65,8 @@ class StreamSession(AsyncSession): def request( self, method: str, url: str, **kwargs ) -> StreamResponse: + if isinstance(kwargs.get("data"), CurlMime): + kwargs["multipart"] = kwargs.pop("data") """Create and return a StreamResponse object for the given HTTP request.""" return StreamResponse(super().request(method, url, stream=True, **kwargs)) @@ -75,3 +77,7 @@ class StreamSession(AsyncSession): put = partialmethod(request, "PUT") patch = partialmethod(request, "PATCH") delete = partialmethod(request, "DELETE") + +class FormData(CurlMime): + def add_field(self, name, data=None, content_type: str = None, filename: str = None) -> None: + self.addpart(name, content_type=content_type, filename=filename, data=data) \ No newline at end of file -- cgit v1.2.3