Skip to content

Commit 5470449

Browse files
committed
Update for pyo3 0.23
1 parent 8bb67a2 commit 5470449

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ crate-type = ["cdylib"]
1616
[dependencies]
1717
anyhow = "1.0.93"
1818
chrono = "0.4.38"
19-
prelude-xml-parser = { version = "0.7.2", features = ["python"] }
20-
pyo3 = { version = "0.22.6", features = ["extension-module"] }
19+
prelude-xml-parser = { version = "0.7.3", features = ["python"] }
20+
pyo3 = { version = "0.23.0", features = ["extension-module"] }
2121
roxmltree = "0.20.0"
2222
serde = { version = "1.0.215", features = ["derive"] }
2323
serde-xml-rs = "0.6.0"

src/lib.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn py_list_append<'py>(
5050
value: Option<&str>,
5151
list: &'py Bound<'py, PyList>,
5252
) -> PyResult<&'py Bound<'py, PyList>> {
53-
let datetime = py.import_bound("datetime")?;
53+
let datetime = py.import("datetime")?;
5454
let date = datetime.getattr("date")?;
5555

5656
match value {
@@ -79,7 +79,7 @@ fn add_item<'py>(
7979
value: Option<&str>,
8080
form_data: &'py Bound<'py, PyDict>,
8181
) -> PyResult<&'py Bound<'py, PyDict>> {
82-
let datetime = py.import_bound("datetime")?;
82+
let datetime = py.import("datetime")?;
8383
let date = datetime.getattr("date")?;
8484

8585
match value {
@@ -122,7 +122,7 @@ fn parse_xml<'py>(
122122
};
123123
if !form_name.is_empty() {
124124
if let Some(d) = data.get_mut(&form_name) {
125-
let form_data = PyDict::new_bound(py);
125+
let form_data = PyDict::new(py);
126126
for child in form.children() {
127127
if child.is_element() && child.tag_name().name() != "" {
128128
let key = if short_names {
@@ -136,7 +136,7 @@ fn parse_xml<'py>(
136136
d.push(form_data);
137137
} else {
138138
let mut items: Vec<Bound<'_, PyDict>> = Vec::new();
139-
let form_data = PyDict::new_bound(py);
139+
let form_data = PyDict::new(py);
140140
for child in form.children() {
141141
if child.is_element() && child.tag_name().name() != "" {
142142
let key = if short_names {
@@ -147,12 +147,13 @@ fn parse_xml<'py>(
147147
add_item(py, &key, child.text(), &form_data)?;
148148
}
149149
}
150-
items.push(form_data.into_py_dict_bound(py));
150+
items.push(form_data.into_py_dict(py)?);
151151
data.insert(form_name, items);
152152
}
153153
}
154154
}
155-
return Ok(data.into_py_dict_bound(py));
155+
let data_dict = data.into_py_dict(py)?;
156+
Ok(data_dict)
156157
}
157158
Err(e) => Err(ParsingError::new_err(format!(
158159
"Error parsing xml file: {:?}",
@@ -176,7 +177,7 @@ fn parse_xml_pandas<'py>(
176177
match reader {
177178
Ok(r) => match Document::parse(&r) {
178179
Ok(doc) => {
179-
let data = PyDict::new_bound(py);
180+
let data = PyDict::new(py);
180181
let tree = doc.root_element();
181182

182183
for form in tree.children() {
@@ -191,14 +192,15 @@ fn parse_xml_pandas<'py>(
191192
py_list_append(py, child.text(), &c.extract()?)?;
192193
data.set_item(column, c)?;
193194
} else {
194-
let list = PyList::empty_bound(py);
195+
let list = PyList::empty(py);
195196
py_list_append(py, child.text(), &list)?;
196197
data.set_item(column, list)?;
197198
}
198199
}
199200
}
200201
}
201-
return Ok(data.into_py_dict_bound(py));
202+
let data_dict = data.into_py_dict(py)?;
203+
Ok(data_dict)
202204
}
203205
Err(e) => Err(ParsingError::new_err(format!(
204206
"Error parsing xml file: {:?}",
@@ -314,15 +316,12 @@ fn _prelude_parser(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
314316
m.add_function(wrap_pyfunction!(parse_subject_native_string, m)?)?;
315317
m.add_function(wrap_pyfunction!(parse_user_native_file, m)?)?;
316318
m.add_function(wrap_pyfunction!(parse_user_native_string, m)?)?;
317-
m.add(
318-
"FileNotFoundError",
319-
py.get_type_bound::<FileNotFoundError>(),
320-
)?;
319+
m.add("FileNotFoundError", py.get_type::<FileNotFoundError>())?;
321320
m.add(
322321
"InvalidFileTypeError",
323-
py.get_type_bound::<InvalidFileTypeError>(),
322+
py.get_type::<InvalidFileTypeError>(),
324323
)?;
325-
m.add("ParsingError", py.get_type_bound::<ParsingError>())?;
324+
m.add("ParsingError", py.get_type::<ParsingError>())?;
326325
Ok(())
327326
}
328327

0 commit comments

Comments
 (0)