MCPcopy Create free account
hub / github.com/AI45Lab/Code / handle

Method handle

sdk/python/src/lib.rs:3382–3398  ·  view source on GitHub ↗
(&self, event: &RustHookEvent)

Source from the content-addressed store, hash-verified

3380
3381impl 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`.

Callers

nothing calls this directly

Calls 2

parse_py_hook_responseFunction · 0.85
as_strMethod · 0.45

Tested by

no test coverage detected