From a94603b6ccc7952d08db9794903b9842044d0612 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 13 Jul 2026 13:54:52 +0200 Subject: [PATCH] auth.Auth.load(): Support dict and StringTree Auth objects can currently be loaded dynamically with a Config type argument. For greater flexibility, allow to pass dict and StringTree mappings to load(), too. Signed-off-by: Jan Lindemann --- src/python/jw/util/auth/Auth.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/python/jw/util/auth/Auth.py b/src/python/jw/util/auth/Auth.py index 46266bd..bd70a3d 100644 --- a/src/python/jw/util/auth/Auth.py +++ b/src/python/jw/util/auth/Auth.py @@ -3,13 +3,17 @@ from __future__ import annotations import abc from enum import Enum, Flag, auto -from typing import TYPE_CHECKING, Self, Sequence +from typing import TYPE_CHECKING from ..log import ERR from ..misc import load_object if TYPE_CHECKING: + + from typing import Any, Self, Sequence + from ..Config import Config + from ..stree.StringTree import StringTree class Access(Enum): # export Read = auto() @@ -80,7 +84,11 @@ class User(AuthEntity): # export class Auth(abc.ABC): # export @classmethod - def load(cls, conf: Config, tp: str = '') -> Self: + def load(cls, conf: Config | dict[str, Any] | StringTree, tp: str = '') -> Self: + if isinstance(conf, dict): + conf = StringTree.from_dict(conf) + if isinstance(conf, StringTree): + conf = Config(tree = conf) if tp == '': val = conf.get('type') if val is None: