python_assembler/formats/pyc/
mod.rs1pub mod marshal;
18pub mod reader;
19pub mod writer;
21
22use crate::program::PythonVersion;
23use gaia_types::{GaiaDiagnostics, GaiaError};
24use std::{fs::File, io::BufReader, path::Path};
25
26#[derive(Debug, Clone, Copy)]
28pub struct PycReadConfig {
29 pub version: PythonVersion,
31}
32
33impl Default for PycReadConfig {
34 fn default() -> Self {
35 Self { version: PythonVersion::Unknown }
36 }
37}
38
39#[derive(Debug, Clone, Copy)]
41pub struct PycWriteConfig {
42 pub version: PythonVersion,
44}
45
46impl Default for PycWriteConfig {
47 fn default() -> Self {
48 Self { version: PythonVersion::Python3_9 }
49 }
50}
51
52pub fn pyc_read_path<P: AsRef<Path>>(path: P, config: &PycReadConfig) -> GaiaDiagnostics<crate::program::PythonProgram> {
54 let file = match File::open(path) {
55 Ok(f) => f,
56 Err(e) => return GaiaDiagnostics { result: Err(GaiaError::from(e)), diagnostics: Vec::new() },
57 };
58
59 let buf_reader = BufReader::new(file);
60 let reader = config.as_reader(buf_reader);
61 reader.finish()
62}