From c955f92af9b9b0186059fc0f5621093bf76eb9b7 Mon Sep 17 00:00:00 2001 From: Bakyt Niiazaliev Date: Sun, 6 Jul 2025 01:37:11 +0700 Subject: [PATCH] feat: add find_ascii_non_printable function to identify non-printable ASCII characters --- python/httpx/_httpx/__init__.pyi | 1 + src/urlparse.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/python/httpx/_httpx/__init__.pyi b/python/httpx/_httpx/__init__.pyi index ed9400d2..d5cb0d01 100644 --- a/python/httpx/_httpx/__init__.pyi +++ b/python/httpx/_httpx/__init__.pyi @@ -174,3 +174,4 @@ def quote(string: str, safe: str) -> str: """ def unquote(value: str) -> str: ... +def find_ascii_non_printable(s: str) -> typing.Optional[int]: ... diff --git a/src/urlparse.rs b/src/urlparse.rs index 4e6181c3..96720870 100644 --- a/src/urlparse.rs +++ b/src/urlparse.rs @@ -71,6 +71,12 @@ pub fn quote(string: &str, safe: &str) -> String { result } +#[pyfunction] +pub fn find_ascii_non_printable(s: &str) -> Option { + s.chars() + .position(|c| c.is_ascii() && !c.is_ascii_graphic() && c != ' ') +} + pub(crate) trait PercentEncoded { fn percent_encoded(&self, safe: &str) -> String; }