Xuanwo commented on code in PR #3402:
URL: 
https://github.com/apache/incubator-opendal/pull/3402#discussion_r1375798569


##########
bindings/python/python/opendal/__init__.pyi:
##########
@@ -107,3 +109,54 @@ class PresignedRequest:
     def method(self) -> str: ...
     @property
     def headers(self) -> dict[str, str]: ...
+
+class Capability:
+    stat: bool
+    stat_with_if_match: bool
+    stat_with_if_none_match: bool
+
+    read: bool
+    read_can_seek: bool
+    read_can_next: bool
+    read_with_range: bool
+    read_with_if_match: bool
+    read_with_if_none_match: bool
+    read_with_override_cache_control: bool
+    read_with_override_content_disposition: bool
+    read_with_override_content_type: bool
+
+    write: bool
+    write_can_multi: bool
+    write_can_empty: bool
+    write_can_append: bool
+    write_with_content_type: bool
+    write_with_content_disposition: bool
+    write_with_cache_control: bool
+    write_multi_max_size: Optional[int]
+    write_multi_min_size: Optional[int]
+    write_multi_align_size: Optional[int]
+    write_total_max_size: Optional[int]
+
+    create_dir: bool
+    delete: bool
+    copy: bool
+    rename: bool
+
+    list: bool
+    list_with_limit: bool
+    list_with_start_after: bool
+    list_with_delimiter_slash: bool
+    list_without_delimiter: bool
+
+    presign: bool
+    presign_read: bool
+    presign_stat: bool
+    presign_write: bool
+
+    batch: bool
+    batch_delete: bool
+    batch_max_operations: Optional[int]
+
+    blocking: bool
+
+    def get_supported_capability_field(self) -> Iterable[str]: ...

Review Comment:
   What's this API for?



##########
bindings/python/src/capability.rs:
##########
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::collections::HashMap;
+
+use pyo3::exceptions::PyAttributeError;
+use pyo3::prelude::*;
+use pyo3::types::PyString;
+
+#[pyclass(module = "opendal")]
+pub struct Capability(opendal::Capability);
+
+impl Capability {
+    pub fn new(capability: opendal::Capability) -> Self {
+        Self(capability)
+    }
+}
+
+#[pymethods]
+impl Capability {
+    fn __getattr__(&self, py: Python, name: &PyString) -> PyResult<PyObject> {
+        let name = name.to_string();

Review Comment:
   This adds a new alloc, we should avoid this.



##########
bindings/python/src/capability.rs:
##########
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::collections::HashMap;
+
+use pyo3::exceptions::PyAttributeError;
+use pyo3::prelude::*;
+use pyo3::types::PyString;
+
+#[pyclass(module = "opendal")]
+pub struct Capability(opendal::Capability);
+
+impl Capability {
+    pub fn new(capability: opendal::Capability) -> Self {
+        Self(capability)
+    }
+}
+
+#[pymethods]
+impl Capability {
+    fn __getattr__(&self, py: Python, name: &PyString) -> PyResult<PyObject> {
+        let name = name.to_string();
+        match name.as_str() {
+            "stat" => Ok(self.0.stat.into_py(py)),
+            "stat_with_if_match" => Ok(self.0.stat_with_if_match.into_py(py)),
+            "stat_with_if_none_match" => 
Ok(self.0.stat_with_if_none_match.into_py(py)),
+            "read" => Ok(self.0.read.into_py(py)),
+            "read_can_seek" => Ok(self.0.read_can_seek.into_py(py)),
+            "read_can_next" => Ok(self.0.read_can_next.into_py(py)),
+            "read_with_range" => Ok(self.0.read_with_range.into_py(py)),
+            "read_with_if_match" => Ok(self.0.read_with_if_match.into_py(py)),
+            "read_with_if_none_match" => 
Ok(self.0.read_with_if_none_match.into_py(py)),
+            "read_with_override_cache_control" => {
+                Ok(self.0.read_with_override_cache_control.into_py(py))
+            }
+            "read_with_override_content_disposition" => {
+                Ok(self.0.read_with_override_content_disposition.into_py(py))
+            }
+            "read_with_override_content_type" => {
+                Ok(self.0.read_with_override_content_type.into_py(py))
+            }
+            "write" => Ok(self.0.write.into_py(py)),
+            "write_can_multi" => Ok(self.0.write_can_multi.into_py(py)),
+            "write_can_empty" => Ok(self.0.write_can_empty.into_py(py)),
+            "write_can_append" => Ok(self.0.write_can_append.into_py(py)),
+            "write_with_content_type" => 
Ok(self.0.write_with_content_type.into_py(py)),
+            "write_with_content_disposition" => {
+                Ok(self.0.write_with_content_disposition.into_py(py))
+            }
+            "write_with_cache_control" => 
Ok(self.0.write_with_cache_control.into_py(py)),
+            "write_multi_max_size" => 
Ok(self.0.write_multi_max_size.into_py(py)),
+            "write_multi_min_size" => 
Ok(self.0.write_multi_min_size.into_py(py)),
+            "write_multi_align_size" => 
Ok(self.0.write_multi_align_size.into_py(py)),
+            "write_total_max_size" => 
Ok(self.0.write_total_max_size.into_py(py)),
+            "create_dir" => Ok(self.0.create_dir.into_py(py)),
+            "delete" => Ok(self.0.delete.into_py(py)),
+            "copy" => Ok(self.0.copy.into_py(py)),
+            "rename" => Ok(self.0.rename.into_py(py)),
+            "list" => Ok(self.0.list.into_py(py)),
+            "list_with_limit" => Ok(self.0.list_with_limit.into_py(py)),
+            "list_with_start_after" => 
Ok(self.0.list_with_start_after.into_py(py)),
+            "list_with_delimiter_slash" => 
Ok(self.0.list_with_delimiter_slash.into_py(py)),
+            "list_without_delimiter" => 
Ok(self.0.list_without_delimiter.into_py(py)),
+            "presign" => Ok(self.0.presign.into_py(py)),
+            "presign_read" => Ok(self.0.presign_read.into_py(py)),
+            "presign_stat" => Ok(self.0.presign_stat.into_py(py)),
+            "presign_write" => Ok(self.0.presign_write.into_py(py)),
+            "batch" => Ok(self.0.batch.into_py(py)),
+            "batch_delete" => Ok(self.0.batch_delete.into_py(py)),
+            "batch_max_operations" => 
Ok(self.0.batch_max_operations.into_py(py)),
+            "blocking" => Ok(self.0.blocking.into_py(py)),
+            _ => Err(PyAttributeError::new_err(format!(
+                "No attribute named '{}'",
+                name
+            ))),
+        }
+    }
+
+    pub fn get_supported_capability_field(&self) -> PyResult<Vec<String>> {

Review Comment:
   We should not add API like this.



##########
bindings/python/Cargo.toml:
##########
@@ -37,3 +37,5 @@ opendal.workspace = true
 pyo3 = "0.19"
 pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] }
 tokio = "1"
+serde = { version = "1.0", features = ["derive"] }

Review Comment:
   Should be added as dev-dependencies.



##########
core/src/types/capability.rs:
##########
@@ -44,7 +44,7 @@ use std::fmt::Debug;
 /// - Operation with variants should be named like `read_can_seek`.
 /// - Operation with arguments should be named like `read_with_range`.
 /// - Operation with limitations should be named like `batch_max_operations`.
-#[derive(Copy, Clone, Default)]
+#[derive(Copy, Clone, Default, Serialize)]

Review Comment:
   Please avoid adding `Serialize` as it could potentially be misused by users.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to