This is an automated email from the ASF dual-hosted git repository.

manjusaka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 648d827e2 feat(bindings/python): export MimeGuessLayer (#6073)
648d827e2 is described below

commit 648d827e20fe2f1258e8c80c217f0f8b133e137b
Author: pk5ls20 <[email protected]>
AuthorDate: Tue Apr 22 04:04:35 2025 +0800

    feat(bindings/python): export MimeGuessLayer (#6073)
---
 bindings/python/Cargo.toml                |  2 ++
 bindings/python/python/opendal/layers.pyi |  4 ++++
 bindings/python/src/layers.rs             | 22 ++++++++++++++++++++++
 bindings/python/src/lib.rs                |  1 +
 bindings/python/tests/conftest.py         |  1 +
 5 files changed, 30 insertions(+)

diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml
index ad7887c03..ea6271a39 100644
--- a/bindings/python/Cargo.toml
+++ b/bindings/python/Cargo.toml
@@ -163,6 +163,7 @@ futures = "0.3.28"
 # this crate won't be published, we always use the local version
 opendal = { version = ">=0", path = "../../core", features = [
   "layers-blocking",
+  "layers-mime-guess"
 ] }
 pyo3 = { version = "0.24.1", features = ["generate-import-lib", "chrono"] }
 pyo3-async-runtimes = { version = "0.24.0", features = ["tokio-runtime"] }
@@ -171,6 +172,7 @@ tokio = "1"
 [target.'cfg(unix)'.dependencies.opendal]
 features = [
   "layers-blocking",
+  "layers-mime-guess",
   # Depend on "openssh" which depends on "tokio-pipe" that is unavailable on 
Windows.
   "services-sftp",
 ]
diff --git a/bindings/python/python/opendal/layers.pyi 
b/bindings/python/python/opendal/layers.pyi
index a4b2df62e..609928ff0 100644
--- a/bindings/python/python/opendal/layers.pyi
+++ b/bindings/python/python/opendal/layers.pyi
@@ -34,3 +34,7 @@ class RetryLayer(Layer):
 @final
 class ConcurrentLimitLayer(Layer):
     def __init__(self, limit: int) -> None: ...
+
+@final
+class MimeGuessLayer(Layer):
+    def __init__(self) -> None: ...
\ No newline at end of file
diff --git a/bindings/python/src/layers.rs b/bindings/python/src/layers.rs
index e03aafac9..59b0c3540 100644
--- a/bindings/python/src/layers.rs
+++ b/bindings/python/src/layers.rs
@@ -103,3 +103,25 @@ impl ConcurrentLimitLayer {
         Ok(class)
     }
 }
+
+#[pyclass(module = "opendal.layers", extends=Layer)]
+#[derive(Clone)]
+pub struct MimeGuessLayer(ocore::layers::MimeGuessLayer);
+
+impl PythonLayer for MimeGuessLayer {
+    fn layer(&self, op: Operator) -> Operator {
+        op.layer(self.0.clone())
+    }
+}
+
+#[pymethods]
+impl MimeGuessLayer {
+    #[new]
+    #[pyo3(signature = ())]
+    fn new() -> PyResult<PyClassInitializer<Self>> {
+        let mime_guess_layer = Self(ocore::layers::MimeGuessLayer::default());
+        let class = 
PyClassInitializer::from(Layer(Box::new(mime_guess_layer.clone())))
+            .add_subclass(mime_guess_layer);
+        Ok(class)
+    }
+}
diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs
index a18efdeed..7e1a99e60 100644
--- a/bindings/python/src/lib.rs
+++ b/bindings/python/src/lib.rs
@@ -60,6 +60,7 @@ fn _opendal(py: Python, m: &Bound<'_, PyModule>) -> 
PyResult<()> {
     layers_module.add_class::<Layer>()?;
     layers_module.add_class::<RetryLayer>()?;
     layers_module.add_class::<ConcurrentLimitLayer>()?;
+    layers_module.add_class::<MimeGuessLayer>()?;
     m.add_submodule(&layers_module)?;
     py.import("sys")?
         .getattr("modules")?
diff --git a/bindings/python/tests/conftest.py 
b/bindings/python/tests/conftest.py
index 5e673317e..0aa29d5a8 100644
--- a/bindings/python/tests/conftest.py
+++ b/bindings/python/tests/conftest.py
@@ -65,6 +65,7 @@ def async_operator(service_name, setup_config):
         opendal.AsyncOperator(service_name, **setup_config)
         .layer(opendal.layers.RetryLayer())
         .layer(opendal.layers.ConcurrentLimitLayer(1024))
+        .layer(opendal.layers.MimeGuessLayer())
     )
 
 

Reply via email to