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

Method readline

crates/stdlib/src/_tokenize.rs:42–67  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

40
41 impl PyTokenizerIter {
42 fn readline(&self, vm: &VirtualMachine) -> PyResult<String> {
43 let raw_line = match self.readline.invoke((), vm) {
44 Ok(v) => v,
45 Err(err) => {
46 if err.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
47 return Ok(String::new());
48 }
49 return Err(err);
50 }
51 };
52 Ok(match &self.encoding {
53 Some(encoding) => {
54 let bytes = raw_line
55 .downcast::<PyBytes>()
56 .map_err(|_| vm.new_type_error("readline() returned a non-bytes object"))?;
57 vm.state
58 .codec_registry
59 .decode_text(bytes.into(), encoding, None, vm)
60 .map(|s| s.to_string())?
61 }
62 None => raw_line
63 .downcast::<PyStr>()
64 .map(|s| s.to_string())
65 .map_err(|_| vm.new_type_error("readline() returned a non-string object"))?,
66 })
67 }
68 }
69
70 impl fmt::Debug for PyTokenizerIter {

Callers 1

nextMethod · 0.45

Calls 7

newFunction · 0.85
fast_isinstanceMethod · 0.80
decode_textMethod · 0.80
to_stringMethod · 0.80
ErrClass · 0.50
invokeMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected