MCPcopy Index your code
hub / github.com/RustPython/RustPython / readall

Method readall

crates/vm/src/stdlib/_io.rs:673–707  ·  view source on GitHub ↗
(instance: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

671
672 #[pymethod]
673 fn readall(instance: PyObjectRef, vm: &VirtualMachine) -> PyResult<Option<Vec<u8>>> {
674 let mut chunks = Vec::new();
675 let mut total_len = 0;
676 loop {
677 // Loop with EINTR handling (PEP 475)
678 let data = loop {
679 let res = vm.call_method(&instance, "read", (DEFAULT_BUFFER_SIZE,));
680 match trap_eintr(res, vm)? {
681 Some(val) => break val,
682 None => continue,
683 }
684 };
685 let data = <Option<PyBytesRef>>::try_from_object(vm, data)?;
686 match data {
687 None => {
688 if chunks.is_empty() {
689 return Ok(None);
690 }
691 break;
692 }
693 Some(b) => {
694 if b.as_bytes().is_empty() {
695 break;
696 }
697 total_len += b.as_bytes().len();
698 chunks.push(b)
699 }
700 }
701 }
702 let mut ret = Vec::with_capacity(total_len);
703 for b in chunks {
704 ret.extend_from_slice(b.as_bytes())
705 }
706 Ok(Some(ret))
707 }
708
709 #[pymethod]
710 fn readinto(_instance: PyObjectRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {

Callers 1

readMethod · 0.45

Calls 15

newFunction · 0.85
trap_eintrFunction · 0.85
io_closed_errorFunction · 0.85
handle_from_fdFunction · 0.85
is_invalid_handleFunction · 0.85
as_mut_ptrMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
call_methodMethod · 0.45
is_emptyMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected