|
|
|
@@ -81,15 +81,41 @@ impl PyEvent { |
|
|
|
pub fn to_py_dict(self, py: Python<'_>) -> PyResult<Py<PyDict>> { |
|
|
|
let mut pydict = HashMap::new(); |
|
|
|
match &self.event { |
|
|
|
MergedEvent::Dora(_) => pydict.insert("kind", "dora".to_object(py)), |
|
|
|
MergedEvent::External(_) => pydict.insert("kind", "external".to_object(py)), |
|
|
|
MergedEvent::Dora(_) => pydict.insert( |
|
|
|
"kind", |
|
|
|
"dora" |
|
|
|
.into_pyobject(py) |
|
|
|
.context("Failed to create pystring")? |
|
|
|
.unbind() |
|
|
|
.into(), |
|
|
|
), |
|
|
|
MergedEvent::External(_) => pydict.insert( |
|
|
|
"kind", |
|
|
|
"external" |
|
|
|
.into_pyobject(py) |
|
|
|
.context("Failed to create pystring")? |
|
|
|
.unbind() |
|
|
|
.into(), |
|
|
|
), |
|
|
|
}; |
|
|
|
match &self.event { |
|
|
|
MergedEvent::Dora(event) => { |
|
|
|
if let Some(id) = Self::id(event) { |
|
|
|
pydict.insert("id", id.into_py(py)); |
|
|
|
pydict.insert( |
|
|
|
"id", |
|
|
|
id.into_pyobject(py) |
|
|
|
.context("Failed to create id pyobject")? |
|
|
|
.into(), |
|
|
|
); |
|
|
|
} |
|
|
|
pydict.insert("type", Self::ty(event).to_object(py)); |
|
|
|
pydict.insert( |
|
|
|
"type", |
|
|
|
Self::ty(event) |
|
|
|
.into_pyobject(py) |
|
|
|
.context("Failed to create event pyobject")? |
|
|
|
.unbind() |
|
|
|
.into(), |
|
|
|
); |
|
|
|
|
|
|
|
if let Some(value) = self.value(py)? { |
|
|
|
pydict.insert("value", value); |
|
|
|
@@ -98,7 +124,14 @@ impl PyEvent { |
|
|
|
pydict.insert("metadata", metadata); |
|
|
|
} |
|
|
|
if let Some(error) = Self::error(event) { |
|
|
|
pydict.insert("error", error.to_object(py)); |
|
|
|
pydict.insert( |
|
|
|
"error", |
|
|
|
error |
|
|
|
.into_pyobject(py) |
|
|
|
.context("Failed to create error pyobject")? |
|
|
|
.unbind() |
|
|
|
.into(), |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
MergedEvent::External(event) => { |
|
|
|
@@ -151,7 +184,10 @@ impl PyEvent { |
|
|
|
Event::Input { metadata, .. } => Ok(Some( |
|
|
|
metadata_to_pydict(metadata, py) |
|
|
|
.context("Issue deserializing metadata")? |
|
|
|
.to_object(py), |
|
|
|
.into_pyobject(py) |
|
|
|
.context("Failed to create metadata_to_pydice")? |
|
|
|
.unbind() |
|
|
|
.into(), |
|
|
|
)), |
|
|
|
_ => Ok(None), |
|
|
|
} |
|
|
|
|