You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by me...@apache.org on 2024/12/26 00:27:52 UTC
(opendal) branch main updated: fix: python binding kwargs parsing (#5458)
This is an automated email from the ASF dual-hosted git repository.
messense 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 93f3aa14b fix: python binding kwargs parsing (#5458)
93f3aa14b is described below
commit 93f3aa14bf4c7247af242ee36d8c644e57275c57
Author: Trim21 <tr...@gmail.com>
AuthorDate: Thu Dec 26 08:27:47 2024 +0800
fix: python binding kwargs parsing (#5458)
* fix: python binding kwargs parsing
* add for test
---
bindings/python/Cargo.toml | 1 +
bindings/python/src/operator.rs | 9 +++++++--
bindings/python/src/options.rs | 5 +++--
bindings/python/tests/test_write.py | 2 +-
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml
index a2db6361c..6cda36ddf 100644
--- a/bindings/python/Cargo.toml
+++ b/bindings/python/Cargo.toml
@@ -158,6 +158,7 @@ doc = false
[dependencies]
bytes = "1.5.0"
+dict_derive = "0.6.0"
futures = "0.3.28"
# this crate won't be published, we always use the local version
opendal = { version = ">=0", path = "../../core", features = [
diff --git a/bindings/python/src/operator.rs b/bindings/python/src/operator.rs
index 4cd539244..b3c14b7c5 100644
--- a/bindings/python/src/operator.rs
+++ b/bindings/python/src/operator.rs
@@ -118,7 +118,10 @@ impl Operator {
#[pyo3(signature = (path, bs, **kwargs))]
pub fn write(&self, path: &str, bs: Vec<u8>, kwargs: Option<WriteOptions>) -> PyResult<()> {
let kwargs = kwargs.unwrap_or_default();
- let mut write = self.core.write_with(path, bs).append(kwargs.append);
+ let mut write = self
+ .core
+ .write_with(path, bs)
+ .append(kwargs.append.unwrap_or(false));
if let Some(chunk) = kwargs.chunk {
write = write.chunk(chunk);
}
@@ -333,7 +336,9 @@ impl AsyncOperator {
let this = self.core.clone();
let bs = bs.as_bytes().to_vec();
future_into_py(py, async move {
- let mut write = this.write_with(&path, bs).append(kwargs.append);
+ let mut write = this
+ .write_with(&path, bs)
+ .append(kwargs.append.unwrap_or(false));
if let Some(buffer) = kwargs.chunk {
write = write.chunk(buffer);
}
diff --git a/bindings/python/src/options.rs b/bindings/python/src/options.rs
index 0992b913d..16e6a4640 100644
--- a/bindings/python/src/options.rs
+++ b/bindings/python/src/options.rs
@@ -15,12 +15,13 @@
// specific language governing permissions and limitations
// under the License.
-use pyo3::{pyclass, FromPyObject};
+use dict_derive::FromPyObject;
+use pyo3::pyclass;
#[pyclass(module = "opendal")]
#[derive(FromPyObject, Default)]
pub struct WriteOptions {
- pub append: bool,
+ pub append: Option<bool>,
pub chunk: Option<usize>,
pub content_type: Option<String>,
pub content_disposition: Option<String>,
diff --git a/bindings/python/tests/test_write.py b/bindings/python/tests/test_write.py
index e15bdd26e..69d448ba0 100644
--- a/bindings/python/tests/test_write.py
+++ b/bindings/python/tests/test_write.py
@@ -29,7 +29,7 @@ def test_sync_write(service_name, operator, async_operator):
filename = f"test_file_{str(uuid4())}.txt"
content = os.urandom(size)
size = len(content)
- operator.write(filename, content)
+ operator.write(filename, content, content_type="text/plain")
metadata = operator.stat(filename)
assert metadata is not None
assert metadata.mode.is_file()