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

Function parse_decoder_state

crates/vm/src/stdlib/_io.rs:3840–3858  ·  view source on GitHub ↗
(state: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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<()> {

Callers 2

tellMethod · 0.85
read_chunkMethod · 0.85

Calls 5

ok_or_elseMethod · 0.80
try_to_primitiveMethod · 0.80
ErrClass · 0.50
as_sliceMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected