From 8bd1f1a4aecd0a70b471375da2ca1946877cfa76 Mon Sep 17 00:00:00 2001 From: Daniel <daniel@harvey> Date: Wed, 8 Jan 2020 10:54:45 +0100 Subject: [PATCH] FIX: Type-safer use of ConfigParser. For #16. --- src/caosdb/connection/connection.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/caosdb/connection/connection.py b/src/caosdb/connection/connection.py index 992efd60..9bd1b82a 100644 --- a/src/caosdb/connection/connection.py +++ b/src/caosdb/connection/connection.py @@ -333,8 +333,21 @@ def configure_connection(**kwargs): _Connection The singleton instance of the _Connection class. """ - global_conf = (dict(get_config().items("Connection")) if - get_config().has_section("Connection") else dict()) + global_conf = {} + conf = get_config() + # Convert config to dict, with preserving types + int_opts = ["timeout"] + bool_opts = ["ssl_insecure"] + if conf.has_section("Connection"): + global_conf = dict(conf.items("Connection")) + # Integer options + for opt in int_opts: + if opt in global_conf: + global_conf[opt] = conf.getint("Connection", opt) + # Boolean options + for opt in bool_opts: + if opt in global_conf: + global_conf[opt] = conf.getboolean("Connection", opt) local_conf = _make_conf(_DEFAULT_CONF, global_conf, kwargs) connection = _Connection.get_instance() -- GitLab