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

Method init

crates/vm/src/stdlib/_io.rs:1603–1648  ·  view source on GitHub ↗
(
            &self,
            raw: PyObjectRef,
            BufferSize { buffer_size }: BufferSize,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1601 }
1602
1603 fn init(
1604 &self,
1605 raw: PyObjectRef,
1606 BufferSize { buffer_size }: BufferSize,
1607 vm: &VirtualMachine,
1608 ) -> PyResult<()> {
1609 let mut data = self.lock(vm)?;
1610 data.raw = None;
1611 data.flags.remove(BufferedFlags::DETACHED);
1612
1613 let buffer_size = match buffer_size {
1614 OptionalArg::Present(i) if i <= 0 => {
1615 return Err(vm.new_value_error("buffer size must be strictly positive"));
1616 }
1617 OptionalArg::Present(i) => i as usize,
1618 OptionalArg::Missing => DEFAULT_BUFFER_SIZE,
1619 };
1620
1621 if Self::SEEKABLE {
1622 check_seekable(&raw, vm)?;
1623 }
1624 if Self::READABLE {
1625 data.flags.insert(BufferedFlags::READABLE);
1626 check_readable(&raw, vm)?;
1627 }
1628 if Self::WRITABLE {
1629 data.flags.insert(BufferedFlags::WRITABLE);
1630 check_writable(&raw, vm)?;
1631 }
1632
1633 data.buffer = vec![0; buffer_size];
1634
1635 if Self::READABLE {
1636 data.reset_read();
1637 }
1638 if Self::WRITABLE {
1639 data.reset_write();
1640 }
1641 if Self::SEEKABLE {
1642 data.pos = 0;
1643 }
1644
1645 data.raw = Some(raw);
1646
1647 Ok(())
1648 }
1649
1650 #[pymethod]
1651 fn seek(

Callers

nothing calls this directly

Implementers 1

_io.rscrates/vm/src/stdlib/_io.rs

Calls 10

check_seekableFunction · 0.85
check_readableFunction · 0.85
check_writableFunction · 0.85
reset_readMethod · 0.80
reset_writeMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
lockMethod · 0.45
removeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected