diff --git a/pyproject.toml b/pyproject.toml index 029a9c39..54e5882f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,9 +29,7 @@ description = "A blazing-fast Python HTTP client with TLS fingerprint" readme = "README.md" dynamic = ["version"] license = { text = "GPL-3.0" } -authors = [ - { name = "0x676e67", email = "gngppz@gmail.com" } -] +authors = [{ name = "0x676e67", email = "gngppz@gmail.com" }] keywords = ["http", "client", "websocket", "ja3", "ja4"] [tool.maturin] @@ -43,7 +41,5 @@ Documentation = "https://github.com/0x676e67/rnet/blob/main/rnet.pyi" Homepage = "https://github.com/0x676e67/rnet" Repository = "https://github.com/0x676e67/rnet" -[tool.poetry.dev-dependencies] -pytest = "^8.3.4" -pytest-asyncio = "^0.25.3" -pytest-rerunfailures = "^15.0" \ No newline at end of file +[dependency-groups] +dev = ["pytest>=8.3.4", "pytest-asyncio>=0.25.3", "pytest-rerunfailures>=15.0"] diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 26e08814..fa0c650b 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -16,7 +16,7 @@ use std::{net::IpAddr, ops::Deref}; /// A client for making HTTP requests. #[gen_stub_pyclass] -#[pyclass] +#[pyclass(subclass)] pub struct Client(rquest::Client); impl Deref for Client { diff --git a/src/blocking/client.rs b/src/blocking/client.rs index a909168f..c0c30358 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -9,7 +9,7 @@ use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods}; /// A blocking client for making HTTP requests. #[gen_stub_pyclass] -#[pyclass] +#[pyclass(subclass)] pub struct BlockingClient(async_impl::Client); macro_rules! define_http_method { diff --git a/tests/client_test.py b/tests/client_test.py index 96f0bf7b..97c482ab 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -1,6 +1,33 @@ import pytest import rnet -from rnet import Impersonate, ImpersonateOS, Cookie +from rnet import Cookie, Impersonate, ImpersonateOS + + +@pytest.mark.asyncio +@pytest.mark.flaky(reruns=1, reruns_delay=2) +async def test_inherit_client(): + class SubClient(rnet.Client): + def __init__(self, **kwargs): + self.test_var = "test" + self.cookie_jar = None + + client = SubClient(impersonate=Impersonate.Chrome133) + url = "https://google.com" + response = await client.get(url) + text = await response.text() + assert text is not None + assert client.cookie_jar is None + assert client.test_var == "test" + client.update( + impersonate=Impersonate.Firefox135, + impersonate_os=ImpersonateOS.Windows, + Impersonate_skip_headers=False, + ) + assert ( + client.user_agent + == "Mozilla/5.0 (Windows NT 10.0; rv:135.0) Gecko/20100101 Firefox/135.0" + ) + assert client.test_var == "test" @pytest.mark.asyncio