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

Method readline

crates/stdlib/src/mmap.rs:1152–1177  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1150
1151 #[pymethod]
1152 fn readline(&self, vm: &VirtualMachine) -> PyResult<PyBytesRef> {
1153 let pos = self.pos();
1154 let mmap = self.check_valid(vm)?;
1155
1156 let remaining = self.__len__().saturating_sub(pos);
1157 if remaining == 0 {
1158 return Ok(PyBytes::from(vec![]).into_ref(&vm.ctx));
1159 }
1160
1161 let slice = mmap.as_ref().unwrap().as_slice();
1162 let eof = slice[pos..].iter().position(|&x| x == b'\n');
1163
1164 let end_pos = if let Some(i) = eof {
1165 pos + i + 1
1166 } else {
1167 self.__len__()
1168 };
1169
1170 let bytes = slice[pos..end_pos].to_vec();
1171
1172 let result = PyBytes::from(bytes).into_ref(&vm.ctx);
1173
1174 self.advance_pos(end_pos - pos);
1175
1176 Ok(result)
1177 }
1178
1179 #[cfg(unix)]
1180 #[pymethod]

Callers

nothing calls this directly

Calls 11

check_validMethod · 0.80
to_vecMethod · 0.80
advance_posMethod · 0.80
posMethod · 0.45
__len__Method · 0.45
into_refMethod · 0.45
as_sliceMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected