Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/rnet/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,10 @@ class WebSocketRequest(TypedDict):
The basic authentication to use for the request.
"""

query: NotRequired[Sequence[Tuple[str, str]]]
query: NotRequired[
Sequence[Tuple[str, str | int | float | bool]]
| Dict[str, str | int | float | bool]
]
"""
The query parameters to use for the request.
"""
Expand Down
9 changes: 2 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct Builder {
/// The proxy to use for the client.
proxies: Option<Extractor<Vec<Proxy>>>,
/// Bind to a local IP Address.
local_address: Option<Extractor<IpAddr>>,
local_address: Option<IpAddr>,
/// Bind to an interface by `SO_BINDTODEVICE`.
interface: Option<String>,

Expand Down Expand Up @@ -432,12 +432,7 @@ impl Client {
}
}
apply_option!(set_if_true, builder, params.no_proxy, no_proxy, false);
apply_option!(
set_if_some_inner,
builder,
params.local_address,
local_address
);
apply_option!(set_if_some, builder, params.local_address, local_address);
#[cfg(any(
target_os = "android",
target_os = "fuchsia",
Expand Down
21 changes: 6 additions & 15 deletions src/client/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Request {
proxy: Option<Extractor<Proxy>>,

/// Bind to a local IP Address.
local_address: Option<Extractor<IpAddr>>,
local_address: Option<IpAddr>,

/// Bind to an interface by `SO_BINDTODEVICE`.
interface: Option<String>,
Expand Down Expand Up @@ -108,6 +108,7 @@ impl FromPyObject<'_, '_> for Request {
extract_option!(ob, params, proxy);
extract_option!(ob, params, local_address);
extract_option!(ob, params, interface);

extract_option!(ob, params, timeout);
extract_option!(ob, params, read_timeout);

Expand Down Expand Up @@ -147,7 +148,7 @@ pub struct WebSocketRequest {
proxy: Option<Extractor<Proxy>>,

/// Bind to a local IP Address.
local_address: Option<Extractor<IpAddr>>,
local_address: Option<IpAddr>,

/// Bind to an interface by `SO_BINDTODEVICE`.
interface: Option<String>,
Expand Down Expand Up @@ -180,7 +181,7 @@ pub struct WebSocketRequest {
basic_auth: Option<(PyBackedStr, Option<PyBackedStr>)>,

/// The query parameters to use for the request.
query: Option<Extractor<Vec<(PyBackedStr, PyBackedStr)>>>,
query: Option<Query>,

/// Read buffer capacity. This buffer is eagerly allocated and used for receiving
/// messages.
Expand Down Expand Up @@ -302,12 +303,7 @@ where

// Network options.
apply_option!(set_if_some_inner, builder, params.proxy, proxy);
apply_option!(
set_if_some_inner,
builder,
params.local_address,
local_address
);
apply_option!(set_if_some, builder, params.local_address, local_address);
#[cfg(any(
target_os = "android",
target_os = "fuchsia",
Expand Down Expand Up @@ -458,12 +454,7 @@ where

// Network options.
apply_option!(set_if_some_inner, builder, params.proxy, proxy);
apply_option!(
set_if_some_inner,
builder,
params.local_address,
local_address
);
apply_option!(set_if_some, builder, params.local_address, local_address);
#[cfg(any(
target_os = "android",
target_os = "fuchsia",
Expand Down
33 changes: 0 additions & 33 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use pyo3::{
pybacked::PyBackedStr,
types::{PyDict, PyList},
};
use serde::ser::{Serialize, SerializeSeq, Serializer};
use wreq::header::{self, HeaderName, HeaderValue};

use crate::{
Expand All @@ -20,29 +19,6 @@ use crate::{
/// A generic extractor for various types.
pub struct Extractor<T>(pub T);

/// Serialize implementation for [`Vec<(PyBackedStr, PyBackedStr)>`].
impl Serialize for Extractor<Vec<(PyBackedStr, PyBackedStr)>> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut seq = serializer.serialize_seq(Some(self.0.len()))?;
for (key, value) in &self.0 {
seq.serialize_element::<(&str, &str)>(&(key.as_ref(), value.as_ref()))?;
}
seq.end()
}
}

/// Extractor for URL-encoded values as [`Vec<(PyBackedStr, PyBackedStr)>`].
impl FromPyObject<'_, '_> for Extractor<Vec<(PyBackedStr, PyBackedStr)>> {
type Error = PyErr;

fn extract(ob: Borrowed<PyAny>) -> PyResult<Self> {
ob.extract().map(Self)
}
}

/// Extractor for HTTP Version as [`wreq::Version`].
impl FromPyObject<'_, '_> for Extractor<wreq::Version> {
type Error = PyErr;
Expand Down Expand Up @@ -198,12 +174,3 @@ impl FromPyObject<'_, '_> for Extractor<wreq::multipart::Form> {
.map_err(Into::into)
}
}

/// Extractor for a single IP address as [`std::net::IpAddr`].
impl FromPyObject<'_, '_> for Extractor<std::net::IpAddr> {
type Error = PyErr;

fn extract(ob: Borrowed<PyAny>) -> PyResult<Self> {
ob.extract().map(Self)
}
}
Loading