From b3227b10292f523726fcc0cee0afce24f681a738 Mon Sep 17 00:00:00 2001 From: rdimaio Date: Mon, 25 Mar 2024 18:31:17 +0100 Subject: [PATCH] Client: refactor constructor to improve static type checking; #6588 --- lib/rucio/client/baseclient.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/rucio/client/baseclient.py b/lib/rucio/client/baseclient.py index 77a5df050d..3b98a943c4 100644 --- a/lib/rucio/client/baseclient.py +++ b/lib/rucio/client/baseclient.py @@ -93,9 +93,7 @@ def __init__(self, rucio_host=None, auth_host=None, account=None, ca_cert=None, :param logger: Logger object to use. If None, use the default LOG created by the module """ - self.host = rucio_host self.list_hosts = [] - self.auth_host = auth_host self.logger = logger or LOG self.session = Session() self.user_agent = "%s/%s" % (user_agent, version.version_string()) # e.g. "rucio-clients/0.2.13" @@ -104,9 +102,17 @@ def __init__(self, rucio_host=None, auth_host=None, account=None, ca_cert=None, if self.script_id == '': # Python interpreter used self.script_id = 'python' try: - if self.host is None: + if rucio_host is not None: + self.host = rucio_host + else: self.host = config_get('client', 'rucio_host') - if self.auth_host is None: + except (NoOptionError, NoSectionError) as error: + raise MissingClientParameter('Section client and Option \'%s\' cannot be found in config file' % error.args[0]) + + try: + if auth_host is not None: + self.auth_host = auth_host + else: self.auth_host = config_get('client', 'auth_host') except (NoOptionError, NoSectionError) as error: raise MissingClientParameter('Section client and Option \'%s\' cannot be found in config file' % error.args[0]) @@ -295,9 +301,12 @@ def _get_exception(self, headers, status_code=None, data=None): :return: A rucio exception class and an error string. """ - try: - data = parse_response(data) - except ValueError: + if data is not None: + try: + data = parse_response(data) + except ValueError: + data = {} + else: data = {} exc_cls = 'RucioException'