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

Method read

crates/vm/src/stdlib/_io.rs:1852–1866  ·  view source on GitHub ↗
(&self, size: OptionalSize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1850
1851 #[pymethod]
1852 fn read(&self, size: OptionalSize, vm: &VirtualMachine) -> PyResult<Option<PyBytesRef>> {
1853 let mut data = self.reader().lock(vm)?;
1854 let raw = data.check_init(vm)?;
1855 let n = size.size.map(|s| *s).unwrap_or(-1);
1856 if n < -1 {
1857 return Err(vm.new_value_error("read length must be non-negative or -1"));
1858 }
1859 ensure_unclosed(raw, "read of closed file", vm)?;
1860 match n.to_usize() {
1861 Some(n) => data
1862 .read_generic(n, vm)
1863 .map(|x| x.map(|b| PyBytes::from(b).into_ref(&vm.ctx))),
1864 None => data.read_all(vm),
1865 }
1866 }
1867
1868 #[pymethod]
1869 fn peek(&self, _size: OptionalSize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {

Callers

nothing calls this directly

Implementers 1

_io.rscrates/vm/src/stdlib/_io.rs

Calls 10

ensure_unclosedFunction · 0.85
check_initMethod · 0.80
read_genericMethod · 0.80
read_allMethod · 0.80
ErrClass · 0.50
lockMethod · 0.45
readerMethod · 0.45
mapMethod · 0.45
to_usizeMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected