Skip to content

Commit ffa93ae

Browse files
authored
Merge pull request #3 from bgpkit/fix-regression
Fix regressions from 6.0
2 parents b34db74 + 00a521d commit ffa93ae

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ crate-type = ["cdylib", "rlib"]
1717
[dependencies]
1818
bgpkit-parser = "0.11.1"
1919
pyo3 = { version = "0.25", features = ["extension-module"] }
20+
serde = { version = "1.0", features = ["derive"] }
21+
serde_json = "1"
2022

2123
[build-dependencies]
2224
pyo3-build-config = "0.25"

examples/filter_count_print.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
print(elem.as_path)
1414

1515
# Optional fields can be checked for None
16-
print(elem.aggr_ip==None)
16+
print(elem.aggr_ip is None)
1717

1818
# Print the entire parsed BGP update as a dictionary
19-
print(json.dumps(elem.to_dict(), indent=4))
19+
print(json.dumps(elem.to_dict()))
20+
print(elem)
2021
break

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use bgpkit_parser::models::*;
22
use bgpkit_parser::*;
33
use pyo3::exceptions::PyValueError;
44
use pyo3::prelude::*;
5+
use serde::Serialize;
56
use std::collections::HashMap;
67
use std::io::Read;
78

@@ -38,7 +39,7 @@ fn pybgpkit_parser(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
3839
}
3940

4041
#[pyclass]
41-
#[derive(Clone, PartialEq)]
42+
#[derive(Clone, PartialEq, Serialize)]
4243
pub struct Elem {
4344
#[pyo3(get, set)]
4445
pub timestamp: f64,
@@ -100,6 +101,11 @@ fn pybgpkit_parser(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
100101
fn __getstate__(&self, py: Python) -> PyObject {
101102
self.to_dict(py)
102103
}
104+
105+
#[pyo3(name = "__str__")]
106+
fn str_repr(&self) -> PyResult<String> {
107+
Ok(serde_json::to_string(self).unwrap().to_string())
108+
}
103109
}
104110

105111
#[pyclass]
@@ -113,7 +119,7 @@ fn pybgpkit_parser(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
113119
#[pymethods]
114120
impl Parser {
115121
#[new]
116-
#[pyo3(text_signature = "(url, filters, /)")]
122+
#[pyo3(signature = (url, filters=None, cache_dir=None))]
117123
fn new(
118124
url: String,
119125
filters: Option<HashMap<String, String>>,

0 commit comments

Comments
 (0)