|
| 1 | +/* |
| 2 | + * I/O core tools. |
| 3 | + */ |
| 4 | + |
| 5 | +// use super::super::obj::{objstr, objtype}; |
| 6 | +use super::super::pyobject::{ |
| 7 | + AttributeProtocol, DictProtocol, PyContext, PyFuncArgs, PyObjectRef, PyResult, |
| 8 | +}; |
| 9 | +use super::super::VirtualMachine; |
| 10 | + |
| 11 | +fn string_io_init(vm: &mut VirtualMachine, _args: PyFuncArgs) -> PyResult { |
| 12 | + // arg_check!(vm, args, required = [(s, Some(vm.ctx.str_type()))]); |
| 13 | + // TODO |
| 14 | + Ok(vm.get_none()) |
| 15 | +} |
| 16 | + |
| 17 | +fn string_io_getvalue(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { |
| 18 | + arg_check!(vm, args); |
| 19 | + // TODO |
| 20 | + Ok(vm.get_none()) |
| 21 | +} |
| 22 | + |
| 23 | +fn bytes_io_init(vm: &mut VirtualMachine, _args: PyFuncArgs) -> PyResult { |
| 24 | + // TODO |
| 25 | + Ok(vm.get_none()) |
| 26 | +} |
| 27 | + |
| 28 | +fn bytes_io_getvalue(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { |
| 29 | + arg_check!(vm, args); |
| 30 | + // TODO |
| 31 | + Ok(vm.get_none()) |
| 32 | +} |
| 33 | + |
| 34 | +pub fn mk_module(ctx: &PyContext) -> PyObjectRef { |
| 35 | + let py_mod = ctx.new_module(&"io".to_string(), ctx.new_scope(None)); |
| 36 | + |
| 37 | + let io_base = ctx.new_class("IOBase", ctx.object()); |
| 38 | + py_mod.set_item("IOBase", io_base.clone()); |
| 39 | + |
| 40 | + let string_io = ctx.new_class("StringIO", io_base.clone()); |
| 41 | + string_io.set_attr("__init__", ctx.new_rustfunc(string_io_init)); |
| 42 | + string_io.set_attr("getvalue", ctx.new_rustfunc(string_io_getvalue)); |
| 43 | + py_mod.set_item("StringIO", string_io); |
| 44 | + |
| 45 | + let bytes_io = ctx.new_class("BytesIO", io_base.clone()); |
| 46 | + bytes_io.set_attr("__init__", ctx.new_rustfunc(bytes_io_init)); |
| 47 | + bytes_io.set_attr("getvalue", ctx.new_rustfunc(bytes_io_getvalue)); |
| 48 | + py_mod.set_item("BytesIO", bytes_io); |
| 49 | + |
| 50 | + py_mod |
| 51 | +} |
0 commit comments