Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def test_block_add_hook(self):
def test_block_add_hook_baseexception(self):
self.do_test("test_block_add_hook_baseexception")

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_marshal(self):
import_helper.import_module("marshal")

Expand Down
39 changes: 26 additions & 13 deletions crates/vm/src/stdlib/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod decl {
PySet, PyStopIteration, PyStr, PyTuple,
},
convert::ToPyObject,
function::ArgBytesLike,
function::{ArgBytesLike, ArgIntoBool},
object::{AsObject, PyPayload},
};
use core::cell::RefCell;
Expand Down Expand Up @@ -102,8 +102,8 @@ mod decl {
value: PyObjectRef,
#[pyarg(positional, default = 6)]
version: i32,
#[pyarg(named, default = true)]
allow_code: bool,
#[pyarg(named, default = ArgIntoBool::TRUE)]
allow_code: ArgIntoBool,
}

#[pyfunction]
Expand All @@ -113,6 +113,7 @@ mod decl {
allow_code,
version,
} = args;
let allow_code = allow_code.into();

vm.audit("marshal.dumps", || (value.clone(), version))?;

Expand Down Expand Up @@ -526,12 +527,12 @@ mod decl {
file: PyObjectRef,
#[pyarg(positional, default = 6)]
version: i32,
#[pyarg(named, default = true)]
allow_code: bool,
#[pyarg(named, default = ArgIntoBool::TRUE)]
allow_code: ArgIntoBool,
}

#[pyfunction]
fn dump(args: DumpArgs, vm: &VirtualMachine) -> PyResult<()> {
fn dump(args: DumpArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
let dumped = dumps(
DumpsArgs {
value: args.value,
Expand All @@ -540,8 +541,7 @@ mod decl {
},
vm,
)?;
vm.call_method(&args.file, "write", (dumped,))?;
Ok(())
vm.call_method(&args.file, "write", (dumped,))
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -828,13 +828,17 @@ mod decl {
#[pyarg(positional)]
// marshal_loads_impl takes `bytes: Py_buffer`, a y* argument.
bytes: ArgBytesLike,
#[pyarg(named, default = true)]
allow_code: bool,
#[pyarg(named, default = ArgIntoBool::TRUE)]
allow_code: ArgIntoBool,
}

#[pyfunction]
fn loads(args: LoadsArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
let LoadsArgs { bytes, allow_code } = args;
let allow_code = allow_code.into();
vm.audit("marshal.loads", || {
(vm.ctx.new_bytes(bytes.borrow_buf().to_vec()),)
})?;
let buf = bytes.borrow_buf();

deserialize_value(&mut &buf[..], allow_code, vm)
Expand All @@ -844,12 +848,21 @@ mod decl {
struct LoadArgs {
#[pyarg(positional)]
file: PyObjectRef,
#[pyarg(named, default = true)]
allow_code: bool,
#[pyarg(named, default = ArgIntoBool::TRUE)]
allow_code: ArgIntoBool,
}

#[pyfunction]
fn load(args: LoadArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
let data = vm.call_method(&args.file, "read", (0,))?;
if data.downcast_ref::<PyBytes>().is_none() {
let name = data.class().slot_name();
return Err(vm.new_type_error(format!(
"file.read() returned not bytes but {}",
&name[..name.floor_char_boundary(100.min(name.len()))]
)));
}
vm.audit("marshal.load", || ())?;
let mut rdr = ReadableFile {
file: args.file,
vm,
Expand All @@ -859,7 +872,7 @@ mod decl {
let pending_error = RefCell::new(None);
let result = marshal::deserialize_value(
&mut rdr,
PyMarshalBag::new(vm, &pending_error, args.allow_code),
PyMarshalBag::new(vm, &pending_error, args.allow_code.into()),
);
if let Some(err) = rdr.error.take() {
return Err(err);
Expand Down
Loading