(&self, event: &RustHookEvent)
| 3380 | |
| 3381 | impl RustHookHandler for PythonCallbackHandler { |
| 3382 | fn handle(&self, event: &RustHookEvent) -> RustHookResponse { |
| 3383 | let Ok(json_str) = serde_json::to_string(event) else { |
| 3384 | return RustHookResponse::continue_(); |
| 3385 | }; |
| 3386 | |
| 3387 | pyo3::Python::with_gil(|py| { |
| 3388 | // Deserialize the event into a Python dict via json.loads. |
| 3389 | let result = (|| -> pyo3::PyResult<RustHookResponse> { |
| 3390 | let json_mod = py.import("json")?; |
| 3391 | let event_dict = json_mod.call_method1("loads", (json_str.as_str(),))?; |
| 3392 | let ret = self.callback.call1(py, (event_dict,))?; |
| 3393 | parse_py_hook_response(py, ret.bind(py)) |
| 3394 | })(); |
| 3395 | |
| 3396 | result.unwrap_or_else(|_| RustHookResponse::continue_()) |
| 3397 | }) |
| 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | /// Parse the return value of a Python hook callback into a `HookResponse`. |
nothing calls this directly
no test coverage detected