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