use std::borrow::Cow;
use pyo3::prelude::*;
use pyo3::types::PyString;
#[pyfunction]
#[pyo3(signature = (text,))]
pub fn _escape_html<'py>(text: &Bound<'py, PyString>) -> PyResult<Bound<'py, PyString>> {
let s = text.to_cow()?;
match crate::encoders::escape_html_str(&s) {
Cow::Borrowed(_) => Ok(text.clone()),
Cow::Owned(escaped) => Ok(PyString::new(text.py(), &escaped)),
}
}
#[pyfunction]
#[pyo3(signature = (text, *, component))]
pub fn _percent_encode(text: &str, component: &str) -> PyResult<String> {
crate::encoders::percent_encode_str(text, component).ok_or_else(|| {
crate::InvalidArgumentError::new_err(format!(
"unknown percent-encode component {component:?}; expected one of: \
'path', 'segment', 'query', 'form'"
))
})
}