Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for pyo3 0.23 #443

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ crate-type = ["cdylib"]
[dependencies]
anyhow = "1.0.93"
chrono = "0.4.38"
prelude-xml-parser = { version = "0.7.2", features = ["python"] }
pyo3 = { version = "0.22.6", features = ["extension-module"] }
prelude-xml-parser = { version = "0.7.3", features = ["python"] }
pyo3 = { version = "0.23.0", features = ["extension-module"] }
roxmltree = "0.20.0"
serde = { version = "1.0.215", features = ["derive"] }
serde-xml-rs = "0.6.0"
Expand Down
29 changes: 14 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn py_list_append<'py>(
value: Option<&str>,
list: &'py Bound<'py, PyList>,
) -> PyResult<&'py Bound<'py, PyList>> {
let datetime = py.import_bound("datetime")?;
let datetime = py.import("datetime")?;
let date = datetime.getattr("date")?;

match value {
Expand Down Expand Up @@ -79,7 +79,7 @@ fn add_item<'py>(
value: Option<&str>,
form_data: &'py Bound<'py, PyDict>,
) -> PyResult<&'py Bound<'py, PyDict>> {
let datetime = py.import_bound("datetime")?;
let datetime = py.import("datetime")?;
let date = datetime.getattr("date")?;

match value {
Expand Down Expand Up @@ -122,7 +122,7 @@ fn parse_xml<'py>(
};
if !form_name.is_empty() {
if let Some(d) = data.get_mut(&form_name) {
let form_data = PyDict::new_bound(py);
let form_data = PyDict::new(py);
for child in form.children() {
if child.is_element() && child.tag_name().name() != "" {
let key = if short_names {
Expand All @@ -136,7 +136,7 @@ fn parse_xml<'py>(
d.push(form_data);
} else {
let mut items: Vec<Bound<'_, PyDict>> = Vec::new();
let form_data = PyDict::new_bound(py);
let form_data = PyDict::new(py);
for child in form.children() {
if child.is_element() && child.tag_name().name() != "" {
let key = if short_names {
Expand All @@ -147,12 +147,13 @@ fn parse_xml<'py>(
add_item(py, &key, child.text(), &form_data)?;
}
}
items.push(form_data.into_py_dict_bound(py));
items.push(form_data.into_py_dict(py)?);
data.insert(form_name, items);
}
}
}
return Ok(data.into_py_dict_bound(py));
let data_dict = data.into_py_dict(py)?;
Ok(data_dict)
}
Err(e) => Err(ParsingError::new_err(format!(
"Error parsing xml file: {:?}",
Expand All @@ -176,7 +177,7 @@ fn parse_xml_pandas<'py>(
match reader {
Ok(r) => match Document::parse(&r) {
Ok(doc) => {
let data = PyDict::new_bound(py);
let data = PyDict::new(py);
let tree = doc.root_element();

for form in tree.children() {
Expand All @@ -191,14 +192,15 @@ fn parse_xml_pandas<'py>(
py_list_append(py, child.text(), &c.extract()?)?;
data.set_item(column, c)?;
} else {
let list = PyList::empty_bound(py);
let list = PyList::empty(py);
py_list_append(py, child.text(), &list)?;
data.set_item(column, list)?;
}
}
}
}
return Ok(data.into_py_dict_bound(py));
let data_dict = data.into_py_dict(py)?;
Ok(data_dict)
}
Err(e) => Err(ParsingError::new_err(format!(
"Error parsing xml file: {:?}",
Expand Down Expand Up @@ -314,15 +316,12 @@ fn _prelude_parser(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(parse_subject_native_string, m)?)?;
m.add_function(wrap_pyfunction!(parse_user_native_file, m)?)?;
m.add_function(wrap_pyfunction!(parse_user_native_string, m)?)?;
m.add(
"FileNotFoundError",
py.get_type_bound::<FileNotFoundError>(),
)?;
m.add("FileNotFoundError", py.get_type::<FileNotFoundError>())?;
m.add(
"InvalidFileTypeError",
py.get_type_bound::<InvalidFileTypeError>(),
py.get_type::<InvalidFileTypeError>(),
)?;
m.add("ParsingError", py.get_type_bound::<ParsingError>())?;
m.add("ParsingError", py.get_type::<ParsingError>())?;
Ok(())
}

Expand Down