From acaa2eef3e33dd46ebdd1651f0bc1f11a46fe72e Mon Sep 17 00:00:00 2001 From: Sam Bentley Date: Sat, 28 Nov 2020 17:48:36 +0000 Subject: [PATCH] Changed error handling message of file read --- py_test.py | 12 ++++++++---- src/lib.rs | 7 ++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/py_test.py b/py_test.py index 0684c9d..4aae255 100644 --- a/py_test.py +++ b/py_test.py @@ -1,7 +1,11 @@ from qvd import reader +import sys -df = reader.read('test_qvd.qvd') -print(df) +args = sys.argv[1:] -dict = reader.read_to_dict('test_qvd_null.qvd') -print(dict) +for file in args: + df = reader.read(file) + print(df) + + dict = reader.read_to_dict(file) + print(f'\n {dict}') diff --git a/src/lib.rs b/src/lib.rs index faf7710..45d3b93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ fn qvd(_py: Python, m: &PyModule) -> PyResult<()> { #[pyfunction] pub fn read_qvd<'a>(py: Python, file_name: String) -> PyResult> { - let xml: String = get_xml_data(&file_name).expect("Unable to locate xml section in qvd file"); + let xml: String = get_xml_data(&file_name).expect("Error reading file"); let dict = PyDict::new(py); let binary_section_offset = xml.as_bytes().len(); @@ -154,7 +154,7 @@ fn get_xml_data(file_name: &String) -> Result { let mut buffer = Vec::new(); // There is a line break, carriage return and a null terminator between the XMl and data // Find the null terminator - reader.read_until(0, &mut buffer).unwrap(); + reader.read_until(0, &mut buffer).expect("Failed to read file"); let xml_string = str::from_utf8(&buffer[..]).expect("xml section contains invalid UTF-8 chars"); Ok(xml_string.to_owned()) @@ -223,8 +223,6 @@ pub fn retrieve_number_symbols(buf: &[u8]) -> Vec> { numbers } -// The output is wrapped in a Result to allow matching on errors -// Returns an Iterator to the Reader of the lines of the file. fn read_file

(filename: P) -> io::Result> where P: AsRef, @@ -236,7 +234,6 @@ where #[cfg(test)] mod tests { use super::*; - use bitvec::prelude::*; #[test] fn it_works() {