Don't panic on invalid utf8 compile(), add __get__/__delete__ to getset/property

This commit is contained in:
Noah
2021-04-06 12:09:48 -05:00
parent 730f37c91a
commit 97f2da7778
3 changed files with 28 additions and 1 deletions

View File

@@ -336,6 +336,19 @@ impl PyGetSet {
}
}
}
#[pymethod]
fn __set__(
zelf: PyObjectRef,
obj: PyObjectRef,
value: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<()> {
Self::descr_set(zelf, obj, Some(value), vm)
}
#[pymethod]
fn __delete__(zelf: PyObjectRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
Self::descr_set(zelf, obj, None, vm)
}
#[pyproperty(magic)]
fn name(&self) -> String {

View File

@@ -157,7 +157,8 @@ mod decl {
// TODO: compile::compile should probably get bytes
let source = match &source {
Either::A(string) => string.borrow_value(),
Either::B(bytes) => std::str::from_utf8(bytes).unwrap(),
Either::B(bytes) => std::str::from_utf8(bytes)
.map_err(|e| vm.new_unicode_decode_error(e.to_string()))?,
};
let flags = args

View File

@@ -136,6 +136,19 @@ impl PyProperty {
}
}
}
#[pymethod]
fn __set__(
zelf: PyObjectRef,
obj: PyObjectRef,
value: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<()> {
Self::descr_set(zelf, obj, Some(value), vm)
}
#[pymethod]
fn __delete__(zelf: PyObjectRef, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
Self::descr_set(zelf, obj, None, vm)
}
// Access functions