From 8ed15f0c16ff9abc47fc6dbf9d61b6078bcb5c0d Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Fri, 14 Mar 2025 14:45:41 -0400 Subject: [PATCH] aiohttp backend --- python/src/lib.rs | 1 + python/src/reader/aiohttp.rs | 28 ++++++++++++++++++++++++++++ python/src/reader/mod.rs | 1 + 3 files changed, 30 insertions(+) create mode 100644 python/src/reader/aiohttp.rs create mode 100644 python/src/reader/mod.rs diff --git a/python/src/lib.rs b/python/src/lib.rs index 26be624..7eafa43 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -4,6 +4,7 @@ mod decoder; mod enums; mod geo; mod ifd; +mod reader; mod thread_pool; mod tiff; mod tile; diff --git a/python/src/reader/aiohttp.rs b/python/src/reader/aiohttp.rs new file mode 100644 index 0000000..3f9e4a7 --- /dev/null +++ b/python/src/reader/aiohttp.rs @@ -0,0 +1,28 @@ +use pyo3::exceptions::PyTypeError; +use pyo3::intern; +use pyo3::prelude::*; +use pyo3::pybacked::PyBackedStr; + +struct AiohttpSession(PyObject); + +impl<'py> FromPyObject<'py> for AiohttpSession { + fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult { + let py = ob.py(); + let cls = ob.getattr(intern!(py, "__class__"))?; + let module = cls + .getattr(intern!(py, "__module__"))? + .extract::()?; + let class_name = cls + .getattr(intern!(py, "__name__"))? + .extract::()?; + if module.starts_with("aiohttp") && class_name == "ClientSession" { + todo!() + } else { + let msg = format!( + "Expected aiohttp.ClientSession, got {}.{}", + module, class_name + ); + Err(PyTypeError::new_err(msg)) + } + } +} diff --git a/python/src/reader/mod.rs b/python/src/reader/mod.rs new file mode 100644 index 0000000..d6640bb --- /dev/null +++ b/python/src/reader/mod.rs @@ -0,0 +1 @@ +mod aiohttp;