forked from Rust-related/RustPython
Don't panic on invalid utf8 compile(), add __get__/__delete__ to getset/property
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user