(state: PyObjectRef, vm: &VirtualMachine)
| 3838 | } |
| 3839 | |
| 3840 | fn parse_decoder_state(state: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyBytesRef, i32)> { |
| 3841 | use crate::builtins::{PyTuple, int}; |
| 3842 | let state_err = || vm.new_type_error("illegal decoder state"); |
| 3843 | let state = state.downcast::<PyTuple>().map_err(|_| state_err())?; |
| 3844 | match state.as_slice() { |
| 3845 | [buf, flags] => { |
| 3846 | let buf = buf.clone().downcast::<PyBytes>().map_err(|obj| { |
| 3847 | vm.new_type_error(format!( |
| 3848 | "illegal decoder state: the first item should be a bytes object, not '{}'", |
| 3849 | obj.class().name() |
| 3850 | )) |
| 3851 | })?; |
| 3852 | let flags = flags.downcast_ref::<int::PyInt>().ok_or_else(state_err)?; |
| 3853 | let flags = flags.try_to_primitive(vm)?; |
| 3854 | Ok((buf, flags)) |
| 3855 | } |
| 3856 | _ => Err(state_err()), |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | impl TextIOData { |
| 3861 | fn write_pending(&mut self, vm: &VirtualMachine) -> PyResult<()> { |
no test coverage detected