Skip to content

Commit

Permalink
feat(all): updating libs to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
nephi-dev committed Jul 12, 2024
1 parent 8fe86e9 commit 42ee8a7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 150 deletions.
171 changes: 27 additions & 144 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 @@ -8,5 +8,5 @@ name = "rxml"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.21.2"
quick-xml = "0.31.0"
pyo3 = "0.22.1"
quick-xml = "0.36.0"
10 changes: 8 additions & 2 deletions src/entities.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pyo3::prelude::*;
use std::collections::HashMap;

#[derive(Clone)]
#[pyclass]
#[derive(Clone, PartialEq)]
#[pyclass(eq, eq_int)]
pub enum SearchType {
Tag,
Attr,
Expand All @@ -25,6 +25,7 @@ pub struct Node {
#[pymethods]
impl Node {
#[new]
#[pyo3(signature = (name, attrs=None, children=None, text=None))]
pub fn new(
name: String,
attrs: Option<HashMap<String, String>>,
Expand All @@ -40,6 +41,7 @@ impl Node {
text,
})
}
#[pyo3(signature = (spacing=None))]
fn __to_string(&self, spacing: Option<u8>) -> String {
let _spacing = spacing.unwrap_or(0);
let spaces = " ".repeat(_spacing as usize);
Expand Down Expand Up @@ -74,6 +76,7 @@ impl Node {
fn __repr__(&self) -> String {
format!("Node({})", self.name)
}
#[pyo3(signature = (name, depth=None))]
fn search_by_name(&self, name: &str, depth: Option<i32>) -> Vec<Node> {
let mut nodes = Vec::new();
if self.name == name {
Expand All @@ -89,6 +92,7 @@ impl Node {
}
nodes
}
#[pyo3(signature = (key, depth=None))]
fn search_by_attr(&self, key: &str, depth: Option<i32>) -> Vec<Node> {
let mut nodes = Vec::new();
if self.attrs.contains_key(key) {
Expand All @@ -104,6 +108,7 @@ impl Node {
}
nodes
}
#[pyo3(signature = (text, depth=None))]
fn search_by_text(&self, text: &str, depth: Option<i32>) -> Vec<Node> {
let mut nodes = Vec::new();
if let Some(t) = &self.text {
Expand All @@ -121,6 +126,7 @@ impl Node {
}
nodes
}
#[pyo3(signature = (by, value, depth=None))]
pub fn search(&self, by: SearchType, value: &str, depth: Option<i32>) -> Vec<Node> {
match by {
SearchType::Tag => self.search_by_name(value, depth),
Expand Down
4 changes: 2 additions & 2 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ pub fn read_file(file_path: String, root_tag: String) -> Node {
let mut file_str = String::new();
file.read_to_string(&mut file_str).unwrap();
let mut reader = Reader::from_str(file_str.as_str());
reader.trim_text(true);
reader.config_mut().trim_text(true);
read_node(f_str!(root_tag), &mut reader)
}

#[pyfunction]
pub fn read_string(xml_string: String, root_tag: String) -> Node {
let mut reader = Reader::from_str(xml_string.as_str());
reader.trim_text(true);
reader.config_mut().trim_text(true);
read_node(f_str!(root_tag), &mut reader)
}

Expand Down
Loading

0 comments on commit 42ee8a7

Please sign in to comment.