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

Method readline

crates/vm/src/stdlib/sys.rs:132–148  ·  view source on GitHub ↗
(&self, size: OptionalArg<isize>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

130
131 #[pymethod]
132 fn readline(&self, size: OptionalArg<isize>, vm: &VirtualMachine) -> PyResult<String> {
133 if self.fd != 0 {
134 return Err(vm.new_os_error("not readable".to_owned()));
135 }
136 let size = size.unwrap_or(-1);
137 if size == 0 {
138 return Ok(String::new());
139 }
140 let mut line = String::new();
141 std::io::stdin()
142 .read_line(&mut line)
143 .map_err(|e| vm.new_os_error(e.to_string()))?;
144 if size > 0 {
145 line.truncate(size as usize);
146 }
147 Ok(line)
148 }
149
150 #[pymethod]
151 fn flush(&self, vm: &VirtualMachine) -> PyResult<()> {

Callers 1

inputFunction · 0.45

Calls 6

newFunction · 0.85
new_os_errorMethod · 0.80
to_stringMethod · 0.80
ErrClass · 0.50
to_ownedMethod · 0.45
truncateMethod · 0.45

Tested by

no test coverage detected