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

Method seek

crates/stdlib/src/_sqlite3.rs:2420–2452  ·  view source on GitHub ↗
(
            &self,
            mut offset: c_int,
            origin: OptionalArg<c_int>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

2418
2419 #[pymethod]
2420 fn seek(
2421 &self,
2422 mut offset: c_int,
2423 origin: OptionalArg<c_int>,
2424 vm: &VirtualMachine,
2425 ) -> PyResult<()> {
2426 self.ensure_connection_open(vm)?;
2427 let origin = origin.unwrap_or(libc::SEEK_SET);
2428 let mut inner = self.inner(vm)?;
2429 let blob_len = inner.blob.bytes();
2430
2431 let overflow_err = || vm.new_overflow_error("seek offset results in overflow");
2432
2433 match origin {
2434 libc::SEEK_SET => {}
2435 libc::SEEK_CUR => {
2436 offset = offset.checked_add(inner.offset).ok_or_else(overflow_err)?
2437 }
2438 libc::SEEK_END => offset = offset.checked_add(blob_len).ok_or_else(overflow_err)?,
2439 _ => {
2440 return Err(vm.new_value_error(
2441 "'origin' should be os.SEEK_SET, os.SEEK_CUR, or os.SEEK_END",
2442 ));
2443 }
2444 }
2445
2446 if offset < 0 || offset > blob_len {
2447 Err(vm.new_value_error("offset out of blob range"))
2448 } else {
2449 inner.offset = offset;
2450 Ok(())
2451 }
2452 }
2453
2454 #[pymethod]
2455 fn __enter__(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {

Callers

nothing calls this directly

Calls 5

ok_or_elseMethod · 0.80
ErrClass · 0.50
innerMethod · 0.45
bytesMethod · 0.45

Tested by

no test coverage detected