Add json_load

This commit is contained in:
Daehee Kim
2019-08-15 15:02:38 +09:00
parent 5285c8eeac
commit 73549a5e6f

View File

@@ -39,6 +39,11 @@ pub fn json_loads(string: PyStringRef, vm: &VirtualMachine) -> PyResult {
})
}
pub fn json_load(fp: PyObjectRef, vm: &VirtualMachine) -> PyResult {
let result = vm.call_method(&fp, "read", vec![])?;
json_loads(result.downcast()?, vm)
}
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
@@ -53,6 +58,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"dumps" => ctx.new_rustfunc(json_dumps),
"dump" => ctx.new_rustfunc(json_dump),
"loads" => ctx.new_rustfunc(json_loads),
"load" => ctx.new_rustfunc(json_load),
"JSONDecodeError" => json_decode_error
})
}