(&self, size: OptionalSize, vm: &VirtualMachine)
| 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>> { |
nothing calls this directly
no test coverage detected