mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
open builtin
This commit is contained in:
@@ -13,10 +13,13 @@ use super::obj::objint;
|
||||
use super::obj::objiter;
|
||||
use super::obj::objstr;
|
||||
use super::obj::objtype;
|
||||
|
||||
use super::stdlib::io::io_open;
|
||||
use super::pyobject::{
|
||||
AttributeProtocol, IdProtocol, PyContext, PyFuncArgs, PyObject, PyObjectKind, PyObjectRef,
|
||||
PyResult, Scope, TypeProtocol,
|
||||
PyResult, Scope, TypeProtocol
|
||||
};
|
||||
|
||||
use super::vm::VirtualMachine;
|
||||
use num_bigint::ToBigInt;
|
||||
use num_traits::{Signed, ToPrimitive, Zero};
|
||||
@@ -585,8 +588,6 @@ fn builtin_oct(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
Ok(vm.new_str(s))
|
||||
}
|
||||
|
||||
// builtin_open
|
||||
|
||||
fn builtin_ord(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(vm, args, required = [(string, Some(vm.ctx.str_type()))]);
|
||||
let string = objstr::get_value(string);
|
||||
@@ -776,6 +777,7 @@ pub fn make_module(ctx: &PyContext) -> PyObjectRef {
|
||||
ctx.set_attr(&py_mod, "min", ctx.new_rustfunc(builtin_min));
|
||||
ctx.set_attr(&py_mod, "object", ctx.object());
|
||||
ctx.set_attr(&py_mod, "oct", ctx.new_rustfunc(builtin_oct));
|
||||
ctx.set_attr(&py_mod, "open", ctx.new_rustfunc(io_open));
|
||||
ctx.set_attr(&py_mod, "ord", ctx.new_rustfunc(builtin_ord));
|
||||
ctx.set_attr(&py_mod, "next", ctx.new_rustfunc(builtin_next));
|
||||
ctx.set_attr(&py_mod, "pow", ctx.new_rustfunc(builtin_pow));
|
||||
|
||||
@@ -243,7 +243,7 @@ fn buffered_writer_write(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult
|
||||
|
||||
}
|
||||
|
||||
fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
pub fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
arg_check!(
|
||||
vm,
|
||||
args,
|
||||
@@ -259,7 +259,7 @@ fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
let buffered_reader_class = vm.ctx.get_attr(&module, "BufferedReader").unwrap();
|
||||
|
||||
//instantiate raw fileio
|
||||
let file_io = vm.invoke(file_io_class, PyFuncArgs::new(vec![file.clone()], vec![])).unwrap();
|
||||
let file_io = vm.invoke(file_io_class, args.clone()).unwrap();
|
||||
|
||||
//This is subsequently consumed by a Buffered_class of type depending
|
||||
//operation in the mode. i.e:
|
||||
@@ -269,7 +269,6 @@ fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
// creating || writing || appending => BufferedWriter
|
||||
let buffered = if rust_mode.contains("w") {
|
||||
// vm.new_not_implemented_error("Writes are not yet implemented".to_string());
|
||||
println!("writer class");
|
||||
vm.invoke(buffered_writer_class, PyFuncArgs::new(vec![file_io.clone()], vec![]))
|
||||
// reading => BufferedReader
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod ast;
|
||||
mod io;
|
||||
pub mod io;
|
||||
mod json;
|
||||
mod keyword;
|
||||
mod math;
|
||||
|
||||
Reference in New Issue
Block a user