From 40a521403f36737b54d4440304016ac65b6b38f3 Mon Sep 17 00:00:00 2001 From: Stefan Hynek <stefan.hynek@uni-goettingen.de> Date: Thu, 21 Nov 2024 14:01:30 +0100 Subject: [PATCH 1/2] feat: provide serialization for TextgridConfig --- src/tgclients/config.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tgclients/config.py b/src/tgclients/config.py index a3d32fc..a0c7694 100644 --- a/src/tgclients/config.py +++ b/src/tgclients/config.py @@ -4,6 +4,7 @@ """Variable config options with defaults to be used with the TextGrid clients library.""" +import json import logging from typing import Optional @@ -163,3 +164,25 @@ class TextgridConfig: value (float): the timeout """ self._http_timeout = value + + def __dict__(self): + return { + 'host': self.host, + 'auth_wsdl': self.auth_wsdl, + 'auth_address': self.auth_address, + 'extra_crud_wsdl': self.extra_crud_wsdl, + 'extra_crud_address': self.extra_crud_address, + 'search': self.search, + 'search_public': self.search_public, + 'crud': self.crud, + 'crud_public': self.crud_public, + 'aggregator': self.aggregator, + 'publish': self.publish, + 'http_timeout': self.http_timeout, + } + + def __json__(self): + return json.dumps(self.__dict__()) + + def __str__(self): + return self.__json__() -- GitLab From 6690e6e1ebd44909da27562e4ff1af1f61a2a8e0 Mon Sep 17 00:00:00 2001 From: Stefan Hynek <stefan.hynek@uni-goettingen.de> Date: Fri, 22 Nov 2024 12:22:55 +0100 Subject: [PATCH 2/2] fix(config): rename serialisation helper functions; add docstring to __str__() --- src/tgclients/config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tgclients/config.py b/src/tgclients/config.py index a0c7694..d28a03b 100644 --- a/src/tgclients/config.py +++ b/src/tgclients/config.py @@ -165,7 +165,7 @@ class TextgridConfig: """ self._http_timeout = value - def __dict__(self): + def _to_dict(self): return { 'host': self.host, 'auth_wsdl': self.auth_wsdl, @@ -181,8 +181,9 @@ class TextgridConfig: 'http_timeout': self.http_timeout, } - def __json__(self): - return json.dumps(self.__dict__()) + def _to_json(self): + return json.dumps(self._to_dict()) def __str__(self): - return self.__json__() + """Return a string representation of the TextgridConfig object.""" + return self._to_json() -- GitLab