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

Function maybe_pyc_file_with_magic

crates/vm/src/vm/python_run.rs:157–175  ·  view source on GitHub ↗
(path: &str)

Source from the content-addressed store, hash-verified

155 }
156
157 fn maybe_pyc_file_with_magic(path: &str) -> std::io::Result<bool> {
158 let path_obj = std::path::Path::new(path);
159 if !path_obj.is_file() {
160 return Ok(false);
161 }
162
163 let mut file = std::fs::File::open(path)?;
164 let mut buf = [0u8; 2];
165
166 use std::io::Read;
167 if file.read(&mut buf)? != 2 {
168 return Ok(false);
169 }
170
171 // Read only two bytes of the magic. If the file was opened in
172 // text mode, the bytes 3 and 4 of the magic (\r\n) might not
173 // be read as they are on disk.
174 Ok(crate::import::check_pyc_magic_number_bytes(&buf))
175 }
176}

Callers 1

maybe_pyc_fileFunction · 0.85

Calls 5

newFunction · 0.85
openFunction · 0.50
is_fileMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected