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

Method fromfile

crates/stdlib/src/array.rs:867–892  ·  view source on GitHub ↗
(&self, f: PyObjectRef, n: isize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

865
866 #[pymethod]
867 fn fromfile(&self, f: PyObjectRef, n: isize, vm: &VirtualMachine) -> PyResult<()> {
868 let itemsize = self.itemsize();
869 if n < 0 {
870 return Err(vm.new_value_error("negative count"));
871 }
872 let n = vm.check_repeat_or_overflow_error(itemsize, n)?;
873 let n_bytes = n * itemsize;
874
875 let b = vm.call_method(&f, "read", (n_bytes,))?;
876 let b = b
877 .downcast::<PyBytes>()
878 .map_err(|_| vm.new_type_error("read() didn't return bytes"))?;
879
880 let not_enough_bytes = b.len() != n_bytes;
881
882 self._from_bytes(b.as_bytes(), itemsize, vm)?;
883
884 if not_enough_bytes {
885 Err(vm.new_exception_msg(
886 vm.ctx.exceptions.eof_error.to_owned(),
887 "read() didn't return enough bytes".into(),
888 ))
889 } else {
890 Ok(())
891 }
892 }
893
894 #[pymethod]
895 fn byteswap(&self) {

Callers

nothing calls this directly

Calls 9

_from_bytesMethod · 0.80
new_exception_msgMethod · 0.80
ErrClass · 0.50
itemsizeMethod · 0.45
call_methodMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected