Skip to content

Commit 91fb0f1

Browse files
authored
fix: Fix conversion from python string to Rust Attribute (#520)
1 parent 38cf3a6 commit 91fb0f1

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

obstore/src/attributes.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ pub(crate) struct PyAttribute(Attribute);
1212

1313
impl<'py> FromPyObject<'py> for PyAttribute {
1414
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
15-
let s = ob.extract::<PyBackedStr>()?.to_ascii_lowercase();
16-
match s.as_str() {
15+
let s = ob.extract::<PyBackedStr>()?;
16+
match s.to_ascii_lowercase().as_str() {
1717
"content-disposition" | "contentdisposition" => Ok(Self(Attribute::ContentDisposition)),
18-
"Content-Encoding" | "ContentEncoding" => Ok(Self(Attribute::ContentEncoding)),
19-
"Content-Language" | "ContentLanguage" => Ok(Self(Attribute::ContentLanguage)),
20-
"Content-Type" | "ContentType" => Ok(Self(Attribute::ContentType)),
21-
"Cache-Control" | "CacheControl" => Ok(Self(Attribute::CacheControl)),
22-
_ => Ok(Self(Attribute::Metadata(Cow::Owned(s)))),
18+
"content-encoding" | "contentencoding" => Ok(Self(Attribute::ContentEncoding)),
19+
"content-language" | "contentlanguage" => Ok(Self(Attribute::ContentLanguage)),
20+
"content-type" | "contenttype" => Ok(Self(Attribute::ContentType)),
21+
"cache-control" | "cachecontrol" => Ok(Self(Attribute::CacheControl)),
22+
_ => Ok(Self(Attribute::Metadata(Cow::Owned(s.to_string())))),
2323
}
2424
}
2525
}

tests/test_attributes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from obstore.store import MemoryStore
2+
3+
4+
def test_content_type():
5+
store = MemoryStore()
6+
store.put("test.txt", b"Hello, World!", attributes={"Content-Type": "text/plain"})
7+
result = store.get("test.txt")
8+
assert result.attributes.get("Content-Type") == "text/plain"
9+
10+
11+
def test_custom_attribute():
12+
store = MemoryStore()
13+
store.put(
14+
"test.txt",
15+
b"Hello, World!",
16+
attributes={"My-Custom-Attribute": "CustomValue"},
17+
)
18+
result = store.get("test.txt")
19+
assert result.attributes.get("My-Custom-Attribute") == "CustomValue"

0 commit comments

Comments
 (0)