| 4793 | impl PyRef<BytesIO> { |
| 4794 | #[pymethod] |
| 4795 | fn getbuffer(self, vm: &VirtualMachine) -> PyResult<PyMemoryView> { |
| 4796 | if self.closed.load() { |
| 4797 | return Err(vm.new_value_error("I/O operation on closed file.")); |
| 4798 | } |
| 4799 | let len = self.buffer.read().cursor.get_ref().len(); |
| 4800 | let buffer = PyBuffer::new( |
| 4801 | self.into(), |
| 4802 | BufferDescriptor::simple(len, false), |
| 4803 | &BYTES_IO_BUFFER_METHODS, |
| 4804 | ); |
| 4805 | let view = PyMemoryView::from_buffer(buffer, vm)?; |
| 4806 | Ok(view) |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | static BYTES_IO_BUFFER_METHODS: BufferMethods = BufferMethods { |