mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
Merge pull request #641 from RustPython/py_module_use
Use py_module at more places.
This commit is contained in:
5 files changed
+27
-28
No files matched your search
@@ -624,8 +624,8 @@ fn ast_parse(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
|
||||
py_module!(ctx, "ast", {
|
||||
"parse" => ctx.new_rustfunc(ast_parse),
|
||||
"Module" => ctx.new_class("_ast.Module", ctx.object()),
|
||||
"FunctionDef" =>ctx.new_class("_ast.FunctionDef", ctx.object()),
|
||||
"Call" => ctx.new_class("_ast.Call", ctx.object())
|
||||
"Module" => py_class!(ctx, "_ast.Module", ctx.object(), {}),
|
||||
"FunctionDef" => py_class!(ctx, "_ast.FunctionDef", ctx.object(), {}),
|
||||
"Call" => py_class!(ctx, "_ast.Call", ctx.object(), {})
|
||||
})
|
||||
}
|
||||
+2
-2
@@ -347,10 +347,10 @@ pub fn io_open(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
|
||||
//IOBase the abstract base class of the IO Module
|
||||
let io_base = ctx.new_class("IOBase", ctx.object());
|
||||
let io_base = py_class!(ctx, "IOBase", ctx.object(), {});
|
||||
|
||||
// IOBase Subclasses
|
||||
let raw_io_base = ctx.new_class("RawIOBase", ctx.object());
|
||||
let raw_io_base = py_class!(ctx, "RawIOBase", ctx.object(), {});
|
||||
|
||||
let buffered_io_base = py_class!(ctx, "BufferedIOBase", io_base.clone(), {
|
||||
"__init__" => ctx.new_rustfunc(buffered_io_base_init)
|
||||
|
||||
+11
-11
@@ -119,17 +119,17 @@ fn os_error(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
}
|
||||
|
||||
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
|
||||
let py_mod = ctx.new_module(&"os".to_string(), ctx.new_scope(None));
|
||||
ctx.set_attr(&py_mod, "open", ctx.new_rustfunc(os_open));
|
||||
ctx.set_attr(&py_mod, "close", ctx.new_rustfunc(os_close));
|
||||
ctx.set_attr(&py_mod, "error", ctx.new_rustfunc(os_error));
|
||||
|
||||
ctx.set_attr(&py_mod, "O_RDONLY", ctx.new_int(0));
|
||||
ctx.set_attr(&py_mod, "O_WRONLY", ctx.new_int(1));
|
||||
ctx.set_attr(&py_mod, "O_RDWR", ctx.new_int(2));
|
||||
ctx.set_attr(&py_mod, "O_NONBLOCK", ctx.new_int(4));
|
||||
ctx.set_attr(&py_mod, "O_APPEND", ctx.new_int(8));
|
||||
ctx.set_attr(&py_mod, "O_CREAT", ctx.new_int(512));
|
||||
let py_mod = py_module!(ctx, "os", {
|
||||
"open" => ctx.new_rustfunc(os_open),
|
||||
"close" => ctx.new_rustfunc(os_close),
|
||||
"error" => ctx.new_rustfunc(os_error),
|
||||
"O_RDONLY" => ctx.new_int(0),
|
||||
"O_WRONLY" => ctx.new_int(1),
|
||||
"O_RDWR" => ctx.new_int(2),
|
||||
"O_NONBLOCK" => ctx.new_int(4),
|
||||
"O_APPEND" => ctx.new_int(8),
|
||||
"O_CREAT" => ctx.new_int(512)
|
||||
});
|
||||
|
||||
if cfg!(windows) {
|
||||
ctx.set_attr(&py_mod, "name", ctx.new_str("nt".to_string()));
|
||||
|
||||
@@ -13,13 +13,14 @@ use crate::VirtualMachine;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
|
||||
let py_mod = ctx.new_module("_weakref", ctx.new_scope(None));
|
||||
let py_ref_class = py_class!(ctx, "ref", ctx.object(), {
|
||||
"__new__" => ctx.new_rustfunc(ref_new),
|
||||
"__call__" => ctx.new_rustfunc(ref_call)
|
||||
});
|
||||
|
||||
let py_ref_class = ctx.new_class("ref", ctx.object());
|
||||
ctx.set_attr(&py_ref_class, "__new__", ctx.new_rustfunc(ref_new));
|
||||
ctx.set_attr(&py_ref_class, "__call__", ctx.new_rustfunc(ref_call));
|
||||
ctx.set_attr(&py_mod, "ref", py_ref_class);
|
||||
py_mod
|
||||
py_module!(ctx, "_weakref", {
|
||||
"ref" => py_ref_class
|
||||
})
|
||||
}
|
||||
|
||||
fn ref_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
|
||||
@@ -311,12 +311,10 @@ fn browser_prompt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
const BROWSER_NAME: &str = "browser";
|
||||
|
||||
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
|
||||
let promise = {
|
||||
let promise = ctx.new_class("Promise", ctx.object());
|
||||
ctx.set_attr(&promise, "then", ctx.new_rustfunc(promise_then));
|
||||
ctx.set_attr(&promise, "catch", ctx.new_rustfunc(promise_catch));
|
||||
promise
|
||||
};
|
||||
let promise = py_class!(ctx, "Promise", ctx.object(), {
|
||||
"then" => ctx.new_rustfunc(promise_then),
|
||||
"catch" => ctx.new_rustfunc(promise_catch)
|
||||
});
|
||||
|
||||
py_module!(ctx, BROWSER_NAME, {
|
||||
"fetch" => ctx.new_rustfunc(browser_fetch),
|
||||
|
||||
Reference in new issue
Block a user