fix(py): fixed the configuration and rearranged a bit. tested. builds and works.

This commit is contained in:
cschen 2024-09-20 16:39:09 +02:00
parent e67b1c6bd0
commit d60ac63b49

View file

@ -11,7 +11,7 @@ use crate::{
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::{ use pyo3::{
exceptions::{PyAttributeError, PyConnectionError, PyRuntimeError, PySystemError}, exceptions::{PyConnectionError, PyRuntimeError, PySystemError},
types::PyDict, types::PyDict,
}; };
@ -166,21 +166,21 @@ impl Config {
password: String, password: String,
kwds: Option<Bound<'_, PyDict>>, kwds: Option<Bound<'_, PyDict>>,
) -> PyResult<Self> { ) -> PyResult<Self> {
let config = kwds.map_or(Config::new(username, password), |dict| { if let Some(kwgs) = kwds {
let host: Option<String> = dict.get_item("host")?.map(|s| s.extract()); let host = kwgs.get_item("host")?.map(|e| e.extract().ok()).flatten();
let port: Option<u16> = dict.get_item("port")?.map(|p| p.extract()); let port = kwgs.get_item("port")?.map(|e| e.extract().ok()).flatten();
let tls: Option<bool> = dict.get_item("tls")?.map(|t| t.extract()); let tls = kwgs.get_item("tls")?.map(|e| e.extract().ok()).flatten();
Config { Ok(Config {
username, username,
password, password,
host, host,
port, port,
tls, tls,
} })
}); } else {
Ok(Config::new(username, password))
Ok(config) }
} }
} }
@ -271,6 +271,7 @@ fn codemp(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Workspace>()?; m.add_class::<Workspace>()?;
m.add_class::<Client>()?; m.add_class::<Client>()?;
m.add_class::<Config>()?;
Ok(()) Ok(())
} }