From d60ac63b49b0329ed88d966ee9e07a03246c7094 Mon Sep 17 00:00:00 2001 From: cschen Date: Fri, 20 Sep 2024 16:39:09 +0200 Subject: [PATCH] fix(py): fixed the configuration and rearranged a bit. tested. builds and works. --- src/ffi/python/mod.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ffi/python/mod.rs b/src/ffi/python/mod.rs index 5b4903a..d1c7105 100644 --- a/src/ffi/python/mod.rs +++ b/src/ffi/python/mod.rs @@ -11,7 +11,7 @@ use crate::{ use pyo3::prelude::*; use pyo3::{ - exceptions::{PyAttributeError, PyConnectionError, PyRuntimeError, PySystemError}, + exceptions::{PyConnectionError, PyRuntimeError, PySystemError}, types::PyDict, }; @@ -166,21 +166,21 @@ impl Config { password: String, kwds: Option>, ) -> PyResult { - let config = kwds.map_or(Config::new(username, password), |dict| { - let host: Option = dict.get_item("host")?.map(|s| s.extract()); - let port: Option = dict.get_item("port")?.map(|p| p.extract()); - let tls: Option = dict.get_item("tls")?.map(|t| t.extract()); + if let Some(kwgs) = kwds { + let host = kwgs.get_item("host")?.map(|e| e.extract().ok()).flatten(); + let port = kwgs.get_item("port")?.map(|e| e.extract().ok()).flatten(); + let tls = kwgs.get_item("tls")?.map(|e| e.extract().ok()).flatten(); - Config { + Ok(Config { username, password, host, port, tls, - } - }); - - Ok(config) + }) + } else { + Ok(Config::new(username, password)) + } } } @@ -271,6 +271,7 @@ fn codemp(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; + m.add_class::()?; Ok(()) }