From 7fecd890282a5da87a3bc9b28a8bc684ebbd2025 Mon Sep 17 00:00:00 2001 From: fnk93 Date: Wed, 19 Mar 2025 20:53:38 +0100 Subject: [PATCH 1/5] chore: move dev dependencies to group and raise python version --- pyproject.toml | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 029a9c39..fce6b7cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,34 +4,30 @@ build-backend = "maturin" [project] name = "rnet" -requires-python = ">=3.7" +requires-python = ">=3.9" classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries :: Python Modules", - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: Unix', - 'Operating System :: MacOS', + "Programming Language :: Rust", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries :: Python Modules", + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: Unix', + 'Operating System :: MacOS', ] 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 +39,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"] From 67bd8a565602ddcc97a43c672f51e1046fdff971 Mon Sep 17 00:00:00 2001 From: fnk93 Date: Wed, 19 Mar 2025 20:55:32 +0100 Subject: [PATCH 2/5] fix: allow inheritance of Client and BlockingClient --- rnet.pyi | 1 + src/async_impl/client.rs | 1 + src/blocking/client.rs | 1 + tests/client_test.py | 29 ++++++++++++++++++++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/rnet.pyi b/rnet.pyi index 6bb33ea4..447dce1a 100644 --- a/rnet.pyi +++ b/rnet.pyi @@ -2058,6 +2058,7 @@ class Impersonate(Enum): SafariIPad18 = auto() Safari18_2 = auto() Safari18_3 = auto() + Safari18_3_1 = auto() SafariIos18_1_1 = auto() OkHttp3_9 = auto() OkHttp3_11 = auto() diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 26e08814..51bb831b 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -17,6 +17,7 @@ use std::{net::IpAddr, ops::Deref}; /// A client for making HTTP requests. #[gen_stub_pyclass] #[pyclass] +#[pyo3(subclass)] pub struct Client(rquest::Client); impl Deref for Client { diff --git a/src/blocking/client.rs b/src/blocking/client.rs index a909168f..067f45d1 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -10,6 +10,7 @@ use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods}; /// A blocking client for making HTTP requests. #[gen_stub_pyclass] #[pyclass] +#[pyo3(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 From e330cc398985ddfd05ca905d31c5aba6dd02db53 Mon Sep 17 00:00:00 2001 From: 0x676e67 Date: Thu, 20 Mar 2025 07:15:04 +0800 Subject: [PATCH 3/5] revert `raise python version` --- pyproject.toml | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fce6b7cd..54e5882f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,24 +4,26 @@ build-backend = "maturin" [project] name = "rnet" -requires-python = ">=3.9" +requires-python = ">=3.7" classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries :: Python Modules", - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: Unix', - 'Operating System :: MacOS', + "Programming Language :: Rust", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries :: Python Modules", + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: Unix', + 'Operating System :: MacOS', ] description = "A blazing-fast Python HTTP client with TLS fingerprint" readme = "README.md" From fb517f24f8f5c8ae20a235097ae031df4f820e1a Mon Sep 17 00:00:00 2001 From: 0x676e67 Date: Thu, 20 Mar 2025 07:16:04 +0800 Subject: [PATCH 4/5] Update client.rs --- src/blocking/client.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/blocking/client.rs b/src/blocking/client.rs index 067f45d1..c0c30358 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -9,8 +9,7 @@ use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods}; /// A blocking client for making HTTP requests. #[gen_stub_pyclass] -#[pyclass] -#[pyo3(subclass)] +#[pyclass(subclass)] pub struct BlockingClient(async_impl::Client); macro_rules! define_http_method { From dd6ccbac08d85a845569028a964d81e27f457af6 Mon Sep 17 00:00:00 2001 From: 0x676e67 Date: Thu, 20 Mar 2025 07:16:23 +0800 Subject: [PATCH 5/5] Update client.rs --- src/async_impl/client.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 51bb831b..fa0c650b 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -16,8 +16,7 @@ use std::{net::IpAddr, ops::Deref}; /// A client for making HTTP requests. #[gen_stub_pyclass] -#[pyclass] -#[pyo3(subclass)] +#[pyclass(subclass)] pub struct Client(rquest::Client); impl Deref for Client {